From eebdd32932f2db561b57ad4df46482f8b30d47d6 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Tue, 28 Feb 2017 15:25:25 +0700 Subject: [PATCH] Replace rectAttrib::color by uniform. --- src/Graphics/Context.h | 1 - .../GLSL/glsl_CombinerProgramBuilder.cpp | 8 ++--- .../glsl_CombinerProgramUniformFactory.cpp | 26 +++++++++++++--- .../OpenGLContext/GLSL/glsl_Utils.cpp | 1 - .../OpenGLContext/opengl_Attributes.cpp | 17 +++++----- .../OpenGLContext/opengl_Attributes.h | 1 - .../OpenGLContext/opengl_BufferedDrawer.cpp | 3 -- .../OpenGLContext/opengl_UnbufferedDrawer.cpp | 3 -- src/GraphicsDrawer.cpp | 31 +++++++++---------- src/TexrectDrawer.cpp | 2 -- src/TextDrawer.cpp | 1 - src/gDP.h | 3 +- 12 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/Graphics/Context.h b/src/Graphics/Context.h index cfa0469b..46d5d124 100644 --- a/src/Graphics/Context.h +++ b/src/Graphics/Context.h @@ -244,7 +244,6 @@ namespace graphics { { DrawModeParam mode; u32 verticesCount = 0; - std::array rectColor; RectVertex * vertices = nullptr; const CombinerProgram * combiner = nullptr; }; diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index 917cf2f9..1b1e587f 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -355,17 +355,17 @@ public: { m_part = "IN highp vec4 aRectPosition; \n" - "IN lowp vec4 aRectColor; \n" "IN highp vec2 aTexCoord0; \n" "IN highp vec2 aTexCoord1; \n" " \n" "OUT lowp vec4 vShadeColor; \n" "OUT mediump vec2 vTexCoord0; \n" "OUT mediump vec2 vTexCoord1; \n" + "uniform lowp vec4 uRectColor; \n" "void main() \n" "{ \n" " gl_Position = aRectPosition; \n" - " vShadeColor = aRectColor; \n" + " vShadeColor = uRectColor; \n" " vTexCoord0 = aTexCoord0; \n" " vTexCoord1 = aTexCoord1; \n" ; @@ -387,13 +387,13 @@ public: { m_part = "IN highp vec4 aRectPosition; \n" - "IN lowp vec4 aRectColor; \n" " \n" "OUT lowp vec4 vShadeColor; \n" + "uniform lowp vec4 uRectColor; \n" "void main() \n" "{ \n" " gl_Position = aRectPosition; \n" - " vShadeColor = aRectColor; \n" + " vShadeColor = uRectColor; \n" ; if (!_glinfo.isGLESX) { m_part += diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp index aa83201f..8d348bed 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp @@ -638,6 +638,22 @@ private: fUniform uK5; }; +class URectColor : public UniformGroup +{ +public: + URectColor(GLuint _program) { + LocateUniform(uRectColor); + } + + void update(bool _force) override + { + uRectColor.set(&gDP.rectColor.r, _force); + } + +private: + fv4Uniform uRectColor; +}; + class UTextureSize : public UniformGroup { public: @@ -772,8 +788,10 @@ void CombinerProgramUniformFactory::buildUniforms(GLuint _program, if (config.generalEmulation.enableNoise != 0) _uniforms.emplace_back(new UNoiseTex(_program)); - if (!m_glInfo.isGLES2) + if (!m_glInfo.isGLES2) { _uniforms.emplace_back(new UDepthTex(_program)); + _uniforms.emplace_back(new UDepthScale(_program)); + } if (_inputs.usesTexture()) { _uniforms.emplace_back(new UTextures(_program)); @@ -820,9 +838,6 @@ void CombinerProgramUniformFactory::buildUniforms(GLuint _program, _uniforms.emplace_back(new UAlphaTestInfo(_program)); - if (!m_glInfo.isGLES2) - _uniforms.emplace_back(new UDepthScale(_program)); - if (config.frameBufferEmulation.N64DepthCompare != 0) _uniforms.emplace_back(new UDepthInfo(_program)); @@ -834,6 +849,9 @@ void CombinerProgramUniformFactory::buildUniforms(GLuint _program, _uniforms.emplace_back(new UColors(_program)); + if (_key.isRectKey()) + _uniforms.emplace_back(new URectColor(_program)); + if (_inputs.usesHwLighting()) _uniforms.emplace_back(new ULights(_program)); } diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_Utils.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_Utils.cpp index 11e571e4..6b98a766 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_Utils.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_Utils.cpp @@ -9,7 +9,6 @@ void Utils::locateAttributes(GLuint _program, bool _rect, bool _textures) { if (_rect) { glBindAttribLocation(_program, opengl::rectAttrib::position, "aRectPosition"); - glBindAttribLocation(_program, opengl::rectAttrib::color, "aRectColor"); if (_textures) { glBindAttribLocation(_program, opengl::rectAttrib::texcoord0, "aTexCoord0"); glBindAttribLocation(_program, opengl::rectAttrib::texcoord1, "aTexCoord1"); diff --git a/src/Graphics/OpenGLContext/opengl_Attributes.cpp b/src/Graphics/OpenGLContext/opengl_Attributes.cpp index 74a5f76a..6f05bb53 100644 --- a/src/Graphics/OpenGLContext/opengl_Attributes.cpp +++ b/src/Graphics/OpenGLContext/opengl_Attributes.cpp @@ -3,18 +3,17 @@ namespace opengl { namespace triangleAttrib { - const GLuint position = 1U; - const GLuint color = 2U; - const GLuint texcoord = 3U; - const GLuint numlights = 4U; - const GLuint modify = 5U; + const GLuint position = 0U; + const GLuint color = 1U; + const GLuint texcoord = 2U; + const GLuint numlights = 3U; + const GLuint modify = 4U; } // Rect attributes namespace rectAttrib { - const GLuint position = 6U; - const GLuint color = 7U; - const GLuint texcoord0 = 8U; - const GLuint texcoord1 = 9U; + const GLuint position = 5U; + const GLuint texcoord0 = 6U; + const GLuint texcoord1 = 7U; } } diff --git a/src/Graphics/OpenGLContext/opengl_Attributes.h b/src/Graphics/OpenGLContext/opengl_Attributes.h index 84652296..a3073556 100644 --- a/src/Graphics/OpenGLContext/opengl_Attributes.h +++ b/src/Graphics/OpenGLContext/opengl_Attributes.h @@ -15,7 +15,6 @@ namespace opengl { // Rect attributes namespace rectAttrib { extern const GLuint position; - extern const GLuint color; extern const GLuint texcoord0; extern const GLuint texcoord1; } diff --git a/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp b/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp index d89be383..f1eb8320 100644 --- a/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp +++ b/src/Graphics/OpenGLContext/opengl_BufferedDrawer.cpp @@ -28,7 +28,6 @@ BufferedDrawer::BufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArray * m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, true); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord0, true); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, true); - m_cachedAttribArray->enableVertexAttribArray(rectAttrib::color, false); glVertexAttribPointer(rectAttrib::position, 4, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, x))); glVertexAttribPointer(rectAttrib::texcoord0, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, s0))); glVertexAttribPointer(rectAttrib::texcoord1, 2, GL_FLOAT, GL_FALSE, sizeof(RectVertex), (const GLvoid *)(offsetof(RectVertex, s1))); @@ -134,8 +133,6 @@ void BufferedDrawer::drawRects(const graphics::Context::DrawRectParameters & _pa { _updateRectBuffer(_params); - glVertexAttrib4fv(rectAttrib::color, _params.rectColor.data()); - glDrawArrays(GLenum(_params.mode), m_rectsBuffers.vbo.pos - _params.verticesCount, _params.verticesCount); } diff --git a/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp b/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp index b22ce65e..2bdf5dec 100644 --- a/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp +++ b/src/Graphics/OpenGLContext/opengl_UnbufferedDrawer.cpp @@ -17,7 +17,6 @@ UnbufferedDrawer::UnbufferedDrawer(const GLInfo & _glinfo, CachedVertexAttribArr m_cachedAttribArray->enableVertexAttribArray(triangleAttrib::modify, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::position, false); - m_cachedAttribArray->enableVertexAttribArray(rectAttrib::color, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord0, false); m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord1, false); @@ -97,8 +96,6 @@ void UnbufferedDrawer::drawRects(const graphics::Context::DrawRectParameters & _ glVertexAttribPointer(rectAttrib::position, 4, GL_FLOAT, GL_FALSE, sizeof(RectVertex), ptr); } - glVertexAttrib4fv(rectAttrib::color, _params.rectColor.data()); - if (_params.combiner->usesTile(0)) { m_cachedAttribArray->enableVertexAttribArray(rectAttrib::texcoord0, true); const void * ptr = &_params.vertices->s0; diff --git a/src/GraphicsDrawer.cpp b/src/GraphicsDrawer.cpp index 3830f79f..9744a298 100644 --- a/src/GraphicsDrawer.cpp +++ b/src/GraphicsDrawer.cpp @@ -835,6 +835,14 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry, float *_pC if (!_canDraw()) return; + if (gDP.otherMode.cycleType == G_CYC_FILL) { + gDP.rectColor.r = _pColor[0]; + gDP.rectColor.g = _pColor[1]; + gDP.rectColor.b = _pColor[2]; + gDP.rectColor.a = _pColor[3]; + } else { + gDP.rectColor = gDPInfo::Color(); + } gSP.changed &= ~CHANGED_GEOMETRYMODE; // Don't update cull mode if (gSP.changed || gDP.changed) _updateStates(DrawingState::Rect); @@ -879,10 +887,6 @@ void GraphicsDrawer::drawRect(int _ulx, int _uly, int _lrx, int _lry, float *_pC Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLE_STRIP; - if (gDP.otherMode.cycleType == G_CYC_FILL) - std::copy_n(_pColor, 4, rectParams.rectColor.begin()); - else - rectParams.rectColor.fill(0.0f); rectParams.verticesCount = 4; rectParams.vertices = m_rect; rectParams.combiner = currentCombiner(); @@ -1052,7 +1056,6 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params) { gSP.changed &= ~CHANGED_GEOMETRYMODE; // Don't update cull mode m_drawingState = DrawingState::TexRect; - f32 alpha = 0.0f; if (!m_texrectDrawer.isEmpty()) { CombinerInfo & cmbInfo = CombinerInfo::get(); @@ -1061,19 +1064,16 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params) _updateTextures(); cmbInfo.updateParameters(); } else { + gDP.rectColor = gDPInfo::Color(); + if (gDP.otherMode.cycleType < G_CYC_COPY) { + if (gDP.combine.mA0 == G_ACMUX_0 && gDP.combine.aA0 == G_ACMUX_SHADE) + gDP.rectColor.a = 1.0f; + } + if (_params.texrectCmd && (gSP.changed | gDP.changed) != 0) _updateStates(DrawingState::TexRect); gfxContext.enable(enable::CULL_FACE, false); - if (CombinerInfo::get().isChanged()) { - if (currentCombiner()->usesShade()) { - gDPCombine combine; - combine.mux = currentCombiner()->getKey().getMux(); - if (combine.mA0 == G_ACMUX_0 && combine.aA0 == G_ACMUX_SHADE) - alpha = 1.0f; - } - } - if (_params.texrectCmd && texturedRectSpecial != nullptr && texturedRectSpecial(_params)) { gSP.changed |= CHANGED_GEOMETRYMODE; return; @@ -1253,8 +1253,6 @@ void GraphicsDrawer::drawTexturedRect(const TexturedRectParams & _params) Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLE_STRIP; - rectParams.rectColor.fill(0.0f); - rectParams.rectColor[3] = alpha; rectParams.verticesCount = 4; rectParams.vertices = m_rect; rectParams.combiner = currentCombiner(); @@ -1466,7 +1464,6 @@ void GraphicsDrawer::copyTexturedRect(const CopyRectParams & _params) Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLE_STRIP; - rectParams.rectColor.fill(0.0f); rectParams.verticesCount = 4; rectParams.vertices = m_rect; rectParams.combiner = _params.combiner; diff --git a/src/TexrectDrawer.cpp b/src/TexrectDrawer.cpp index 982d11d6..2eff64bb 100644 --- a/src/TexrectDrawer.cpp +++ b/src/TexrectDrawer.cpp @@ -173,7 +173,6 @@ void TexrectDrawer::add() Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLE_STRIP; - rectParams.rectColor.fill(0.0f); rectParams.verticesCount = 4; rectParams.vertices = pRect; rectParams.combiner = currentCombiner(); @@ -286,7 +285,6 @@ bool TexrectDrawer::draw() Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLE_STRIP; - rectParams.rectColor.fill(0.0f); rectParams.verticesCount = 4; rectParams.vertices = rect; rectParams.combiner = m_programTex.get(); diff --git a/src/TextDrawer.cpp b/src/TextDrawer.cpp index 33309005..1d26893c 100644 --- a/src/TextDrawer.cpp +++ b/src/TextDrawer.cpp @@ -344,7 +344,6 @@ void TextDrawer::drawText(const char *_pText, float _x, float _y) const Context::DrawRectParameters rectParams; rectParams.mode = drawmode::TRIANGLES; - rectParams.rectColor.fill(0.0f); rectParams.verticesCount = coords.size(); rectParams.vertices = coords.data(); rectParams.combiner = m_program.get(); diff --git a/src/gDP.h b/src/gDP.h index edfc2552..a07e80b9 100644 --- a/src/gDP.h +++ b/src/gDP.h @@ -191,8 +191,9 @@ struct gDPInfo struct Color { + Color() : r(0), g(0), b(0), a(0) {} f32 r, g, b, a; - } fogColor, blendColor, envColor; + } fogColor, blendColor, envColor, rectColor; struct {