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;
102 void InitCapabilities() const;
103 void InitState() const;
105 void RestoreActiveTexture() const;
106 void RestoreAllTextureUnitBindings() const;
107 void RestoreAttribute(GLuint index) const;
108 void RestoreBufferBindings() const;
109 void RestoreGlobalState() const;
110 void RestoreProgramBindings() const;
111 void RestoreRenderbufferBindings() const;
112 void RestoreTextureUnitBindings(GLuint unit) const;
114 // Helper for getting cached state.
115 bool GetStateAsGLint(
116 GLenum pname, GLint* params, GLsizei* num_written) const;
117 bool GetStateAsGLfloat(
118 GLenum pname, GLfloat* params, GLsizei* num_written) const;
119 bool GetEnabled(GLenum cap) const;
121 ErrorState* GetErrorState();
123 #include "gpu/command_buffer/service/context_state_autogen.h"
125 EnableFlags enable_flags;
127 // Current active texture by 0 - n index.
128 // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would
130 GLuint active_texture_unit;
132 // The currently bound array buffer. If this is 0 it is illegal to call
133 // glVertexAttribPointer.
134 scoped_refptr<Buffer> bound_array_buffer;
136 // Which textures are bound to texture units through glActiveTexture.
137 std::vector<TextureUnit> texture_units;
139 // The values for each attrib.
140 std::vector<Vec4> attrib_values;
142 // Class that manages vertex attribs.
143 scoped_refptr<VertexAttribManager> vertex_attrib_manager;
145 // The program in use by glUseProgram
146 scoped_refptr<Program> current_program;
148 // The currently bound renderbuffer
149 scoped_refptr<Renderbuffer> bound_renderbuffer;
151 scoped_refptr<QueryManager::Query> current_query;
153 bool pack_reverse_row_order;
155 mutable bool fbo_binding_for_scissor_workaround_dirty_;
156 FeatureInfo* feature_info_;
159 scoped_ptr<ErrorState> error_state_;
165 #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_