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