[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 | |||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 10 | #include <vector> |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 11 | #include "base/logging.h" |
12 | #include "gpu/command_buffer/service/gl_utils.h" | ||||
13 | #include "gpu/command_buffer/service/buffer_manager.h" | ||||
14 | #include "gpu/command_buffer/service/framebuffer_manager.h" | ||||
15 | #include "gpu/command_buffer/service/program_manager.h" | ||||
16 | #include "gpu/command_buffer/service/query_manager.h" | ||||
17 | #include "gpu/command_buffer/service/renderbuffer_manager.h" | ||||
18 | #include "gpu/command_buffer/service/texture_manager.h" | ||||
19 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" | ||||
20 | #include "gpu/command_buffer/service/vertex_array_manager.h" | ||||
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 21 | #include "gpu/gpu_export.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 22 | |
23 | namespace gpu { | ||||
24 | namespace gles2 { | ||||
25 | |||||
[email protected] | b3cbad1 | 2012-12-05 19:56:36 | [diff] [blame] | 26 | class FeatureInfo; |
27 | |||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 28 | // State associated with each texture unit. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 29 | struct GPU_EXPORT TextureUnit { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 30 | TextureUnit(); |
31 | ~TextureUnit(); | ||||
32 | |||||
33 | // The last target that was bound to this texture unit. | ||||
34 | GLenum bind_target; | ||||
35 | |||||
36 | // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture | ||||
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 37 | scoped_refptr<Texture> bound_texture_2d; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 38 | |
39 | // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with | ||||
40 | // glBindTexture | ||||
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 41 | scoped_refptr<Texture> bound_texture_cube_map; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 42 | |
43 | // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with | ||||
44 | // glBindTexture | ||||
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 45 | scoped_refptr<Texture> bound_texture_external_oes; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 46 | |
47 | // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with | ||||
48 | // glBindTexture | ||||
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 49 | scoped_refptr<Texture> bound_texture_rectangle_arb; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 50 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 51 | scoped_refptr<Texture> GetInfoForSamplerType( |
52 | GLenum type) { | ||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 53 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
54 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); | ||||
55 | switch (type) { | ||||
56 | case GL_SAMPLER_2D: | ||||
57 | return bound_texture_2d; | ||||
58 | case GL_SAMPLER_CUBE: | ||||
59 | return bound_texture_cube_map; | ||||
60 | case GL_SAMPLER_EXTERNAL_OES: | ||||
61 | return bound_texture_external_oes; | ||||
62 | case GL_SAMPLER_2D_RECT_ARB: | ||||
63 | return bound_texture_rectangle_arb; | ||||
64 | } | ||||
65 | |||||
66 | NOTREACHED(); | ||||
67 | return NULL; | ||||
68 | } | ||||
69 | |||||
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 70 | void Unbind(Texture* texture) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 71 | if (bound_texture_2d == texture) { |
72 | bound_texture_2d = NULL; | ||||
73 | } | ||||
74 | if (bound_texture_cube_map == texture) { | ||||
75 | bound_texture_cube_map = NULL; | ||||
76 | } | ||||
77 | if (bound_texture_external_oes == texture) { | ||||
78 | bound_texture_external_oes = NULL; | ||||
79 | } | ||||
80 | } | ||||
81 | }; | ||||
82 | |||||
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 83 | struct Vec4 { |
84 | Vec4() { | ||||
85 | v[0] = 0.0f; | ||||
86 | v[1] = 0.0f; | ||||
87 | v[2] = 0.0f; | ||||
88 | v[3] = 1.0f; | ||||
89 | } | ||||
90 | float v[4]; | ||||
91 | }; | ||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 92 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 93 | struct GPU_EXPORT ContextState { |
[email protected] | b3cbad1 | 2012-12-05 19:56:36 | [diff] [blame] | 94 | explicit ContextState(FeatureInfo* feature_info); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 95 | ~ContextState(); |
96 | |||||
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 97 | void Initialize(); |
98 | |||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 99 | void RestoreState() const; |
100 | void InitCapabilities() const; | ||||
101 | void InitState() const; | ||||
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 102 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 103 | void RestoreActiveTexture() const; |
104 | void RestoreAttribute(GLuint index) const; | ||||
105 | void RestoreBufferBindings() const; | ||||
106 | void RestoreGlobalState() const; | ||||
107 | void RestoreProgramBindings() const; | ||||
108 | void RestoreRenderbufferBindings() const; | ||||
109 | void RestoreTextureUnitBindings(GLuint unit) const; | ||||
110 | |||||
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 111 | // Helper for getting cached state. |
112 | bool GetStateAsGLint( | ||||
113 | GLenum pname, GLint* params, GLsizei* num_written) const; | ||||
114 | bool GetStateAsGLfloat( | ||||
115 | GLenum pname, GLfloat* params, GLsizei* num_written) const; | ||||
116 | bool GetEnabled(GLenum cap) const; | ||||
117 | |||||
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 118 | #include "gpu/command_buffer/service/context_state_autogen.h" |
119 | |||||
120 | EnableFlags enable_flags; | ||||
121 | |||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 122 | // pack alignment as last set by glPixelStorei |
123 | GLint pack_alignment; | ||||
124 | |||||
125 | // unpack alignment as last set by glPixelStorei | ||||
126 | GLint unpack_alignment; | ||||
127 | |||||
128 | // Current active texture by 0 - n index. | ||||
129 | // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would | ||||
130 | // be 2. | ||||
131 | GLuint active_texture_unit; | ||||
132 | |||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 133 | // The currently bound array buffer. If this is 0 it is illegal to call |
134 | // glVertexAttribPointer. | ||||
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame^] | 135 | scoped_refptr<Buffer> bound_array_buffer; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 136 | |
137 | // Which textures are bound to texture units through glActiveTexture. | ||||
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 138 | std::vector<TextureUnit> texture_units; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 139 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 140 | // The values for each attrib. |
141 | std::vector<Vec4> attrib_values; | ||||
142 | |||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 143 | // Class that manages vertex attribs. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 144 | scoped_refptr<VertexAttribManager> vertex_attrib_manager; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 145 | |
146 | // The program in use by glUseProgram | ||||
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 147 | scoped_refptr<Program> current_program; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 148 | |
149 | // The currently bound framebuffers | ||||
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 150 | scoped_refptr<Framebuffer> bound_read_framebuffer; |
151 | scoped_refptr<Framebuffer> bound_draw_framebuffer; | ||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 152 | |
153 | // The currently bound renderbuffer | ||||
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 154 | scoped_refptr<Renderbuffer> bound_renderbuffer; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 155 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 156 | scoped_refptr<QueryManager::Query> current_query; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 157 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 158 | GLenum hint_generate_mipmap; |
159 | GLenum hint_fragment_shader_derivative; | ||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 160 | |
161 | bool pack_reverse_row_order; | ||||
[email protected] | b3cbad1 | 2012-12-05 19:56:36 | [diff] [blame] | 162 | |
163 | FeatureInfo* feature_info_; | ||||
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 164 | }; |
165 | |||||
166 | } // namespace gles2 | ||||
167 | } // namespace gpu | ||||
168 | |||||
169 | #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ | ||||
170 |