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"
30 // State associated with each texture unit.
31 struct GPU_EXPORT TextureUnit {
35 // The last target that was bound to this texture unit.
38 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
39 scoped_refptr<TextureRef> bound_texture_2d;
41 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
43 scoped_refptr<TextureRef> bound_texture_cube_map;
45 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
47 scoped_refptr<TextureRef> bound_texture_external_oes;
49 // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with
51 scoped_refptr<TextureRef> bound_texture_rectangle_arb;
53 scoped_refptr<TextureRef> GetInfoForSamplerType(
55 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
56 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
59 return bound_texture_2d;
61 return bound_texture_cube_map;
62 case GL_SAMPLER_EXTERNAL_OES:
63 return bound_texture_external_oes;
64 case GL_SAMPLER_2D_RECT_ARB:
65 return bound_texture_rectangle_arb;
72 void Unbind(TextureRef* texture) {
73 if (bound_texture_2d.get() == texture) {
74 bound_texture_2d = NULL;
76 if (bound_texture_cube_map.get() == texture) {
77 bound_texture_cube_map = NULL;
79 if (bound_texture_external_oes.get() == texture) {
80 bound_texture_external_oes = NULL;
95 struct GPU_EXPORT ContextState {
96 ContextState(FeatureInfo* feature_info, Logger* logger);
101 void RestoreState(const ContextState* prev_state) const;
102 void InitCapabilities() const;
103 void InitState() const;
105 void RestoreActiveTexture() const;
106 void RestoreAllTextureUnitBindings(const ContextState* prev_state) const;
107 void RestoreActiveTextureUnitBinding(unsigned int target) const;
108 void RestoreAttribute(GLuint index) const;
109 void RestoreBufferBindings() const;
110 void RestoreGlobalState() const;
111 void RestoreProgramBindings() const;
112 void RestoreRenderbufferBindings() const;
113 void RestoreTextureUnitBindings(
114 GLuint unit, const ContextState* prev_state) const;
116 // Helper for getting cached state.
117 bool GetStateAsGLint(
118 GLenum pname, GLint* params, GLsizei* num_written) const;
119 bool GetStateAsGLfloat(
120 GLenum pname, GLfloat* params, GLsizei* num_written) const;
121 bool GetEnabled(GLenum cap) const;
123 ErrorState* GetErrorState();
125 #include "gpu/command_buffer/service/context_state_autogen.h"
127 EnableFlags enable_flags;
129 // Current active texture by 0 - n index.
130 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would
132 GLuint active_texture_unit;
134 // The currently bound array buffer. If this is 0 it is illegal to call
135 // glVertexAttribPointer.
136 scoped_refptr<Buffer> bound_array_buffer;
138 // Which textures are bound to texture units through glActiveTexture.
139 std::vector<TextureUnit> texture_units;
141 // The values for each attrib.
142 std::vector<Vec4> attrib_values;
144 // Class that manages vertex attribs.
145 scoped_refptr<VertexAttribManager> vertex_attrib_manager;
147 // The program in use by glUseProgram
148 scoped_refptr<Program> current_program;
150 // The currently bound renderbuffer
151 scoped_refptr<Renderbuffer> bound_renderbuffer;
153 // A map of of target -> Query for current queries
154 typedef std::map<GLuint, scoped_refptr<QueryManager::Query> > QueryMap;
155 QueryMap current_queries;
157 bool pack_reverse_row_order;
159 mutable bool fbo_binding_for_scissor_workaround_dirty_;
160 FeatureInfo* feature_info_;
163 scoped_ptr<ErrorState> error_state_;
169 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_