From bee5a4b3a6cbce4c23beac288288e1e1437c6c64 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Sun, 30 May 2021 00:30:55 +0000 Subject: [PATCH] Uses Canvas2D for str_gui_solid_mask material in GUIRenderer. This was SVN commit r25597. --- source/graphics/Canvas2D.cpp | 21 ++++++++++++--------- source/gui/GUIRenderer.cpp | 11 ++++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/source/graphics/Canvas2D.cpp b/source/graphics/Canvas2D.cpp index dc66ab052f..4d87431135 100644 --- a/source/graphics/Canvas2D.cpp +++ b/source/graphics/Canvas2D.cpp @@ -36,8 +36,8 @@ namespace // Array of 2D elements unrolled into 1D array. using PlaneArray2D = std::array; -void DrawTextureImpl(CTexturePtr texture, - const PlaneArray2D& vertices, const PlaneArray2D& uvs, +inline void DrawTextureImpl(CTexturePtr texture, + const PlaneArray2D& vertices, PlaneArray2D uvs, const CColor& multiply, const CColor& add) { CShaderDefines defines; @@ -47,6 +47,14 @@ void DrawTextureImpl(CTexturePtr texture, CShaderProgramPtr shader = tech->GetShader(); shader->BindTexture(str_tex, texture); + for (size_t idx = 0; idx < uvs.size(); idx += 2) + { + if (texture->GetWidth() > 0.0f) + uvs[idx + 0] /= texture->GetWidth(); + if (texture->GetHeight() > 0.0f) + uvs[idx + 1] /= texture->GetHeight(); + } + shader->Uniform(str_transform, GetDefaultGuiMatrix()); shader->Uniform(str_colorAdd, add); shader->Uniform(str_colorMul, multiply); @@ -127,17 +135,12 @@ void CCanvas2D::DrawTexture( CTexturePtr texture, const CRect& destination, const CRect& source, const CColor& multiply, const CColor& add) { - PlaneArray2D uvs = { + const PlaneArray2D uvs = { source.left, source.bottom, source.right, source.bottom, source.right, source.top, source.left, source.top }; - for (size_t idx = 0; idx < uvs.size() / 2; idx += 2) - { - uvs[idx + 0] /= texture->GetWidth(); - uvs[idx + 1] /= texture->GetHeight(); - } const PlaneArray2D vertices = { destination.left, destination.bottom, destination.right, destination.bottom, @@ -146,4 +149,4 @@ void CCanvas2D::DrawTexture( }; DrawTextureImpl(texture, vertices, uvs, multiply, add); -} \ No newline at end of file +} diff --git a/source/gui/GUIRenderer.cpp b/source/gui/GUIRenderer.cpp index 49aa14639d..c98b3352a0 100644 --- a/source/gui/GUIRenderer.cpp +++ b/source/gui/GUIRenderer.cpp @@ -243,9 +243,10 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const } else if ((*cit)->m_Effects->m_SolidColor != CGUIColor()) { - Call.m_Shader = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid_mask); Call.m_Material = str_gui_solid_mask; - Call.m_ShaderColorParameter = (*cit)->m_Effects->m_SolidColor; + const CColor color = (*cit)->m_Effects->m_SolidColor; + Call.m_ColorAdd = CColor(color.r, color.g, color.b, 0.0f); + Call.m_ColorMultiply = CColor(0.0f, 0.0f, 0.0f, color.a); } else /* Slight confusion - why no effects? */ { @@ -339,10 +340,10 @@ void GUIRenderer::Draw(DrawCalls& Calls, CCanvas2D& canvas) // Iterate through each DrawCall, and execute whatever drawing code is being called for (DrawCalls::const_iterator cit = Calls.begin(); cit != Calls.end(); ++cit) { - if (cit->m_HasTexture && cit->m_Material == str_gui_basic) + if (cit->m_HasTexture && (cit->m_Material == str_gui_basic || cit->m_Material == str_gui_solid_mask)) { - CRect texCoords = cit->ComputeTexCoords(); - texCoords.Scale(cit->m_Texture->GetWidth(), cit->m_Texture->GetHeight()); + CRect texCoords = cit->ComputeTexCoords().Scale( + cit->m_Texture->GetWidth(), cit->m_Texture->GetHeight()); // Ensure the quad has the correct winding order CRect rect = cit->m_Vertices;