[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame^] | 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. |
| 4 | |
| 5 | // This file contains the ContextState class. |
| 6 | |
| 7 | #ifndef GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ |
| 8 | #define GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ |
| 9 | |
| 10 | #include "base/logging.h" |
| 11 | #include "gpu/command_buffer/service/gl_utils.h" |
| 12 | #include "gpu/command_buffer/service/buffer_manager.h" |
| 13 | #include "gpu/command_buffer/service/framebuffer_manager.h" |
| 14 | #include "gpu/command_buffer/service/program_manager.h" |
| 15 | #include "gpu/command_buffer/service/query_manager.h" |
| 16 | #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| 17 | #include "gpu/command_buffer/service/texture_manager.h" |
| 18 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
| 19 | #include "gpu/command_buffer/service/vertex_array_manager.h" |
| 20 | |
| 21 | namespace gpu { |
| 22 | namespace gles2 { |
| 23 | |
| 24 | // State associated with each texture unit. |
| 25 | struct TextureUnit { |
| 26 | TextureUnit(); |
| 27 | ~TextureUnit(); |
| 28 | |
| 29 | // The last target that was bound to this texture unit. |
| 30 | GLenum bind_target; |
| 31 | |
| 32 | // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture |
| 33 | TextureManager::TextureInfo::Ref bound_texture_2d; |
| 34 | |
| 35 | // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with |
| 36 | // glBindTexture |
| 37 | TextureManager::TextureInfo::Ref bound_texture_cube_map; |
| 38 | |
| 39 | // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with |
| 40 | // glBindTexture |
| 41 | TextureManager::TextureInfo::Ref bound_texture_external_oes; |
| 42 | |
| 43 | // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with |
| 44 | // glBindTexture |
| 45 | TextureManager::TextureInfo::Ref bound_texture_rectangle_arb; |
| 46 | |
| 47 | TextureManager::TextureInfo::Ref GetInfoForSamplerType(GLenum type) { |
| 48 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
| 49 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 50 | switch (type) { |
| 51 | case GL_SAMPLER_2D: |
| 52 | return bound_texture_2d; |
| 53 | case GL_SAMPLER_CUBE: |
| 54 | return bound_texture_cube_map; |
| 55 | case GL_SAMPLER_EXTERNAL_OES: |
| 56 | return bound_texture_external_oes; |
| 57 | case GL_SAMPLER_2D_RECT_ARB: |
| 58 | return bound_texture_rectangle_arb; |
| 59 | } |
| 60 | |
| 61 | NOTREACHED(); |
| 62 | return NULL; |
| 63 | } |
| 64 | |
| 65 | void Unbind(TextureManager::TextureInfo* texture) { |
| 66 | if (bound_texture_2d == texture) { |
| 67 | bound_texture_2d = NULL; |
| 68 | } |
| 69 | if (bound_texture_cube_map == texture) { |
| 70 | bound_texture_cube_map = NULL; |
| 71 | } |
| 72 | if (bound_texture_external_oes == texture) { |
| 73 | bound_texture_external_oes = NULL; |
| 74 | } |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | struct ContextState { |
| 80 | ContextState(); |
| 81 | ~ContextState(); |
| 82 | |
| 83 | // pack alignment as last set by glPixelStorei |
| 84 | GLint pack_alignment; |
| 85 | |
| 86 | // unpack alignment as last set by glPixelStorei |
| 87 | GLint unpack_alignment; |
| 88 | |
| 89 | // Current active texture by 0 - n index. |
| 90 | // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would |
| 91 | // be 2. |
| 92 | GLuint active_texture_unit; |
| 93 | |
| 94 | GLfloat color_clear_red; |
| 95 | GLfloat color_clear_green; |
| 96 | GLfloat color_clear_blue; |
| 97 | GLfloat color_clear_alpha; |
| 98 | GLboolean color_mask_red; |
| 99 | GLboolean color_mask_green; |
| 100 | GLboolean color_mask_blue; |
| 101 | GLboolean color_mask_alpha; |
| 102 | |
| 103 | GLint stencil_clear; |
| 104 | GLuint stencil_mask_front; |
| 105 | GLuint stencil_mask_back; |
| 106 | GLclampf depth_clear; |
| 107 | GLboolean depth_mask; |
| 108 | |
| 109 | bool enable_blend; |
| 110 | bool enable_cull_face; |
| 111 | bool enable_scissor_test; |
| 112 | bool enable_depth_test; |
| 113 | bool enable_stencil_test; |
| 114 | |
| 115 | // Cached values of the currently assigned viewport dimensions. |
| 116 | GLint viewport_x; |
| 117 | GLint viewport_y; |
| 118 | GLsizei viewport_width; |
| 119 | GLsizei viewport_height; |
| 120 | GLsizei viewport_max_width; |
| 121 | GLsizei viewport_max_height; |
| 122 | |
| 123 | // The currently bound array buffer. If this is 0 it is illegal to call |
| 124 | // glVertexAttribPointer. |
| 125 | BufferManager::BufferInfo::Ref bound_array_buffer; |
| 126 | |
| 127 | // Which textures are bound to texture units through glActiveTexture. |
| 128 | scoped_array<TextureUnit> texture_units; |
| 129 | |
| 130 | // Class that manages vertex attribs. |
| 131 | VertexAttribManager::Ref vertex_attrib_manager; |
| 132 | |
| 133 | // The program in use by glUseProgram |
| 134 | ProgramManager::ProgramInfo::Ref current_program; |
| 135 | |
| 136 | // The currently bound framebuffers |
| 137 | FramebufferManager::FramebufferInfo::Ref bound_read_framebuffer; |
| 138 | FramebufferManager::FramebufferInfo::Ref bound_draw_framebuffer; |
| 139 | |
| 140 | // The currently bound renderbuffer |
| 141 | RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer; |
| 142 | |
| 143 | QueryManager::Query::Ref current_query; |
| 144 | |
| 145 | GLenum cull_mode; |
| 146 | GLenum front_face; |
| 147 | GLenum depth_func; |
| 148 | GLenum source_blend_rgb; |
| 149 | GLenum dest_blend_rgb; |
| 150 | GLenum source_blend_alpha; |
| 151 | GLenum dest_blend_alpha; |
| 152 | GLenum blend_equation_rgb; |
| 153 | GLenum blend_equation_alpha; |
| 154 | GLfloat blend_color_red; |
| 155 | GLfloat blend_color_green; |
| 156 | GLfloat blend_color_blue; |
| 157 | GLfloat blend_color_alpha; |
| 158 | GLenum stencil_func; |
| 159 | GLint stencil_ref; |
| 160 | GLenum stencil_fail; |
| 161 | GLenum stencil_pass_depth_fail; |
| 162 | GLenum stencil_pass_depth_pass; |
| 163 | GLuint stencil_writemask; |
| 164 | GLenum stencil_back_func; |
| 165 | GLint stencil_back_ref; |
| 166 | GLenum stencil_back_fail; |
| 167 | GLenum stencil_back_pass_depth_fail; |
| 168 | GLenum stencil_back_pass_depth_pass; |
| 169 | GLuint stencil_back_writemask; |
| 170 | bool polygon_offset_fill; |
| 171 | GLfloat polygon_offset_factor; |
| 172 | GLfloat polygon_offset_units; |
| 173 | bool sample_alpha_to_coverage; |
| 174 | bool sample_coverage; |
| 175 | GLclampf sample_coverage_value; |
| 176 | bool sample_coverage_invert; |
| 177 | bool dither; |
| 178 | |
| 179 | GLfloat line_width; |
| 180 | |
| 181 | GLenum generate_mipmap_hint; |
| 182 | GLenum fragment_shader_derivative_hint; |
| 183 | |
| 184 | float z_near; |
| 185 | float z_far; |
| 186 | |
| 187 | GLint scissor_x; |
| 188 | GLint scissor_y; |
| 189 | GLsizei scissor_width; |
| 190 | GLsizei scissor_height; |
| 191 | |
| 192 | bool pack_reverse_row_order; |
| 193 | }; |
| 194 | |
| 195 | } // namespace gles2 |
| 196 | } // namespace gpu |
| 197 | |
| 198 | #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ |
| 199 | |