VERY experimental Nintendo Switch 2 emulator
C++
OpenGL: Support blend equation
Jannik Vogel55e804b61073
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cppindex ed2e2f3ae2..4222945a49 100644--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp@@ -937,6 +937,8 @@ void RasterizerOpenGL::SyncBlendEnabled() {void RasterizerOpenGL::SyncBlendFuncs() {const auto& regs = Pica::g_state.regs;+ state.blend.rgb_equation = PicaToGL::BlendEquation(regs.output_merger.alpha_blending.blend_equation_rgb);+ state.blend.a_equation = PicaToGL::BlendEquation(regs.output_merger.alpha_blending.blend_equation_a);state.blend.src_rgb_func = PicaToGL::BlendFunc(regs.output_merger.alpha_blending.factor_source_rgb);state.blend.dst_rgb_func = PicaToGL::BlendFunc(regs.output_merger.alpha_blending.factor_dest_rgb);state.blend.src_a_func = PicaToGL::BlendFunc(regs.output_merger.alpha_blending.factor_source_a);diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cppindex 02cd9f4179..fa141fc9ad 100644--- a/src/video_core/renderer_opengl/gl_state.cpp+++ b/src/video_core/renderer_opengl/gl_state.cpp@@ -36,6 +36,8 @@ OpenGLState::OpenGLState() {stencil.action_stencil_fail = GL_KEEP;blend.enabled = false;+ blend.rgb_equation = GL_FUNC_ADD;+ blend.a_equation = GL_FUNC_ADD;blend.src_rgb_func = GL_ONE;blend.dst_rgb_func = GL_ZERO;blend.src_a_func = GL_ONE;@@ -165,6 +167,11 @@ void OpenGLState::Apply() const {blend.src_a_func, blend.dst_a_func);}+ if (blend.rgb_equation != cur_state.blend.rgb_equation ||+ blend.a_equation != cur_state.blend.a_equation) {+ glBlendEquationSeparate(blend.rgb_equation, blend.a_equation);+ }+if (logic_op != cur_state.logic_op) {glLogicOp(logic_op);}diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.hindex 24f20e47cb..2287270549 100644--- a/src/video_core/renderer_opengl/gl_state.h+++ b/src/video_core/renderer_opengl/gl_state.h@@ -40,6 +40,8 @@ public:struct {bool enabled; // GL_BLEND+ GLenum rgb_equation; // GL_BLEND_EQUATION_RGB+ GLenum a_equation; // GL_BLEND_EQUATION_ALPHAGLenum src_rgb_func; // GL_BLEND_SRC_RGBGLenum dst_rgb_func; // GL_BLEND_DST_RGBGLenum src_a_func; // GL_BLEND_SRC_ALPHAdiff --git a/src/video_core/renderer_opengl/pica_to_gl.h b/src/video_core/renderer_opengl/pica_to_gl.hindex 976d1f364a..6dc2758c5a 100644--- a/src/video_core/renderer_opengl/pica_to_gl.h+++ b/src/video_core/renderer_opengl/pica_to_gl.h@@ -78,6 +78,26 @@ inline GLenum WrapMode(Pica::Regs::TextureConfig::WrapMode mode) {return gl_mode;}+inline GLenum BlendEquation(Pica::Regs::BlendEquation equation) {+ static const GLenum blend_equation_table[] = {+ GL_FUNC_ADD, // BlendEquation::Add+ GL_FUNC_SUBTRACT, // BlendEquation::Subtract+ GL_FUNC_REVERSE_SUBTRACT, // BlendEquation::ReverseSubtract+ GL_MIN, // BlendEquation::Min+ GL_MAX, // BlendEquation::Max+ };++ // Range check table for input+ if (static_cast<size_t>(equation) >= ARRAY_SIZE(blend_equation_table)) {+ LOG_CRITICAL(Render_OpenGL, "Unknown blend equation %d", equation);+ UNREACHABLE();++ return GL_FUNC_ADD;+ }++ return blend_equation_table[(unsigned)equation];+}+inline GLenum BlendFunc(Pica::Regs::BlendFactor factor) {static const GLenum blend_func_table[] = {GL_ZERO, // BlendFactor::Zero