1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file contains the ContextState class.
7 #ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
8 #define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "gpu/command_buffer/service/gl_utils.h"
14 #include "gpu/command_buffer/service/query_manager.h"
15 #include "gpu/command_buffer/service/texture_manager.h"
16 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
17 #include "gpu/command_buffer/service/vertex_array_manager.h"
18 #include "gpu/gpu_export.h"
25 class ErrorStateClient;
31 // State associated with each texture unit.
32 struct GPU_EXPORT TextureUnit {
36 // The last target that was bound to this texture unit.
39 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
40 scoped_refptr<TextureRef> bound_texture_2d;
42 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
44 scoped_refptr<TextureRef> bound_texture_cube_map;
46 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
48 scoped_refptr<TextureRef> bound_texture_external_oes;
50 // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with
52 scoped_refptr<TextureRef> bound_texture_rectangle_arb;
54 scoped_refptr<TextureRef> GetInfoForSamplerType(
56 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
57 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
60 return bound_texture_2d;
62 return bound_texture_cube_map;
63 case GL_SAMPLER_EXTERNAL_OES:
64 return bound_texture_external_oes;
65 case GL_SAMPLER_2D_RECT_ARB:
66 return bound_texture_rectangle_arb;
73 void Unbind(TextureRef* texture) {
74 if (bound_texture_2d.get() == texture) {
75 bound_texture_2d = NULL;
77 if (bound_texture_cube_map.get() == texture) {
78 bound_texture_cube_map = NULL;
80 if (bound_texture_external_oes.get() == texture) {
81 bound_texture_external_oes = NULL;
96 struct GPU_EXPORT ContextState {
97 ContextState(FeatureInfo* feature_info,
98 ErrorStateClient* error_state_client,
104 void RestoreState(const ContextState* prev_state) const;
105 void InitCapabilities() const;
106 void InitState() const;
108 void RestoreActiveTexture() const;
109 void RestoreAllTextureUnitBindings(const ContextState* prev_state) const;
110 void RestoreActiveTextureUnitBinding(unsigned int target) const;
111 void RestoreAttribute(GLuint index) const;
112 void RestoreBufferBindings() const;
113 void RestoreGlobalState() const;
114 void RestoreProgramBindings() const;
115 void RestoreRenderbufferBindings() const;
116 void RestoreTextureUnitBindings(
117 GLuint unit, const ContextState* prev_state) const;
119 // Helper for getting cached state.
120 bool GetStateAsGLint(
121 GLenum pname, GLint* params, GLsizei* num_written) const;
122 bool GetStateAsGLfloat(
123 GLenum pname, GLfloat* params, GLsizei* num_written) const;
124 bool GetEnabled(GLenum cap) const;
126 ErrorState* GetErrorState();
128 #include "gpu/command_buffer/service/context_state_autogen.h"
130 EnableFlags enable_flags;
132 // Current active texture by 0 - n index.
133 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would
135 GLuint active_texture_unit;
137 // The currently bound array buffer. If this is 0 it is illegal to call
138 // glVertexAttribPointer.
139 scoped_refptr<Buffer> bound_array_buffer;
141 // Which textures are bound to texture units through glActiveTexture.
142 std::vector<TextureUnit> texture_units;
144 // The values for each attrib.
145 std::vector<Vec4> attrib_values;
147 // Class that manages vertex attribs.
148 scoped_refptr<VertexAttribManager> vertex_attrib_manager;
150 // The program in use by glUseProgram
151 scoped_refptr<Program> current_program;
153 // The currently bound renderbuffer
154 scoped_refptr<Renderbuffer> bound_renderbuffer;
156 // A map of of target -> Query for current queries
157 typedef std::map<GLuint, scoped_refptr<QueryManager::Query> > QueryMap;
158 QueryMap current_queries;
160 bool pack_reverse_row_order;
162 mutable bool fbo_binding_for_scissor_workaround_dirty_;
163 FeatureInfo* feature_info_;
166 scoped_ptr<ErrorState> error_state_;
172 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_