From 0cce86beca2489e86263fc968aae041642929a99 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 18 Dec 2020 16:49:11 +0100 Subject: [PATCH] Created a common pixel conversion function for both renderers. --- es-core/src/components/ComponentGrid.cpp | 2 +- es-core/src/components/ImageComponent.cpp | 4 ++-- es-core/src/components/NinePatchComponent.cpp | 4 ++-- es-core/src/components/RatingComponent.cpp | 6 +++--- es-core/src/components/VideoVlcComponent.cpp | 3 ++- es-core/src/renderers/Renderer.cpp | 8 ++++---- es-core/src/renderers/Renderer.h | 5 ++--- es-core/src/renderers/Renderer_GL21.cpp | 11 ----------- es-core/src/renderers/Renderer_GLES10.cpp | 11 ----------- es-core/src/resources/Font.cpp | 4 ++-- 10 files changed, 18 insertions(+), 40 deletions(-) diff --git a/es-core/src/components/ComponentGrid.cpp b/es-core/src/components/ComponentGrid.cpp index 12eaa3e67..56800874e 100644 --- a/es-core/src/components/ComponentGrid.cpp +++ b/es-core/src/components/ComponentGrid.cpp @@ -163,7 +163,7 @@ void ComponentGrid::updateSeparators() { mLines.clear(); - const unsigned int color = Renderer::convertColor(0xC6C7C6FF); + const unsigned int color = Renderer::convertRGBAToABGR(0xC6C7C6FF); bool drawAll = Settings::getInstance()->getBool("DebugGrid"); Vector2f pos; diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index a2f20af20..ac18c4f3f 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -338,9 +338,9 @@ void ImageComponent::updateVertices() void ImageComponent::updateColors() { const float opacity = (mOpacity * (mFading ? mFadeOpacity / 255.0 : 1.0)) / 255.0; - const unsigned int color = Renderer::convertColor((mColorShift & 0xFFFFFF00) | + const unsigned int color = Renderer::convertRGBAToABGR((mColorShift & 0xFFFFFF00) | static_cast((mColorShift & 0xFF) * opacity)); - const unsigned int colorEnd = Renderer::convertColor((mColorShiftEnd & 0xFFFFFF00) | + const unsigned int colorEnd = Renderer::convertRGBAToABGR((mColorShiftEnd & 0xFFFFFF00) | static_cast((mColorShiftEnd & 0xFF) * opacity)); mVertices[0].col = color; diff --git a/es-core/src/components/NinePatchComponent.cpp b/es-core/src/components/NinePatchComponent.cpp index 9001339a8..a3e349a44 100644 --- a/es-core/src/components/NinePatchComponent.cpp +++ b/es-core/src/components/NinePatchComponent.cpp @@ -36,8 +36,8 @@ NinePatchComponent::~NinePatchComponent() void NinePatchComponent::updateColors() { - const unsigned int edgeColor = Renderer::convertColor(mEdgeColor); - const unsigned int centerColor = Renderer::convertColor(mCenterColor); + const unsigned int edgeColor = Renderer::convertRGBAToABGR(mEdgeColor); + const unsigned int centerColor = Renderer::convertRGBAToABGR(mCenterColor); for (int i = 0; i < 6*9; ++i) mVertices[i].col = edgeColor; diff --git a/es-core/src/components/RatingComponent.cpp b/es-core/src/components/RatingComponent.cpp index dd081e07f..4900342a2 100644 --- a/es-core/src/components/RatingComponent.cpp +++ b/es-core/src/components/RatingComponent.cpp @@ -120,7 +120,7 @@ void RatingComponent::updateVertices() const float h = getSize().y(); // Ss the same as a single star's width. const float w = getSize().y() * mValue * numStars; const float fw = getSize().y() * numStars; - const unsigned int color = Renderer::convertColor(mColorShift); + const unsigned int color = Renderer::convertRGBAToABGR(mColorShift); mVertices[0] = { { 0.0f, 0.0f }, { 0.0f, 1.0f }, color }; mVertices[1] = { { 0.0f, h }, { 0.0f, 0.0f }, color }; @@ -142,7 +142,7 @@ void RatingComponent::updateVertices() void RatingComponent::updateColors() { - const unsigned int color = Renderer::convertColor(mColorShift); + const unsigned int color = Renderer::convertRGBAToABGR(mColorShift); for (int i = 0; i < 8; ++i) mVertices[i].col = color; @@ -165,7 +165,7 @@ void RatingComponent::render(const Transform4x4f& parentTrans) if (mUnfilledTexture->bind()) { if (mUnfilledColor != mColorShift) { - const unsigned int color = Renderer::convertColor(mUnfilledColor); + const unsigned int color = Renderer::convertRGBAToABGR(mUnfilledColor); for (int i = 0; i < 8; ++i) mVertices[i].col = color; } diff --git a/es-core/src/components/VideoVlcComponent.cpp b/es-core/src/components/VideoVlcComponent.cpp index e39838836..625595c06 100644 --- a/es-core/src/components/VideoVlcComponent.cpp +++ b/es-core/src/components/VideoVlcComponent.cpp @@ -198,7 +198,8 @@ void VideoVlcComponent::render(const Transform4x4f& parentTrans) unsigned int color; if (mFadeIn < 1) { const unsigned int fadeIn = mFadeIn * 255.0f; - color = Renderer::convertColor((fadeIn << 24) | (fadeIn << 16) | (fadeIn << 8) | 255); + color = Renderer::convertRGBAToABGR((fadeIn << 24) | + (fadeIn << 16) | (fadeIn << 8) | 255); } else { color = 0xFFFFFFFF; diff --git a/es-core/src/renderers/Renderer.cpp b/es-core/src/renderers/Renderer.cpp index 7dec73b6d..34625eb89 100644 --- a/es-core/src/renderers/Renderer.cpp +++ b/es-core/src/renderers/Renderer.cpp @@ -350,8 +350,8 @@ namespace Renderer const Blend::Factor _srcBlendFactor, const Blend::Factor _dstBlendFactor) { - const unsigned int color = convertColor(_color); - const unsigned int colorEnd = convertColor(_colorEnd); + const unsigned int color = convertRGBAToABGR(_color); + const unsigned int colorEnd = convertRGBAToABGR(_colorEnd); Vertex vertices[4]; vertices[0] = { { _x ,_y }, { 0.0f, 0.0f }, color }; @@ -373,7 +373,7 @@ namespace Renderer drawTriangleStrips(vertices, 4, _trans, _srcBlendFactor, _dstBlendFactor); } - unsigned int rgbaToABGR(const unsigned int _color) + unsigned int convertRGBAToABGR(const unsigned int _color) { unsigned char red = ((_color & 0xff000000) >> 24) & 255; unsigned char green = ((_color & 0x00ff0000) >> 16) & 255; @@ -383,7 +383,7 @@ namespace Renderer return alpha << 24 | blue << 16 | green << 8 | red; } - unsigned int abgrToRGBA(const unsigned int _color) + unsigned int convertABGRToRGBA(const unsigned int _color) { unsigned char alpha = ((_color & 0xff000000) >> 24) & 255; unsigned char blue = ((_color & 0x00ff0000) >> 16) & 255; diff --git a/es-core/src/renderers/Renderer.h b/es-core/src/renderers/Renderer.h index 0ca4a7038..6ed6bada0 100644 --- a/es-core/src/renderers/Renderer.h +++ b/es-core/src/renderers/Renderer.h @@ -157,8 +157,8 @@ namespace Renderer int getScreenOffsetY(); int getScreenRotate(); - unsigned int rgbaToABGR(unsigned int color); - unsigned int abgrToRGBA(unsigned int color); + unsigned int convertRGBAToABGR(unsigned int color); + unsigned int convertABGRToRGBA(unsigned int color); Shader* getShaderProgram(unsigned int shaderID); const Transform4x4f getProjectionMatrix(); @@ -167,7 +167,6 @@ namespace Renderer unsigned char* textureRGBA = nullptr); // API specific. - unsigned int convertColor(const unsigned int _color); unsigned int getWindowFlags(); void setupWindow(); bool createContext(); diff --git a/es-core/src/renderers/Renderer_GL21.cpp b/es-core/src/renderers/Renderer_GL21.cpp index 06a77cb94..34add5aec 100644 --- a/es-core/src/renderers/Renderer_GL21.cpp +++ b/es-core/src/renderers/Renderer_GL21.cpp @@ -44,17 +44,6 @@ namespace Renderer } } - unsigned int convertColor(const unsigned int _color) - { - // Convert from rgba to abgr. - unsigned char r = ((_color & 0xff000000) >> 24) & 255; - unsigned char g = ((_color & 0x00ff0000) >> 16) & 255; - unsigned char b = ((_color & 0x0000ff00) >> 8) & 255; - unsigned char a = ((_color & 0x000000ff) ) & 255; - - return ((a << 24) | (b << 16) | (g << 8) | (r)); - } - unsigned int getWindowFlags() { return SDL_WINDOW_OPENGL; diff --git a/es-core/src/renderers/Renderer_GLES10.cpp b/es-core/src/renderers/Renderer_GLES10.cpp index 981556aa1..cb79a9d2e 100644 --- a/es-core/src/renderers/Renderer_GLES10.cpp +++ b/es-core/src/renderers/Renderer_GLES10.cpp @@ -47,17 +47,6 @@ namespace Renderer } } - unsigned int convertColor(const unsigned int _color) - { - // Convert from rgba to abgr. - unsigned char r = ((_color & 0xff000000) >> 24) & 255; - unsigned char g = ((_color & 0x00ff0000) >> 16) & 255; - unsigned char b = ((_color & 0x0000ff00) >> 8) & 255; - unsigned char a = ((_color & 0x000000ff) ) & 255; - - return ((a << 24) | (b << 16) | (g << 8) | (r)); - } - unsigned int getWindowFlags() { return SDL_WINDOW_OPENGL; diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index a132b5055..06930be0b 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -585,7 +585,7 @@ TextCache* Font::buildTextCache( const float glyphStartX = x + glyph->bearing.x(); const Vector2i& textureSize = glyph->texture->textureSize; - const unsigned int convertedColor = Renderer::convertColor(color); + const unsigned int convertedColor = Renderer::convertRGBAToABGR(color); vertices[1] = { { glyphStartX, y - glyph->bearing.y() }, @@ -648,7 +648,7 @@ TextCache* Font::buildTextCache( void TextCache::setColor(unsigned int color) { - const unsigned int convertedColor = Renderer::convertColor(color); + const unsigned int convertedColor = Renderer::convertRGBAToABGR(color); for (auto it = vertexLists.begin(); it != vertexLists.end(); it++) for (auto it2 = it->verts.begin(); it2 != it->verts.end(); it2++)