summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-03-19 17:05:15 -0400
committerGravatar bunnei2018-03-19 23:13:49 -0400
commit6a0902e56dfdada3f105da9c49442cef2c857cae (patch)
tree0c04e969bde3c9adb6c157dc55116b9f05b5f7c4 /src
parentMerge pull request #252 from N00byKing/3064 (diff)
downloadyuzu-6a0902e56dfdada3f105da9c49442cef2c857cae.tar.gz
yuzu-6a0902e56dfdada3f105da9c49442cef2c857cae.tar.xz
yuzu-6a0902e56dfdada3f105da9c49442cef2c857cae.zip
gl_state: Sync latest version with Citra.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp125
-rw-r--r--src/video_core/renderer_opengl/gl_state.h33
2 files changed, 111 insertions, 47 deletions
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index 5770ae08f..1d396728b 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -33,7 +33,7 @@ OpenGLState::OpenGLState() {
33 stencil.action_depth_pass = GL_KEEP; 33 stencil.action_depth_pass = GL_KEEP;
34 stencil.action_stencil_fail = GL_KEEP; 34 stencil.action_stencil_fail = GL_KEEP;
35 35
36 blend.enabled = false; 36 blend.enabled = true;
37 blend.rgb_equation = GL_FUNC_ADD; 37 blend.rgb_equation = GL_FUNC_ADD;
38 blend.a_equation = GL_FUNC_ADD; 38 blend.a_equation = GL_FUNC_ADD;
39 blend.src_rgb_func = GL_ONE; 39 blend.src_rgb_func = GL_ONE;
@@ -68,6 +68,18 @@ OpenGLState::OpenGLState() {
68 draw.vertex_buffer = 0; 68 draw.vertex_buffer = 0;
69 draw.uniform_buffer = 0; 69 draw.uniform_buffer = 0;
70 draw.shader_program = 0; 70 draw.shader_program = 0;
71 draw.program_pipeline = 0;
72
73 scissor.enabled = false;
74 scissor.x = 0;
75 scissor.y = 0;
76 scissor.width = 0;
77 scissor.height = 0;
78
79 viewport.x = 0;
80 viewport.y = 0;
81 viewport.width = 0;
82 viewport.height = 0;
71 83
72 clip_distance = {}; 84 clip_distance = {};
73} 85}
@@ -148,9 +160,6 @@ void OpenGLState::Apply() const {
148 if (blend.enabled != cur_state.blend.enabled) { 160 if (blend.enabled != cur_state.blend.enabled) {
149 if (blend.enabled) { 161 if (blend.enabled) {
150 glEnable(GL_BLEND); 162 glEnable(GL_BLEND);
151
152 cur_state.logic_op = GL_COPY;
153 glLogicOp(cur_state.logic_op);
154 glDisable(GL_COLOR_LOGIC_OP); 163 glDisable(GL_COLOR_LOGIC_OP);
155 } else { 164 } else {
156 glDisable(GL_BLEND); 165 glDisable(GL_BLEND);
@@ -196,7 +205,7 @@ void OpenGLState::Apply() const {
196 // Lighting LUTs 205 // Lighting LUTs
197 if (lighting_lut.texture_buffer != cur_state.lighting_lut.texture_buffer) { 206 if (lighting_lut.texture_buffer != cur_state.lighting_lut.texture_buffer) {
198 glActiveTexture(TextureUnits::LightingLUT.Enum()); 207 glActiveTexture(TextureUnits::LightingLUT.Enum());
199 glBindTexture(GL_TEXTURE_BUFFER, cur_state.lighting_lut.texture_buffer); 208 glBindTexture(GL_TEXTURE_BUFFER, lighting_lut.texture_buffer);
200 } 209 }
201 210
202 // Fog LUT 211 // Fog LUT
@@ -263,6 +272,31 @@ void OpenGLState::Apply() const {
263 glUseProgram(draw.shader_program); 272 glUseProgram(draw.shader_program);
264 } 273 }
265 274
275 // Program pipeline
276 if (draw.program_pipeline != cur_state.draw.program_pipeline) {
277 glBindProgramPipeline(draw.program_pipeline);
278 }
279
280 // Scissor test
281 if (scissor.enabled != cur_state.scissor.enabled) {
282 if (scissor.enabled) {
283 glEnable(GL_SCISSOR_TEST);
284 } else {
285 glDisable(GL_SCISSOR_TEST);
286 }
287 }
288
289 if (scissor.x != cur_state.scissor.x || scissor.y != cur_state.scissor.y ||
290 scissor.width != cur_state.scissor.width || scissor.height != cur_state.scissor.height) {
291 glScissor(scissor.x, scissor.y, scissor.width, scissor.height);
292 }
293
294 if (viewport.x != cur_state.viewport.x || viewport.y != cur_state.viewport.y ||
295 viewport.width != cur_state.viewport.width ||
296 viewport.height != cur_state.viewport.height) {
297 glViewport(viewport.x, viewport.y, viewport.width, viewport.height);
298 }
299
266 // Clip distance 300 // Clip distance
267 for (size_t i = 0; i < clip_distance.size(); ++i) { 301 for (size_t i = 0; i < clip_distance.size(); ++i) {
268 if (clip_distance[i] != cur_state.clip_distance[i]) { 302 if (clip_distance[i] != cur_state.clip_distance[i]) {
@@ -277,62 +311,75 @@ void OpenGLState::Apply() const {
277 cur_state = *this; 311 cur_state = *this;
278} 312}
279 313
280void OpenGLState::ResetTexture(GLuint handle) { 314OpenGLState& OpenGLState::ResetTexture(GLuint handle) {
281 for (auto& unit : cur_state.texture_units) { 315 for (auto& unit : texture_units) {
282 if (unit.texture_2d == handle) { 316 if (unit.texture_2d == handle) {
283 unit.texture_2d = 0; 317 unit.texture_2d = 0;
284 } 318 }
285 } 319 }
286 if (cur_state.lighting_lut.texture_buffer == handle) 320 if (lighting_lut.texture_buffer == handle)
287 cur_state.lighting_lut.texture_buffer = 0; 321 lighting_lut.texture_buffer = 0;
288 if (cur_state.fog_lut.texture_buffer == handle) 322 if (fog_lut.texture_buffer == handle)
289 cur_state.fog_lut.texture_buffer = 0; 323 fog_lut.texture_buffer = 0;
290 if (cur_state.proctex_noise_lut.texture_buffer == handle) 324 if (proctex_noise_lut.texture_buffer == handle)
291 cur_state.proctex_noise_lut.texture_buffer = 0; 325 proctex_noise_lut.texture_buffer = 0;
292 if (cur_state.proctex_color_map.texture_buffer == handle) 326 if (proctex_color_map.texture_buffer == handle)
293 cur_state.proctex_color_map.texture_buffer = 0; 327 proctex_color_map.texture_buffer = 0;
294 if (cur_state.proctex_alpha_map.texture_buffer == handle) 328 if (proctex_alpha_map.texture_buffer == handle)
295 cur_state.proctex_alpha_map.texture_buffer = 0; 329 proctex_alpha_map.texture_buffer = 0;
296 if (cur_state.proctex_lut.texture_buffer == handle) 330 if (proctex_lut.texture_buffer == handle)
297 cur_state.proctex_lut.texture_buffer = 0; 331 proctex_lut.texture_buffer = 0;
298 if (cur_state.proctex_diff_lut.texture_buffer == handle) 332 if (proctex_diff_lut.texture_buffer == handle)
299 cur_state.proctex_diff_lut.texture_buffer = 0; 333 proctex_diff_lut.texture_buffer = 0;
334 return *this;
300} 335}
301 336
302void OpenGLState::ResetSampler(GLuint handle) { 337OpenGLState& OpenGLState::ResetSampler(GLuint handle) {
303 for (auto& unit : cur_state.texture_units) { 338 for (auto& unit : texture_units) {
304 if (unit.sampler == handle) { 339 if (unit.sampler == handle) {
305 unit.sampler = 0; 340 unit.sampler = 0;
306 } 341 }
307 } 342 }
343 return *this;
344}
345
346OpenGLState& OpenGLState::ResetProgram(GLuint handle) {
347 if (draw.shader_program == handle) {
348 draw.shader_program = 0;
349 }
350 return *this;
308} 351}
309 352
310void OpenGLState::ResetProgram(GLuint handle) { 353OpenGLState& OpenGLState::ResetPipeline(GLuint handle) {
311 if (cur_state.draw.shader_program == handle) { 354 if (draw.program_pipeline == handle) {
312 cur_state.draw.shader_program = 0; 355 draw.program_pipeline = 0;
313 } 356 }
357 return *this;
314} 358}
315 359
316void OpenGLState::ResetBuffer(GLuint handle) { 360OpenGLState& OpenGLState::ResetBuffer(GLuint handle) {
317 if (cur_state.draw.vertex_buffer == handle) { 361 if (draw.vertex_buffer == handle) {
318 cur_state.draw.vertex_buffer = 0; 362 draw.vertex_buffer = 0;
319 } 363 }
320 if (cur_state.draw.uniform_buffer == handle) { 364 if (draw.uniform_buffer == handle) {
321 cur_state.draw.uniform_buffer = 0; 365 draw.uniform_buffer = 0;
322 } 366 }
367 return *this;
323} 368}
324 369
325void OpenGLState::ResetVertexArray(GLuint handle) { 370OpenGLState& OpenGLState::ResetVertexArray(GLuint handle) {
326 if (cur_state.draw.vertex_array == handle) { 371 if (draw.vertex_array == handle) {
327 cur_state.draw.vertex_array = 0; 372 draw.vertex_array = 0;
328 } 373 }
374 return *this;
329} 375}
330 376
331void OpenGLState::ResetFramebuffer(GLuint handle) { 377OpenGLState& OpenGLState::ResetFramebuffer(GLuint handle) {
332 if (cur_state.draw.read_framebuffer == handle) { 378 if (draw.read_framebuffer == handle) {
333 cur_state.draw.read_framebuffer = 0; 379 draw.read_framebuffer = 0;
334 } 380 }
335 if (cur_state.draw.draw_framebuffer == handle) { 381 if (draw.draw_framebuffer == handle) {
336 cur_state.draw.draw_framebuffer = 0; 382 draw.draw_framebuffer = 0;
337 } 383 }
384 return *this;
338} 385}
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index 437fe34c4..940575dfa 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -122,27 +122,44 @@ public:
122 GLuint vertex_buffer; // GL_ARRAY_BUFFER_BINDING 122 GLuint vertex_buffer; // GL_ARRAY_BUFFER_BINDING
123 GLuint uniform_buffer; // GL_UNIFORM_BUFFER_BINDING 123 GLuint uniform_buffer; // GL_UNIFORM_BUFFER_BINDING
124 GLuint shader_program; // GL_CURRENT_PROGRAM 124 GLuint shader_program; // GL_CURRENT_PROGRAM
125 GLuint program_pipeline; // GL_PROGRAM_PIPELINE_BINDING
125 } draw; 126 } draw;
126 127
128 struct {
129 bool enabled; // GL_SCISSOR_TEST
130 GLint x;
131 GLint y;
132 GLsizei width;
133 GLsizei height;
134 } scissor;
135
136 struct {
137 GLint x;
138 GLint y;
139 GLsizei width;
140 GLsizei height;
141 } viewport;
142
127 std::array<bool, 2> clip_distance; // GL_CLIP_DISTANCE 143 std::array<bool, 2> clip_distance; // GL_CLIP_DISTANCE
128 144
129 OpenGLState(); 145 OpenGLState();
130 146
131 /// Get the currently active OpenGL state 147 /// Get the currently active OpenGL state
132 static const OpenGLState& GetCurState() { 148 static OpenGLState GetCurState() {
133 return cur_state; 149 return cur_state;
134 } 150 }
135 151
136 /// Apply this state as the current OpenGL state 152 /// Apply this state as the current OpenGL state
137 void Apply() const; 153 void Apply() const;
138 154
139 /// Resets and unbinds any references to the given resource in the current OpenGL state 155 /// Resets any references to the given resource
140 static void ResetTexture(GLuint handle); 156 OpenGLState& ResetTexture(GLuint handle);
141 static void ResetSampler(GLuint handle); 157 OpenGLState& ResetSampler(GLuint handle);
142 static void ResetProgram(GLuint handle); 158 OpenGLState& ResetProgram(GLuint handle);
143 static void ResetBuffer(GLuint handle); 159 OpenGLState& ResetPipeline(GLuint handle);
144 static void ResetVertexArray(GLuint handle); 160 OpenGLState& ResetBuffer(GLuint handle);
145 static void ResetFramebuffer(GLuint handle); 161 OpenGLState& ResetVertexArray(GLuint handle);
162 OpenGLState& ResetFramebuffer(GLuint handle);
146 163
147private: 164private:
148 static OpenGLState cur_state; 165 static OpenGLState cur_state;