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