[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" |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 20 | #include "gpu/gpu_export.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 21 | |
| 22 | namespace gpu { |
| 23 | namespace gles2 { |
| 24 | |
| 25 | // State associated with each texture unit. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 26 | struct GPU_EXPORT TextureUnit { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 27 | TextureUnit(); |
| 28 | ~TextureUnit(); |
| 29 | |
| 30 | // The last target that was bound to this texture unit. |
| 31 | GLenum bind_target; |
| 32 | |
| 33 | // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture |
| 34 | TextureManager::TextureInfo::Ref bound_texture_2d; |
| 35 | |
| 36 | // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with |
| 37 | // glBindTexture |
| 38 | TextureManager::TextureInfo::Ref bound_texture_cube_map; |
| 39 | |
| 40 | // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with |
| 41 | // glBindTexture |
| 42 | TextureManager::TextureInfo::Ref bound_texture_external_oes; |
| 43 | |
| 44 | // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with |
| 45 | // glBindTexture |
| 46 | TextureManager::TextureInfo::Ref bound_texture_rectangle_arb; |
| 47 | |
| 48 | TextureManager::TextureInfo::Ref GetInfoForSamplerType(GLenum type) { |
| 49 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
| 50 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 51 | switch (type) { |
| 52 | case GL_SAMPLER_2D: |
| 53 | return bound_texture_2d; |
| 54 | case GL_SAMPLER_CUBE: |
| 55 | return bound_texture_cube_map; |
| 56 | case GL_SAMPLER_EXTERNAL_OES: |
| 57 | return bound_texture_external_oes; |
| 58 | case GL_SAMPLER_2D_RECT_ARB: |
| 59 | return bound_texture_rectangle_arb; |
| 60 | } |
| 61 | |
| 62 | NOTREACHED(); |
| 63 | return NULL; |
| 64 | } |
| 65 | |
| 66 | void Unbind(TextureManager::TextureInfo* texture) { |
| 67 | if (bound_texture_2d == texture) { |
| 68 | bound_texture_2d = NULL; |
| 69 | } |
| 70 | if (bound_texture_cube_map == texture) { |
| 71 | bound_texture_cube_map = NULL; |
| 72 | } |
| 73 | if (bound_texture_external_oes == texture) { |
| 74 | bound_texture_external_oes = NULL; |
| 75 | } |
| 76 | } |
| 77 | }; |
| 78 | |
| 79 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 80 | struct GPU_EXPORT ContextState { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 81 | ContextState(); |
| 82 | ~ContextState(); |
| 83 | |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame^] | 84 | void Initialize(); |
| 85 | |
| 86 | void InitCapabilities(); |
| 87 | void InitState(); |
| 88 | |
| 89 | #include "gpu/command_buffer/service/context_state_autogen.h" |
| 90 | |
| 91 | EnableFlags enable_flags; |
| 92 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 93 | // pack alignment as last set by glPixelStorei |
| 94 | GLint pack_alignment; |
| 95 | |
| 96 | // unpack alignment as last set by glPixelStorei |
| 97 | GLint unpack_alignment; |
| 98 | |
| 99 | // Current active texture by 0 - n index. |
| 100 | // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would |
| 101 | // be 2. |
| 102 | GLuint active_texture_unit; |
| 103 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 104 | // Cached values of the currently assigned viewport dimensions. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 105 | GLsizei viewport_max_width; |
| 106 | GLsizei viewport_max_height; |
| 107 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 108 | // The currently bound array buffer. If this is 0 it is illegal to call |
| 109 | // glVertexAttribPointer. |
| 110 | BufferManager::BufferInfo::Ref bound_array_buffer; |
| 111 | |
| 112 | // Which textures are bound to texture units through glActiveTexture. |
| 113 | scoped_array<TextureUnit> texture_units; |
| 114 | |
| 115 | // Class that manages vertex attribs. |
| 116 | VertexAttribManager::Ref vertex_attrib_manager; |
| 117 | |
| 118 | // The program in use by glUseProgram |
| 119 | ProgramManager::ProgramInfo::Ref current_program; |
| 120 | |
| 121 | // The currently bound framebuffers |
| 122 | FramebufferManager::FramebufferInfo::Ref bound_read_framebuffer; |
| 123 | FramebufferManager::FramebufferInfo::Ref bound_draw_framebuffer; |
| 124 | |
| 125 | // The currently bound renderbuffer |
| 126 | RenderbufferManager::RenderbufferInfo::Ref bound_renderbuffer; |
| 127 | |
| 128 | QueryManager::Query::Ref current_query; |
| 129 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 130 | GLenum hint_generate_mipmap; |
| 131 | GLenum hint_fragment_shader_derivative; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 132 | |
| 133 | bool pack_reverse_row_order; |
| 134 | }; |
| 135 | |
| 136 | } // namespace gles2 |
| 137 | } // namespace gpu |
| 138 | |
| 139 | #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ |
| 140 | |