Created a common pixel conversion function for both renderers.

This commit is contained in:
Leon Styhre 2020-12-18 16:49:11 +01:00
parent bb3cc4d4a1
commit 0cce86beca
10 changed files with 18 additions and 40 deletions

View file

@ -163,7 +163,7 @@ void ComponentGrid::updateSeparators()
{ {
mLines.clear(); mLines.clear();
const unsigned int color = Renderer::convertColor(0xC6C7C6FF); const unsigned int color = Renderer::convertRGBAToABGR(0xC6C7C6FF);
bool drawAll = Settings::getInstance()->getBool("DebugGrid"); bool drawAll = Settings::getInstance()->getBool("DebugGrid");
Vector2f pos; Vector2f pos;

View file

@ -338,9 +338,9 @@ void ImageComponent::updateVertices()
void ImageComponent::updateColors() void ImageComponent::updateColors()
{ {
const float opacity = (mOpacity * (mFading ? mFadeOpacity / 255.0 : 1.0)) / 255.0; 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<unsigned char>((mColorShift & 0xFF) * opacity)); static_cast<unsigned char>((mColorShift & 0xFF) * opacity));
const unsigned int colorEnd = Renderer::convertColor((mColorShiftEnd & 0xFFFFFF00) | const unsigned int colorEnd = Renderer::convertRGBAToABGR((mColorShiftEnd & 0xFFFFFF00) |
static_cast<unsigned char>((mColorShiftEnd & 0xFF) * opacity)); static_cast<unsigned char>((mColorShiftEnd & 0xFF) * opacity));
mVertices[0].col = color; mVertices[0].col = color;

View file

@ -36,8 +36,8 @@ NinePatchComponent::~NinePatchComponent()
void NinePatchComponent::updateColors() void NinePatchComponent::updateColors()
{ {
const unsigned int edgeColor = Renderer::convertColor(mEdgeColor); const unsigned int edgeColor = Renderer::convertRGBAToABGR(mEdgeColor);
const unsigned int centerColor = Renderer::convertColor(mCenterColor); const unsigned int centerColor = Renderer::convertRGBAToABGR(mCenterColor);
for (int i = 0; i < 6*9; ++i) for (int i = 0; i < 6*9; ++i)
mVertices[i].col = edgeColor; mVertices[i].col = edgeColor;

View file

@ -120,7 +120,7 @@ void RatingComponent::updateVertices()
const float h = getSize().y(); // Ss the same as a single star's width. const float h = getSize().y(); // Ss the same as a single star's width.
const float w = getSize().y() * mValue * numStars; const float w = getSize().y() * mValue * numStars;
const float fw = getSize().y() * 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[0] = { { 0.0f, 0.0f }, { 0.0f, 1.0f }, color };
mVertices[1] = { { 0.0f, h }, { 0.0f, 0.0f }, color }; mVertices[1] = { { 0.0f, h }, { 0.0f, 0.0f }, color };
@ -142,7 +142,7 @@ void RatingComponent::updateVertices()
void RatingComponent::updateColors() void RatingComponent::updateColors()
{ {
const unsigned int color = Renderer::convertColor(mColorShift); const unsigned int color = Renderer::convertRGBAToABGR(mColorShift);
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
mVertices[i].col = color; mVertices[i].col = color;
@ -165,7 +165,7 @@ void RatingComponent::render(const Transform4x4f& parentTrans)
if (mUnfilledTexture->bind()) { if (mUnfilledTexture->bind()) {
if (mUnfilledColor != mColorShift) { if (mUnfilledColor != mColorShift) {
const unsigned int color = Renderer::convertColor(mUnfilledColor); const unsigned int color = Renderer::convertRGBAToABGR(mUnfilledColor);
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
mVertices[i].col = color; mVertices[i].col = color;
} }

View file

@ -198,7 +198,8 @@ void VideoVlcComponent::render(const Transform4x4f& parentTrans)
unsigned int color; unsigned int color;
if (mFadeIn < 1) { if (mFadeIn < 1) {
const unsigned int fadeIn = mFadeIn * 255.0f; 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 { else {
color = 0xFFFFFFFF; color = 0xFFFFFFFF;

View file

@ -350,8 +350,8 @@ namespace Renderer
const Blend::Factor _srcBlendFactor, const Blend::Factor _srcBlendFactor,
const Blend::Factor _dstBlendFactor) const Blend::Factor _dstBlendFactor)
{ {
const unsigned int color = convertColor(_color); const unsigned int color = convertRGBAToABGR(_color);
const unsigned int colorEnd = convertColor(_colorEnd); const unsigned int colorEnd = convertRGBAToABGR(_colorEnd);
Vertex vertices[4]; Vertex vertices[4];
vertices[0] = { { _x ,_y }, { 0.0f, 0.0f }, color }; vertices[0] = { { _x ,_y }, { 0.0f, 0.0f }, color };
@ -373,7 +373,7 @@ namespace Renderer
drawTriangleStrips(vertices, 4, _trans, _srcBlendFactor, _dstBlendFactor); 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 red = ((_color & 0xff000000) >> 24) & 255;
unsigned char green = ((_color & 0x00ff0000) >> 16) & 255; unsigned char green = ((_color & 0x00ff0000) >> 16) & 255;
@ -383,7 +383,7 @@ namespace Renderer
return alpha << 24 | blue << 16 | green << 8 | red; 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 alpha = ((_color & 0xff000000) >> 24) & 255;
unsigned char blue = ((_color & 0x00ff0000) >> 16) & 255; unsigned char blue = ((_color & 0x00ff0000) >> 16) & 255;

View file

@ -157,8 +157,8 @@ namespace Renderer
int getScreenOffsetY(); int getScreenOffsetY();
int getScreenRotate(); int getScreenRotate();
unsigned int rgbaToABGR(unsigned int color); unsigned int convertRGBAToABGR(unsigned int color);
unsigned int abgrToRGBA(unsigned int color); unsigned int convertABGRToRGBA(unsigned int color);
Shader* getShaderProgram(unsigned int shaderID); Shader* getShaderProgram(unsigned int shaderID);
const Transform4x4f getProjectionMatrix(); const Transform4x4f getProjectionMatrix();
@ -167,7 +167,6 @@ namespace Renderer
unsigned char* textureRGBA = nullptr); unsigned char* textureRGBA = nullptr);
// API specific. // API specific.
unsigned int convertColor(const unsigned int _color);
unsigned int getWindowFlags(); unsigned int getWindowFlags();
void setupWindow(); void setupWindow();
bool createContext(); bool createContext();

View file

@ -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() unsigned int getWindowFlags()
{ {
return SDL_WINDOW_OPENGL; return SDL_WINDOW_OPENGL;

View file

@ -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() unsigned int getWindowFlags()
{ {
return SDL_WINDOW_OPENGL; return SDL_WINDOW_OPENGL;

View file

@ -585,7 +585,7 @@ TextCache* Font::buildTextCache(
const float glyphStartX = x + glyph->bearing.x(); const float glyphStartX = x + glyph->bearing.x();
const Vector2i& textureSize = glyph->texture->textureSize; const Vector2i& textureSize = glyph->texture->textureSize;
const unsigned int convertedColor = Renderer::convertColor(color); const unsigned int convertedColor = Renderer::convertRGBAToABGR(color);
vertices[1] = { vertices[1] = {
{ glyphStartX, y - glyph->bearing.y() }, { glyphStartX, y - glyph->bearing.y() },
@ -648,7 +648,7 @@ TextCache* Font::buildTextCache(
void TextCache::setColor(unsigned int color) 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 it = vertexLists.begin(); it != vertexLists.end(); it++)
for (auto it2 = it->verts.begin(); it2 != it->verts.end(); it2++) for (auto it2 = it->verts.begin(); it2 != it->verts.end(); it2++)