From df3ade896b0b03462b67b3cd6c6390eb76a72db4 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Fri, 7 Aug 2015 12:13:50 +0200 Subject: [PATCH] gsdx-ogl: use integer for blend factor Integer argument&comparison might be lighter V2: Forget to change one OMSetBlendState call --- plugins/GSdx/GLState.cpp | 12 ++---------- plugins/GSdx/GLState.h | 2 +- plugins/GSdx/GSDeviceOGL.cpp | 5 +++-- plugins/GSdx/GSDeviceOGL.h | 2 +- plugins/GSdx/GSRendererOGL.cpp | 7 +++---- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/plugins/GSdx/GLState.cpp b/plugins/GSdx/GLState.cpp index 25028d1ce9..e00c25ca1c 100644 --- a/plugins/GSdx/GLState.cpp +++ b/plugins/GSdx/GLState.cpp @@ -33,7 +33,7 @@ namespace GLState { GLenum f_dRGB; uint32 wrgba; - float bf; + int bf; bool depth; GLenum depth_func; @@ -58,14 +58,6 @@ namespace GLState { GLuint vs; GLuint program; bool dirty_prog; -#if 0 - struct { - GSVertexBufferStateOGL* vb; - GSDepthStencilOGL* dss; - GSBlendStateOGL* bs; - float bf; // blend factor - } m_state; -#endif void Clear() { fbo = 0; @@ -77,7 +69,7 @@ namespace GLState { f_sRGB = 0; f_dRGB = 0; wrgba = 0xF; - bf = 0.0; + bf = 0; depth = false; depth_func = 0; diff --git a/plugins/GSdx/GLState.h b/plugins/GSdx/GLState.h index 43c7836a2e..2db08da410 100644 --- a/plugins/GSdx/GLState.h +++ b/plugins/GSdx/GLState.h @@ -34,7 +34,7 @@ namespace GLState { extern GLenum f_sRGB; extern GLenum f_dRGB; extern uint32 wrgba; - extern float bf; + extern int bf; extern bool depth; extern GLenum depth_func; diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index d5dd22967e..e60b628e4c 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -1332,7 +1332,7 @@ void GSDeviceOGL::OMSetColorMaskState(OMColorMaskSelector sel) } } -void GSDeviceOGL::OMSetBlendState(int blend_index, float blend_factor, bool is_blend_constant) +void GSDeviceOGL::OMSetBlendState(int blend_index, int blend_factor, bool is_blend_constant) { if (blend_index) { if (!GLState::blend) { @@ -1342,7 +1342,8 @@ void GSDeviceOGL::OMSetBlendState(int blend_index, float blend_factor, bool is_b if (is_blend_constant && GLState::bf != blend_factor) { GLState::bf = blend_factor; - gl_BlendColor(blend_factor, blend_factor, blend_factor, 0); + float bf = (float)blend_factor / 128.0f; + gl_BlendColor(bf, bf, bf, bf); } // FIXME test to use uint16 (cache friendly) diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 5edab6f4e1..e17c9bb951 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -527,7 +527,7 @@ class GSDeviceOGL : public GSDevice void PSSetSamplerState(GLuint ss); void OMSetDepthStencilState(GSDepthStencilOGL* dss); - void OMSetBlendState(int blend_index = 0, float blend_factor = 0.0f, bool is_blend_constant = false); + void OMSetBlendState(int blend_index = 0, int blend_factor = 0, bool is_blend_constant = false); void OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4i* scissor = NULL); void OMSetWriteBuffer(GLenum buffer = GL_COLOR_ATTACHMENT0); void OMSetColorMaskState(OMColorMaskSelector sel = OMColorMaskSelector()); diff --git a/plugins/GSdx/GSRendererOGL.cpp b/plugins/GSdx/GSRendererOGL.cpp index 0bd8abedb7..4e5236bd05 100644 --- a/plugins/GSdx/GSRendererOGL.cpp +++ b/plugins/GSdx/GSRendererOGL.cpp @@ -307,7 +307,6 @@ bool GSRendererOGL::EmulateBlending(GSDeviceOGL::PSSelector& ps_sel, bool DATE_G const GIFRegALPHA& ALPHA = m_context->ALPHA; bool require_barrier = false; bool sw_blending = false; - float afix = (float)m_context->ALPHA.FIX / 0x80; // No blending so early exit if (!(PRIM->ABE || PRIM->AA1 && m_vt.m_primclass == GS_LINE_CLASS)) { @@ -400,7 +399,7 @@ bool GSRendererOGL::EmulateBlending(GSDeviceOGL::PSSelector& ps_sel, bool DATE_G // Require the fix alpha vlaue if (ALPHA.C == 2) { - ps_cb.AlphaCoeff.a = afix; + ps_cb.AlphaCoeff.a = (float)ALPHA.FIX / 128.0f; } // No need to flush for every primitive @@ -410,9 +409,9 @@ bool GSRendererOGL::EmulateBlending(GSDeviceOGL::PSSelector& ps_sel, bool DATE_G if (ps_sel.dfmt == 1 && ALPHA.C == 1) { // 24 bits doesn't have an alpha channel so use 1.0f fix factor as equivalent int hacked_blend_index = blend_index + 3; // +3 <=> +1 on C - dev->OMSetBlendState(hacked_blend_index, 1.0f, true); + dev->OMSetBlendState(hacked_blend_index, 128, true); } else { - dev->OMSetBlendState(blend_index, afix, (ALPHA.C == 2)); + dev->OMSetBlendState(blend_index, ALPHA.FIX, (ALPHA.C == 2)); } }