[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 | |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 11 | #include <vector> |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 12 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 13 | #include "base/logging.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 14 | #include "gpu/command_buffer/service/gl_utils.h" |
bajones | 5141d03 | 2015-12-07 21:13:39 | [diff] [blame] | 15 | #include "gpu/command_buffer/service/sampler_manager.h" |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 16 | #include "gpu/command_buffer/service/shader_manager.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 17 | #include "gpu/command_buffer/service/texture_manager.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 18 | #include "gpu/command_buffer/service/vertex_array_manager.h" |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 19 | #include "gpu/command_buffer/service/vertex_attrib_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 | |
[email protected] | 31494b8 | 2013-02-28 10:10:26 | [diff] [blame] | 25 | class Buffer; |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 26 | class ErrorState; |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 27 | class ErrorStateClient; |
[email protected] | b3cbad1 | 2012-12-05 19:56:36 | [diff] [blame] | 28 | class FeatureInfo; |
zmo | 48ee6d3f | 2016-05-06 20:33:26 | [diff] [blame] | 29 | class IndexedBufferBindingHost; |
dyen | b245d37 | 2015-07-25 01:18:38 | [diff] [blame] | 30 | class Logger; |
[email protected] | 31494b8 | 2013-02-28 10:10:26 | [diff] [blame] | 31 | class Program; |
| 32 | class Renderbuffer; |
zmo | 6c468ba | 2016-05-04 20:00:51 | [diff] [blame] | 33 | class TransformFeedback; |
[email protected] | b3cbad1 | 2012-12-05 19:56:36 | [diff] [blame] | 34 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 35 | // State associated with each texture unit. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 36 | struct GPU_EXPORT TextureUnit { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 37 | TextureUnit(); |
vmpstr | 3b7b8b2 | 2016-03-01 23:00:20 | [diff] [blame] | 38 | TextureUnit(const TextureUnit& other); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 39 | ~TextureUnit(); |
| 40 | |
| 41 | // The last target that was bound to this texture unit. |
| 42 | GLenum bind_target; |
| 43 | |
| 44 | // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 45 | scoped_refptr<TextureRef> bound_texture_2d; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 46 | |
| 47 | // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with |
| 48 | // glBindTexture |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 49 | scoped_refptr<TextureRef> bound_texture_cube_map; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 50 | |
| 51 | // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with |
| 52 | // glBindTexture |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 53 | scoped_refptr<TextureRef> bound_texture_external_oes; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 54 | |
| 55 | // texture currently bound to this unit's GL_TEXTURE_RECTANGLE_ARB with |
| 56 | // glBindTexture |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 57 | scoped_refptr<TextureRef> bound_texture_rectangle_arb; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 58 | |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 59 | // texture currently bound to this unit's GL_TEXTURE_3D with glBindTexture |
| 60 | scoped_refptr<TextureRef> bound_texture_3d; |
| 61 | |
| 62 | // texture currently bound to this unit's GL_TEXTURE_2D_ARRAY with |
| 63 | // glBindTexture |
| 64 | scoped_refptr<TextureRef> bound_texture_2d_array; |
| 65 | |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 66 | TextureRef* GetInfoForSamplerType(GLenum type) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 67 | switch (type) { |
| 68 | case GL_SAMPLER_2D: |
zmo | 5e6600b | 2016-11-17 04:27:44 | [diff] [blame] | 69 | case GL_SAMPLER_2D_SHADOW: |
| 70 | case GL_INT_SAMPLER_2D: |
| 71 | case GL_UNSIGNED_INT_SAMPLER_2D: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 72 | return bound_texture_2d.get(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 73 | case GL_SAMPLER_CUBE: |
zmo | 5e6600b | 2016-11-17 04:27:44 | [diff] [blame] | 74 | case GL_SAMPLER_CUBE_SHADOW: |
| 75 | case GL_INT_SAMPLER_CUBE: |
| 76 | case GL_UNSIGNED_INT_SAMPLER_CUBE: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 77 | return bound_texture_cube_map.get(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 78 | case GL_SAMPLER_EXTERNAL_OES: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 79 | return bound_texture_external_oes.get(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 80 | case GL_SAMPLER_2D_RECT_ARB: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 81 | return bound_texture_rectangle_arb.get(); |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 82 | case GL_SAMPLER_3D: |
zmo | 5e6600b | 2016-11-17 04:27:44 | [diff] [blame] | 83 | case GL_INT_SAMPLER_3D: |
| 84 | case GL_UNSIGNED_INT_SAMPLER_3D: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 85 | return bound_texture_3d.get(); |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 86 | case GL_SAMPLER_2D_ARRAY: |
zmo | 5e6600b | 2016-11-17 04:27:44 | [diff] [blame] | 87 | case GL_SAMPLER_2D_ARRAY_SHADOW: |
| 88 | case GL_INT_SAMPLER_2D_ARRAY: |
| 89 | case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 90 | return bound_texture_2d_array.get(); |
| 91 | default: |
| 92 | NOTREACHED(); |
| 93 | return nullptr; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 94 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 95 | } |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 96 | |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 97 | TextureRef* GetInfoForTarget(GLenum target) { |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 98 | switch (target) { |
| 99 | case GL_TEXTURE_2D: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 100 | return bound_texture_2d.get(); |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 101 | case GL_TEXTURE_CUBE_MAP: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 102 | return bound_texture_cube_map.get(); |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 103 | case GL_TEXTURE_EXTERNAL_OES: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 104 | return bound_texture_external_oes.get(); |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 105 | case GL_TEXTURE_RECTANGLE_ARB: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 106 | return bound_texture_rectangle_arb.get(); |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 107 | case GL_TEXTURE_3D: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 108 | return bound_texture_3d.get(); |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 109 | case GL_TEXTURE_2D_ARRAY: |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 110 | return bound_texture_2d_array.get(); |
| 111 | default: |
| 112 | NOTREACHED(); |
| 113 | return nullptr; |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 114 | } |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 115 | } |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 116 | |
zmo | ebb40981 | 2017-02-08 19:13:58 | [diff] [blame] | 117 | void SetInfoForTarget(GLenum target, TextureRef* texture_ref) { |
| 118 | switch (target) { |
| 119 | case GL_TEXTURE_2D: |
| 120 | bound_texture_2d = texture_ref; |
| 121 | break; |
| 122 | case GL_TEXTURE_CUBE_MAP: |
| 123 | bound_texture_cube_map = texture_ref; |
| 124 | break; |
| 125 | case GL_TEXTURE_EXTERNAL_OES: |
| 126 | bound_texture_external_oes = texture_ref; |
| 127 | break; |
| 128 | case GL_TEXTURE_RECTANGLE_ARB: |
| 129 | bound_texture_rectangle_arb = texture_ref; |
| 130 | break; |
| 131 | case GL_TEXTURE_3D: |
| 132 | bound_texture_3d = texture_ref; |
| 133 | break; |
| 134 | case GL_TEXTURE_2D_ARRAY: |
| 135 | bound_texture_2d_array = texture_ref; |
| 136 | break; |
| 137 | default: |
| 138 | NOTREACHED(); |
| 139 | } |
erikchen | ffe273b | 2015-12-17 03:48:13 | [diff] [blame] | 140 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 141 | }; |
| 142 | |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 143 | class GPU_EXPORT Vec4 { |
| 144 | public: |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 145 | Vec4() { |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 146 | v_[0].float_value = 0.0f; |
| 147 | v_[1].float_value = 0.0f; |
| 148 | v_[2].float_value = 0.0f; |
| 149 | v_[3].float_value = 1.0f; |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 150 | type_ = SHADER_VARIABLE_FLOAT; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 151 | } |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 152 | |
| 153 | template <typename T> |
| 154 | void GetValues(T* values) const; |
| 155 | |
| 156 | template <typename T> |
| 157 | void SetValues(const T* values); |
| 158 | |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 159 | ShaderVariableBaseType type() const { |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 160 | return type_; |
| 161 | } |
| 162 | |
| 163 | bool Equal(const Vec4& other) const; |
| 164 | |
| 165 | private: |
| 166 | union ValueUnion { |
| 167 | GLfloat float_value; |
| 168 | GLint int_value; |
| 169 | GLuint uint_value; |
| 170 | }; |
| 171 | |
| 172 | ValueUnion v_[4]; |
zmo | eaae3bb | 2016-07-15 19:23:19 | [diff] [blame] | 173 | ShaderVariableBaseType type_; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 174 | }; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 175 | |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 176 | template <> |
| 177 | GPU_EXPORT void Vec4::GetValues<GLfloat>(GLfloat* values) const; |
| 178 | template <> |
| 179 | GPU_EXPORT void Vec4::GetValues<GLint>(GLint* values) const; |
| 180 | template <> |
| 181 | GPU_EXPORT void Vec4::GetValues<GLuint>(GLuint* values) const; |
| 182 | |
| 183 | template <> |
| 184 | GPU_EXPORT void Vec4::SetValues<GLfloat>(const GLfloat* values); |
| 185 | template <> |
| 186 | GPU_EXPORT void Vec4::SetValues<GLint>(const GLint* values); |
| 187 | template <> |
| 188 | GPU_EXPORT void Vec4::SetValues<GLuint>(const GLuint* values); |
| 189 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 190 | struct GPU_EXPORT ContextState { |
zmo | 2b9c4739 | 2015-12-11 02:21:32 | [diff] [blame] | 191 | enum Dimension { |
| 192 | k2D, |
| 193 | k3D |
| 194 | }; |
| 195 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 196 | ContextState(FeatureInfo* feature_info, |
| 197 | ErrorStateClient* error_state_client, |
| 198 | Logger* logger); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 199 | ~ContextState(); |
| 200 | |
Antoine Labour | 2c1ad96 | 2017-10-24 23:32:56 | [diff] [blame] | 201 | void set_api(gl::GLApi* api) { api_ = api; } |
| 202 | gl::GLApi* api() const { return api_; } |
| 203 | |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 204 | void Initialize(); |
| 205 | |
lof84 | d5e3696 | 2016-11-10 00:35:54 | [diff] [blame] | 206 | void SetLineWidthBounds(GLfloat min, GLfloat max); |
| 207 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 208 | void SetIgnoreCachedStateForTest(bool ignore) { |
| 209 | ignore_cached_state = ignore; |
| 210 | } |
| 211 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 212 | void RestoreState(const ContextState* prev_state); |
[email protected] | 88ba52f | 2014-04-09 12:39:34 | [diff] [blame] | 213 | void InitCapabilities(const ContextState* prev_state) const; |
| 214 | void InitState(const ContextState* prev_state) const; |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 215 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 216 | void RestoreActiveTexture() const; |
kbr | 69c721ec | 2017-04-26 23:58:51 | [diff] [blame] | 217 | void RestoreAllTextureUnitAndSamplerBindings( |
| 218 | const ContextState* prev_state) const; |
[email protected] | 4b2d2b26 | 2014-03-21 22:05:27 | [diff] [blame] | 219 | void RestoreActiveTextureUnitBinding(unsigned int target) const; |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 220 | void RestoreVertexAttribValues() const; |
| 221 | void RestoreVertexAttribArrays( |
| 222 | const scoped_refptr<VertexAttribManager> attrib_manager) const; |
| 223 | void RestoreVertexAttribs() const; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 224 | void RestoreBufferBindings() const; |
[email protected] | 88ba52f | 2014-04-09 12:39:34 | [diff] [blame] | 225 | void RestoreGlobalState(const ContextState* prev_state) const; |
zmo | 744d40e | 2016-05-10 20:56:22 | [diff] [blame] | 226 | void RestoreProgramSettings(const ContextState* prev_state, |
| 227 | bool restore_transform_feedback_bindings) const; |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 228 | void RestoreRenderbufferBindings(); |
zmo | 48ee6d3f | 2016-05-06 20:33:26 | [diff] [blame] | 229 | void RestoreIndexedUniformBufferBindings(const ContextState* prev_state); |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 230 | void RestoreTextureUnitBindings( |
| 231 | GLuint unit, const ContextState* prev_state) const; |
kbr | 69c721ec | 2017-04-26 23:58:51 | [diff] [blame] | 232 | void RestoreSamplerBinding(GLuint unit, const ContextState* prev_state) const; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 233 | |
Zhenyao Mo | 5f72df0c | 2017-12-08 21:46:26 | [diff] [blame] | 234 | void PushTextureUnpackState() const; |
geofflang | 398fb21 | 2016-07-13 16:27:42 | [diff] [blame] | 235 | void RestoreUnpackState() const; |
lof84 | d5e3696 | 2016-11-10 00:35:54 | [diff] [blame] | 236 | void DoLineWidth(GLfloat width) const; |
geofflang | 398fb21 | 2016-07-13 16:27:42 | [diff] [blame] | 237 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 238 | // Helper for getting cached state. |
| 239 | bool GetStateAsGLint( |
| 240 | GLenum pname, GLint* params, GLsizei* num_written) const; |
| 241 | bool GetStateAsGLfloat( |
| 242 | GLenum pname, GLfloat* params, GLsizei* num_written) const; |
| 243 | bool GetEnabled(GLenum cap) const; |
| 244 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 245 | inline void SetDeviceColorMask(GLboolean red, |
| 246 | GLboolean green, |
| 247 | GLboolean blue, |
| 248 | GLboolean alpha) { |
| 249 | if (cached_color_mask_red == red && cached_color_mask_green == green && |
| 250 | cached_color_mask_blue == blue && cached_color_mask_alpha == alpha && |
| 251 | !ignore_cached_state) |
| 252 | return; |
| 253 | cached_color_mask_red = red; |
| 254 | cached_color_mask_green = green; |
| 255 | cached_color_mask_blue = blue; |
| 256 | cached_color_mask_alpha = alpha; |
Antoine Labour | 2c1ad96 | 2017-10-24 23:32:56 | [diff] [blame] | 257 | api()->glColorMaskFn(red, green, blue, alpha); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | inline void SetDeviceDepthMask(GLboolean mask) { |
| 261 | if (cached_depth_mask == mask && !ignore_cached_state) |
| 262 | return; |
| 263 | cached_depth_mask = mask; |
Antoine Labour | 2c1ad96 | 2017-10-24 23:32:56 | [diff] [blame] | 264 | api()->glDepthMaskFn(mask); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | inline void SetDeviceStencilMaskSeparate(GLenum op, GLuint mask) { |
| 268 | if (op == GL_FRONT) { |
| 269 | if (cached_stencil_front_writemask == mask && !ignore_cached_state) |
| 270 | return; |
| 271 | cached_stencil_front_writemask = mask; |
| 272 | } else if (op == GL_BACK) { |
| 273 | if (cached_stencil_back_writemask == mask && !ignore_cached_state) |
| 274 | return; |
| 275 | cached_stencil_back_writemask = mask; |
| 276 | } else { |
| 277 | NOTREACHED(); |
| 278 | return; |
| 279 | } |
Antoine Labour | 2c1ad96 | 2017-10-24 23:32:56 | [diff] [blame] | 280 | api()->glStencilMaskSeparateFn(op, mask); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 281 | } |
| 282 | |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 283 | ErrorState* GetErrorState(); |
| 284 | |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 285 | void SetBoundBuffer(GLenum target, Buffer* buffer); |
| 286 | void RemoveBoundBuffer(Buffer* buffer); |
| 287 | |
zmo | 773ceaef5 | 2016-07-26 05:09:57 | [diff] [blame] | 288 | void InitGenericAttribs(GLuint max_vertex_attribs) { |
| 289 | attrib_values.resize(max_vertex_attribs); |
yunchao.he | c487531 | 2016-07-22 16:11:07 | [diff] [blame] | 290 | |
zmo | 773ceaef5 | 2016-07-26 05:09:57 | [diff] [blame] | 291 | uint32_t packed_size = max_vertex_attribs / 16; |
| 292 | packed_size += (max_vertex_attribs % 16 == 0) ? 0 : 1; |
| 293 | generic_attrib_base_type_mask_.resize(packed_size); |
| 294 | for (uint32_t i = 0; i < packed_size; ++i) { |
| 295 | // All generic attribs are float type by default. |
| 296 | generic_attrib_base_type_mask_[i] = 0x55555555u * SHADER_VARIABLE_FLOAT; |
| 297 | } |
yunchao.he | c487531 | 2016-07-22 16:11:07 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void SetGenericVertexAttribBaseType(GLuint index, GLenum base_type) { |
zmo | 773ceaef5 | 2016-07-26 05:09:57 | [diff] [blame] | 301 | DCHECK_LT(index, attrib_values.size()); |
yunchao.he | c487531 | 2016-07-22 16:11:07 | [diff] [blame] | 302 | int shift_bits = (index % 16) * 2; |
| 303 | generic_attrib_base_type_mask_[index / 16] &= ~(0x3 << shift_bits); |
| 304 | generic_attrib_base_type_mask_[index / 16] |= (base_type << shift_bits); |
| 305 | } |
| 306 | |
zmo | 773ceaef5 | 2016-07-26 05:09:57 | [diff] [blame] | 307 | const std::vector<uint32_t>& generic_attrib_base_type_mask() const { |
| 308 | return generic_attrib_base_type_mask_; |
yunchao.he | c487531 | 2016-07-22 16:11:07 | [diff] [blame] | 309 | } |
| 310 | |
bajones | 2b98b2a | 2015-09-15 02:27:36 | [diff] [blame] | 311 | void UnbindTexture(TextureRef* texture); |
bajones | 5141d03 | 2015-12-07 21:13:39 | [diff] [blame] | 312 | void UnbindSampler(Sampler* sampler); |
bajones | 2b98b2a | 2015-09-15 02:27:36 | [diff] [blame] | 313 | |
zmo | 2b9c4739 | 2015-12-11 02:21:32 | [diff] [blame] | 314 | PixelStoreParams GetPackParams(); |
| 315 | PixelStoreParams GetUnpackParams(Dimension dimension); |
| 316 | |
c.padhi | b0a7f41 | 2017-04-06 06:56:10 | [diff] [blame] | 317 | // If a buffer object is bound to PIXEL_PACK_BUFFER, set all pack parameters |
| 318 | // user values; otherwise, set them to 0. |
| 319 | void UpdatePackParameters() const; |
| 320 | // If a buffer object is bound to PIXEL_UNPACK_BUFFER, set all unpack |
| 321 | // parameters user values; otherwise, set them to 0. |
| 322 | void UpdateUnpackParameters() const; |
| 323 | |
Kai Ninomiya | bcbefdab | 2017-11-03 19:57:27 | [diff] [blame] | 324 | void SetMaxWindowRectangles(size_t max); |
| 325 | size_t GetMaxWindowRectangles() const; |
| 326 | void SetWindowRectangles(GLenum mode, |
| 327 | size_t count, |
| 328 | const volatile GLint* box); |
| 329 | template <typename T> |
| 330 | void GetWindowRectangle(GLuint index, T* box) { |
| 331 | for (size_t i = 0; i < 4; ++i) { |
| 332 | box[i] = window_rectangles_[4 * index + i]; |
| 333 | } |
| 334 | } |
| 335 | void UpdateWindowRectangles() const; |
| 336 | void UpdateWindowRectanglesForBoundDrawFramebufferClientID(GLuint client_id); |
| 337 | |
zmo | 0ed7192 | 2016-06-23 01:18:42 | [diff] [blame] | 338 | void EnableDisableFramebufferSRGB(bool enable); |
| 339 | |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 340 | #include "gpu/command_buffer/service/context_state_autogen.h" |
| 341 | |
| 342 | EnableFlags enable_flags; |
| 343 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 344 | // Current active texture by 0 - n index. |
| 345 | // In other words, if we call glActiveTexture(GL_TEXTURE2) this value would |
| 346 | // be 2. |
| 347 | GLuint active_texture_unit; |
| 348 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 349 | // The currently bound array buffer. If this is 0 it is illegal to call |
| 350 | // glVertexAttribPointer. |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 351 | scoped_refptr<Buffer> bound_array_buffer; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 352 | |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 353 | scoped_refptr<Buffer> bound_copy_read_buffer; |
| 354 | scoped_refptr<Buffer> bound_copy_write_buffer; |
| 355 | scoped_refptr<Buffer> bound_pixel_pack_buffer; |
| 356 | scoped_refptr<Buffer> bound_pixel_unpack_buffer; |
| 357 | scoped_refptr<Buffer> bound_transform_feedback_buffer; |
| 358 | scoped_refptr<Buffer> bound_uniform_buffer; |
| 359 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 360 | // Which textures are bound to texture units through glActiveTexture. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 361 | std::vector<TextureUnit> texture_units; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 362 | |
bajones | 5141d03 | 2015-12-07 21:13:39 | [diff] [blame] | 363 | // Which samplers are bound to each texture unit; |
| 364 | std::vector<scoped_refptr<Sampler>> sampler_units; |
| 365 | |
zmo | 6c468ba | 2016-05-04 20:00:51 | [diff] [blame] | 366 | // We create a transform feedback as the default one per ES3 enabled context |
| 367 | // instead of using GL's default one to make context switching easier. |
| 368 | // For other context, we will never change the default transform feedback's |
| 369 | // states, so we can just use the GL's default one. |
| 370 | scoped_refptr<TransformFeedback> default_transform_feedback; |
| 371 | |
| 372 | scoped_refptr<TransformFeedback> bound_transform_feedback; |
| 373 | |
zmo | 48ee6d3f | 2016-05-06 20:33:26 | [diff] [blame] | 374 | scoped_refptr<IndexedBufferBindingHost> indexed_uniform_buffer_bindings; |
| 375 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 376 | // The values for each attrib. |
| 377 | std::vector<Vec4> attrib_values; |
| 378 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 379 | // Class that manages vertex attribs. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 380 | scoped_refptr<VertexAttribManager> vertex_attrib_manager; |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 381 | scoped_refptr<VertexAttribManager> default_vertex_attrib_manager; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 382 | |
| 383 | // The program in use by glUseProgram |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 384 | scoped_refptr<Program> current_program; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 385 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 386 | // The currently bound renderbuffer |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 387 | scoped_refptr<Renderbuffer> bound_renderbuffer; |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 388 | bool bound_renderbuffer_valid; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 389 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 390 | bool pack_reverse_row_order; |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 391 | bool ignore_cached_state; |
[email protected] | b3cbad1 | 2012-12-05 19:56:36 | [diff] [blame] | 392 | |
zmo | 8ac3bab | 2015-04-18 02:30:58 | [diff] [blame] | 393 | mutable bool fbo_binding_for_scissor_workaround_dirty; |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 394 | |
Kai Ninomiya | bcbefdab | 2017-11-03 19:57:27 | [diff] [blame] | 395 | GLuint current_draw_framebuffer_client_id = 0; |
| 396 | |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 397 | private: |
zmo | 8ac3bab | 2015-04-18 02:30:58 | [diff] [blame] | 398 | void EnableDisable(GLenum pname, bool enable) const; |
| 399 | |
zmo | b730f32b | 2016-01-06 20:39:08 | [diff] [blame] | 400 | void InitStateManual(const ContextState* prev_state) const; |
| 401 | |
ccameron | ddaa56a | 2016-12-02 04:05:46 | [diff] [blame] | 402 | // EnableDisableFramebufferSRGB is called at very high frequency. Cache the |
| 403 | // true value of FRAMEBUFFER_SRGB, if we know it, to elide some of these |
| 404 | // calls. |
| 405 | bool framebuffer_srgb_valid_ = false; |
| 406 | bool framebuffer_srgb_ = false; |
zmo | 0ed7192 | 2016-06-23 01:18:42 | [diff] [blame] | 407 | |
yunchao.he | c487531 | 2016-07-22 16:11:07 | [diff] [blame] | 408 | // Generic vertex attrib base types: FLOAT, INT, or UINT. |
| 409 | // Each base type is encoded into 2 bits, the lowest 2 bits for location 0, |
zmo | 773ceaef5 | 2016-07-26 05:09:57 | [diff] [blame] | 410 | // the highest 2 bits for location (max_vertex_attribs - 1). |
yunchao.he | c487531 | 2016-07-22 16:11:07 | [diff] [blame] | 411 | std::vector<uint32_t> generic_attrib_base_type_mask_; |
| 412 | |
lof84 | d5e3696 | 2016-11-10 00:35:54 | [diff] [blame] | 413 | GLfloat line_width_min_ = 0.0f; |
| 414 | GLfloat line_width_max_ = 1.0f; |
| 415 | |
Kai Ninomiya | bcbefdab | 2017-11-03 19:57:27 | [diff] [blame] | 416 | // Stores the list of N window rectangles as N*4 GLints, like |
| 417 | // vector<[x,y,w,h]>. Always has space for MAX_WINDOW_RECTANGLES rectangles. |
| 418 | std::vector<GLint> window_rectangles_; |
| 419 | |
Antoine Labour | 2c1ad96 | 2017-10-24 23:32:56 | [diff] [blame] | 420 | gl::GLApi* api_ = nullptr; |
zmo | 8ac3bab | 2015-04-18 02:30:58 | [diff] [blame] | 421 | FeatureInfo* feature_info_; |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 422 | std::unique_ptr<ErrorState> error_state_; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | } // namespace gles2 |
| 426 | } // namespace gpu |
| 427 | |
| 428 | #endif // GPU_COMMAND_BUFFER_SERVICE_CONTEXT_STATE_H_ |