summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-10-29 21:24:34 -0300
committerGravatar ReinUsesLisp2019-10-29 21:27:25 -0300
commitce20ed8e4eecfcf04a801fe0f539df520a5e5042 (patch)
treef1255be431cc48381534f5657b828c9d5e6b2c57 /src
parentgl_state: Remove ApplyDefaultState (diff)
downloadyuzu-ce20ed8e4eecfcf04a801fe0f539df520a5e5042.tar.gz
yuzu-ce20ed8e4eecfcf04a801fe0f539df520a5e5042.tar.xz
yuzu-ce20ed8e4eecfcf04a801fe0f539df520a5e5042.zip
gl_state: Move dirty checks to individual apply calls instead of Apply
This requires removing constness from some methods, but for consistency it's removed in all methods.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp90
-rw-r--r--src/video_core/renderer_opengl/gl_state.h50
2 files changed, 74 insertions, 66 deletions
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index 48c123ffe..c431a8635 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -92,7 +92,7 @@ void OpenGLState::SetDefaultViewports() {
92 depth_clamp.near_plane = false; 92 depth_clamp.near_plane = false;
93} 93}
94 94
95void OpenGLState::ApplyFramebufferState() const { 95void OpenGLState::ApplyFramebufferState() {
96 if (UpdateValue(cur_state.draw.read_framebuffer, draw.read_framebuffer)) { 96 if (UpdateValue(cur_state.draw.read_framebuffer, draw.read_framebuffer)) {
97 glBindFramebuffer(GL_READ_FRAMEBUFFER, draw.read_framebuffer); 97 glBindFramebuffer(GL_READ_FRAMEBUFFER, draw.read_framebuffer);
98 } 98 }
@@ -101,52 +101,52 @@ void OpenGLState::ApplyFramebufferState() const {
101 } 101 }
102} 102}
103 103
104void OpenGLState::ApplyVertexArrayState() const { 104void OpenGLState::ApplyVertexArrayState() {
105 if (UpdateValue(cur_state.draw.vertex_array, draw.vertex_array)) { 105 if (UpdateValue(cur_state.draw.vertex_array, draw.vertex_array)) {
106 glBindVertexArray(draw.vertex_array); 106 glBindVertexArray(draw.vertex_array);
107 } 107 }
108} 108}
109 109
110void OpenGLState::ApplyShaderProgram() const { 110void OpenGLState::ApplyShaderProgram() {
111 if (UpdateValue(cur_state.draw.shader_program, draw.shader_program)) { 111 if (UpdateValue(cur_state.draw.shader_program, draw.shader_program)) {
112 glUseProgram(draw.shader_program); 112 glUseProgram(draw.shader_program);
113 } 113 }
114} 114}
115 115
116void OpenGLState::ApplyProgramPipeline() const { 116void OpenGLState::ApplyProgramPipeline() {
117 if (UpdateValue(cur_state.draw.program_pipeline, draw.program_pipeline)) { 117 if (UpdateValue(cur_state.draw.program_pipeline, draw.program_pipeline)) {
118 glBindProgramPipeline(draw.program_pipeline); 118 glBindProgramPipeline(draw.program_pipeline);
119 } 119 }
120} 120}
121 121
122void OpenGLState::ApplyClipDistances() const { 122void OpenGLState::ApplyClipDistances() {
123 for (std::size_t i = 0; i < clip_distance.size(); ++i) { 123 for (std::size_t i = 0; i < clip_distance.size(); ++i) {
124 Enable(GL_CLIP_DISTANCE0 + static_cast<GLenum>(i), cur_state.clip_distance[i], 124 Enable(GL_CLIP_DISTANCE0 + static_cast<GLenum>(i), cur_state.clip_distance[i],
125 clip_distance[i]); 125 clip_distance[i]);
126 } 126 }
127} 127}
128 128
129void OpenGLState::ApplyPointSize() const { 129void OpenGLState::ApplyPointSize() {
130 if (UpdateValue(cur_state.point.size, point.size)) { 130 if (UpdateValue(cur_state.point.size, point.size)) {
131 glPointSize(point.size); 131 glPointSize(point.size);
132 } 132 }
133} 133}
134 134
135void OpenGLState::ApplyFragmentColorClamp() const { 135void OpenGLState::ApplyFragmentColorClamp() {
136 if (UpdateValue(cur_state.fragment_color_clamp.enabled, fragment_color_clamp.enabled)) { 136 if (UpdateValue(cur_state.fragment_color_clamp.enabled, fragment_color_clamp.enabled)) {
137 glClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB, 137 glClampColor(GL_CLAMP_FRAGMENT_COLOR_ARB,
138 fragment_color_clamp.enabled ? GL_TRUE : GL_FALSE); 138 fragment_color_clamp.enabled ? GL_TRUE : GL_FALSE);
139 } 139 }
140} 140}
141 141
142void OpenGLState::ApplyMultisample() const { 142void OpenGLState::ApplyMultisample() {
143 Enable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur_state.multisample_control.alpha_to_coverage, 143 Enable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur_state.multisample_control.alpha_to_coverage,
144 multisample_control.alpha_to_coverage); 144 multisample_control.alpha_to_coverage);
145 Enable(GL_SAMPLE_ALPHA_TO_ONE, cur_state.multisample_control.alpha_to_one, 145 Enable(GL_SAMPLE_ALPHA_TO_ONE, cur_state.multisample_control.alpha_to_one,
146 multisample_control.alpha_to_one); 146 multisample_control.alpha_to_one);
147} 147}
148 148
149void OpenGLState::ApplyDepthClamp() const { 149void OpenGLState::ApplyDepthClamp() {
150 if (depth_clamp.far_plane == cur_state.depth_clamp.far_plane && 150 if (depth_clamp.far_plane == cur_state.depth_clamp.far_plane &&
151 depth_clamp.near_plane == cur_state.depth_clamp.near_plane) { 151 depth_clamp.near_plane == cur_state.depth_clamp.near_plane) {
152 return; 152 return;
@@ -159,7 +159,7 @@ void OpenGLState::ApplyDepthClamp() const {
159 Enable(GL_DEPTH_CLAMP, depth_clamp.far_plane || depth_clamp.near_plane); 159 Enable(GL_DEPTH_CLAMP, depth_clamp.far_plane || depth_clamp.near_plane);
160} 160}
161 161
162void OpenGLState::ApplySRgb() const { 162void OpenGLState::ApplySRgb() {
163 if (cur_state.framebuffer_srgb.enabled == framebuffer_srgb.enabled) 163 if (cur_state.framebuffer_srgb.enabled == framebuffer_srgb.enabled)
164 return; 164 return;
165 cur_state.framebuffer_srgb.enabled = framebuffer_srgb.enabled; 165 cur_state.framebuffer_srgb.enabled = framebuffer_srgb.enabled;
@@ -170,7 +170,7 @@ void OpenGLState::ApplySRgb() const {
170 } 170 }
171} 171}
172 172
173void OpenGLState::ApplyCulling() const { 173void OpenGLState::ApplyCulling() {
174 Enable(GL_CULL_FACE, cur_state.cull.enabled, cull.enabled); 174 Enable(GL_CULL_FACE, cur_state.cull.enabled, cull.enabled);
175 175
176 if (UpdateValue(cur_state.cull.mode, cull.mode)) { 176 if (UpdateValue(cur_state.cull.mode, cull.mode)) {
@@ -182,7 +182,12 @@ void OpenGLState::ApplyCulling() const {
182 } 182 }
183} 183}
184 184
185void OpenGLState::ApplyColorMask() const { 185void OpenGLState::ApplyColorMask() {
186 if (!dirty.color_mask) {
187 return;
188 }
189 dirty.color_mask = false;
190
186 for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) { 191 for (std::size_t i = 0; i < Maxwell::NumRenderTargets; ++i) {
187 const auto& updated = color_mask[i]; 192 const auto& updated = color_mask[i];
188 auto& current = cur_state.color_mask[i]; 193 auto& current = cur_state.color_mask[i];
@@ -197,7 +202,7 @@ void OpenGLState::ApplyColorMask() const {
197 } 202 }
198} 203}
199 204
200void OpenGLState::ApplyDepth() const { 205void OpenGLState::ApplyDepth() {
201 Enable(GL_DEPTH_TEST, cur_state.depth.test_enabled, depth.test_enabled); 206 Enable(GL_DEPTH_TEST, cur_state.depth.test_enabled, depth.test_enabled);
202 207
203 if (cur_state.depth.test_func != depth.test_func) { 208 if (cur_state.depth.test_func != depth.test_func) {
@@ -211,7 +216,7 @@ void OpenGLState::ApplyDepth() const {
211 } 216 }
212} 217}
213 218
214void OpenGLState::ApplyPrimitiveRestart() const { 219void OpenGLState::ApplyPrimitiveRestart() {
215 Enable(GL_PRIMITIVE_RESTART, cur_state.primitive_restart.enabled, primitive_restart.enabled); 220 Enable(GL_PRIMITIVE_RESTART, cur_state.primitive_restart.enabled, primitive_restart.enabled);
216 221
217 if (cur_state.primitive_restart.index != primitive_restart.index) { 222 if (cur_state.primitive_restart.index != primitive_restart.index) {
@@ -220,7 +225,12 @@ void OpenGLState::ApplyPrimitiveRestart() const {
220 } 225 }
221} 226}
222 227
223void OpenGLState::ApplyStencilTest() const { 228void OpenGLState::ApplyStencilTest() {
229 if (!dirty.stencil_state) {
230 return;
231 }
232 dirty.stencil_state = false;
233
224 Enable(GL_STENCIL_TEST, cur_state.stencil.test_enabled, stencil.test_enabled); 234 Enable(GL_STENCIL_TEST, cur_state.stencil.test_enabled, stencil.test_enabled);
225 235
226 const auto ConfigStencil = [](GLenum face, const auto& config, auto& current) { 236 const auto ConfigStencil = [](GLenum face, const auto& config, auto& current) {
@@ -249,7 +259,7 @@ void OpenGLState::ApplyStencilTest() const {
249 ConfigStencil(GL_BACK, stencil.back, cur_state.stencil.back); 259 ConfigStencil(GL_BACK, stencil.back, cur_state.stencil.back);
250} 260}
251 261
252void OpenGLState::ApplyViewport() const { 262void OpenGLState::ApplyViewport() {
253 for (GLuint i = 0; i < static_cast<GLuint>(Maxwell::NumViewports); ++i) { 263 for (GLuint i = 0; i < static_cast<GLuint>(Maxwell::NumViewports); ++i) {
254 const auto& updated = viewports[i]; 264 const auto& updated = viewports[i];
255 auto& current = cur_state.viewports[i]; 265 auto& current = cur_state.viewports[i];
@@ -286,7 +296,7 @@ void OpenGLState::ApplyViewport() const {
286 } 296 }
287} 297}
288 298
289void OpenGLState::ApplyGlobalBlending() const { 299void OpenGLState::ApplyGlobalBlending() {
290 const Blend& updated = blend[0]; 300 const Blend& updated = blend[0];
291 Blend& current = cur_state.blend[0]; 301 Blend& current = cur_state.blend[0];
292 302
@@ -310,7 +320,7 @@ void OpenGLState::ApplyGlobalBlending() const {
310 } 320 }
311} 321}
312 322
313void OpenGLState::ApplyTargetBlending(std::size_t target, bool force) const { 323void OpenGLState::ApplyTargetBlending(std::size_t target, bool force) {
314 const Blend& updated = blend[target]; 324 const Blend& updated = blend[target];
315 Blend& current = cur_state.blend[target]; 325 Blend& current = cur_state.blend[target];
316 326
@@ -334,7 +344,12 @@ void OpenGLState::ApplyTargetBlending(std::size_t target, bool force) const {
334 } 344 }
335} 345}
336 346
337void OpenGLState::ApplyBlending() const { 347void OpenGLState::ApplyBlending() {
348 if (!dirty.blend_state) {
349 return;
350 }
351 dirty.blend_state = false;
352
338 if (independant_blend.enabled) { 353 if (independant_blend.enabled) {
339 const bool force = independant_blend.enabled != cur_state.independant_blend.enabled; 354 const bool force = independant_blend.enabled != cur_state.independant_blend.enabled;
340 for (std::size_t target = 0; target < Maxwell::NumRenderTargets; ++target) { 355 for (std::size_t target = 0; target < Maxwell::NumRenderTargets; ++target) {
@@ -353,7 +368,7 @@ void OpenGLState::ApplyBlending() const {
353 } 368 }
354} 369}
355 370
356void OpenGLState::ApplyLogicOp() const { 371void OpenGLState::ApplyLogicOp() {
357 Enable(GL_COLOR_LOGIC_OP, cur_state.logic_op.enabled, logic_op.enabled); 372 Enable(GL_COLOR_LOGIC_OP, cur_state.logic_op.enabled, logic_op.enabled);
358 373
359 if (UpdateValue(cur_state.logic_op.operation, logic_op.operation)) { 374 if (UpdateValue(cur_state.logic_op.operation, logic_op.operation)) {
@@ -361,7 +376,12 @@ void OpenGLState::ApplyLogicOp() const {
361 } 376 }
362} 377}
363 378
364void OpenGLState::ApplyPolygonOffset() const { 379void OpenGLState::ApplyPolygonOffset() {
380 if (!dirty.polygon_offset) {
381 return;
382 }
383 dirty.polygon_offset = false;
384
365 Enable(GL_POLYGON_OFFSET_FILL, cur_state.polygon_offset.fill_enable, 385 Enable(GL_POLYGON_OFFSET_FILL, cur_state.polygon_offset.fill_enable,
366 polygon_offset.fill_enable); 386 polygon_offset.fill_enable);
367 Enable(GL_POLYGON_OFFSET_LINE, cur_state.polygon_offset.line_enable, 387 Enable(GL_POLYGON_OFFSET_LINE, cur_state.polygon_offset.line_enable,
@@ -382,7 +402,7 @@ void OpenGLState::ApplyPolygonOffset() const {
382 } 402 }
383} 403}
384 404
385void OpenGLState::ApplyAlphaTest() const { 405void OpenGLState::ApplyAlphaTest() {
386 Enable(GL_ALPHA_TEST, cur_state.alpha_test.enabled, alpha_test.enabled); 406 Enable(GL_ALPHA_TEST, cur_state.alpha_test.enabled, alpha_test.enabled);
387 if (UpdateTie(std::tie(cur_state.alpha_test.func, cur_state.alpha_test.ref), 407 if (UpdateTie(std::tie(cur_state.alpha_test.func, cur_state.alpha_test.ref),
388 std::tie(alpha_test.func, alpha_test.ref))) { 408 std::tie(alpha_test.func, alpha_test.ref))) {
@@ -390,19 +410,19 @@ void OpenGLState::ApplyAlphaTest() const {
390 } 410 }
391} 411}
392 412
393void OpenGLState::ApplyTextures() const { 413void OpenGLState::ApplyTextures() {
394 if (const auto update = UpdateArray(cur_state.textures, textures)) { 414 if (const auto update = UpdateArray(cur_state.textures, textures)) {
395 glBindTextures(update->first, update->second, textures.data() + update->first); 415 glBindTextures(update->first, update->second, textures.data() + update->first);
396 } 416 }
397} 417}
398 418
399void OpenGLState::ApplySamplers() const { 419void OpenGLState::ApplySamplers() {
400 if (const auto update = UpdateArray(cur_state.samplers, samplers)) { 420 if (const auto update = UpdateArray(cur_state.samplers, samplers)) {
401 glBindSamplers(update->first, update->second, samplers.data() + update->first); 421 glBindSamplers(update->first, update->second, samplers.data() + update->first);
402 } 422 }
403} 423}
404 424
405void OpenGLState::ApplyImages() const { 425void OpenGLState::ApplyImages() {
406 if (const auto update = UpdateArray(cur_state.images, images)) { 426 if (const auto update = UpdateArray(cur_state.images, images)) {
407 glBindImageTextures(update->first, update->second, images.data() + update->first); 427 glBindImageTextures(update->first, update->second, images.data() + update->first);
408 } 428 }
@@ -418,32 +438,20 @@ void OpenGLState::Apply() {
418 ApplyPointSize(); 438 ApplyPointSize();
419 ApplyFragmentColorClamp(); 439 ApplyFragmentColorClamp();
420 ApplyMultisample(); 440 ApplyMultisample();
421 if (dirty.color_mask) { 441 ApplyColorMask();
422 ApplyColorMask();
423 dirty.color_mask = false;
424 }
425 ApplyDepthClamp(); 442 ApplyDepthClamp();
426 ApplyViewport(); 443 ApplyViewport();
427 if (dirty.stencil_state) { 444 ApplyStencilTest();
428 ApplyStencilTest();
429 dirty.stencil_state = false;
430 }
431 ApplySRgb(); 445 ApplySRgb();
432 ApplyCulling(); 446 ApplyCulling();
433 ApplyDepth(); 447 ApplyDepth();
434 ApplyPrimitiveRestart(); 448 ApplyPrimitiveRestart();
435 if (dirty.blend_state) { 449 ApplyBlending();
436 ApplyBlending();
437 dirty.blend_state = false;
438 }
439 ApplyLogicOp(); 450 ApplyLogicOp();
440 ApplyTextures(); 451 ApplyTextures();
441 ApplySamplers(); 452 ApplySamplers();
442 ApplyImages(); 453 ApplyImages();
443 if (dirty.polygon_offset) { 454 ApplyPolygonOffset();
444 ApplyPolygonOffset();
445 dirty.polygon_offset = false;
446 }
447 ApplyAlphaTest(); 455 ApplyAlphaTest();
448} 456}
449 457
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index b95f33613..cca25206b 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -157,31 +157,31 @@ public:
157 /// Apply this state as the current OpenGL state 157 /// Apply this state as the current OpenGL state
158 void Apply(); 158 void Apply();
159 159
160 void ApplyFramebufferState() const; 160 void ApplyFramebufferState();
161 void ApplyVertexArrayState() const; 161 void ApplyVertexArrayState();
162 void ApplyShaderProgram() const; 162 void ApplyShaderProgram();
163 void ApplyProgramPipeline() const; 163 void ApplyProgramPipeline();
164 void ApplyClipDistances() const; 164 void ApplyClipDistances();
165 void ApplyPointSize() const; 165 void ApplyPointSize();
166 void ApplyFragmentColorClamp() const; 166 void ApplyFragmentColorClamp();
167 void ApplyMultisample() const; 167 void ApplyMultisample();
168 void ApplySRgb() const; 168 void ApplySRgb();
169 void ApplyCulling() const; 169 void ApplyCulling();
170 void ApplyColorMask() const; 170 void ApplyColorMask();
171 void ApplyDepth() const; 171 void ApplyDepth();
172 void ApplyPrimitiveRestart() const; 172 void ApplyPrimitiveRestart();
173 void ApplyStencilTest() const; 173 void ApplyStencilTest();
174 void ApplyViewport() const; 174 void ApplyViewport();
175 void ApplyTargetBlending(std::size_t target, bool force) const; 175 void ApplyTargetBlending(std::size_t target, bool force);
176 void ApplyGlobalBlending() const; 176 void ApplyGlobalBlending();
177 void ApplyBlending() const; 177 void ApplyBlending();
178 void ApplyLogicOp() const; 178 void ApplyLogicOp();
179 void ApplyTextures() const; 179 void ApplyTextures();
180 void ApplySamplers() const; 180 void ApplySamplers();
181 void ApplyImages() const; 181 void ApplyImages();
182 void ApplyDepthClamp() const; 182 void ApplyDepthClamp();
183 void ApplyPolygonOffset() const; 183 void ApplyPolygonOffset();
184 void ApplyAlphaTest() const; 184 void ApplyAlphaTest();
185 185
186 /// Resets any references to the given resource 186 /// Resets any references to the given resource
187 OpenGLState& UnbindTexture(GLuint handle); 187 OpenGLState& UnbindTexture(GLuint handle);