Found a better solution to the single-pixel alignment rendering issue.

This commit is contained in:
Leon Styhre 2022-04-27 18:40:28 +02:00
parent 7eecf6bb41
commit 97da2df0a4
8 changed files with 19 additions and 10 deletions

View file

@ -133,7 +133,6 @@ void ButtonComponent::render(const glm::mat4& parentTrans)
glm::vec3 centerOffset {(mSize.x - mTextCache->metrics.size.x) / 2.0f,
(mSize.y - mTextCache->metrics.size.y) / 2.0f, 0.0f};
trans = glm::translate(trans, centerOffset);
trans[3] = glm::round(trans[3]);
if (Settings::getInstance()->getBool("DebugText")) {
mRenderer->drawRect(centerOffset.x, 0.0f, mTextCache->metrics.size.x, mSize.y,

View file

@ -397,7 +397,12 @@ void ImageComponent::render(const glm::mat4& parentTrans)
return;
glm::mat4 trans {parentTrans * getTransform()};
mRenderer->setMatrix(trans);
// Don't round vertices if scaled as it may lead to single-pixel alignment issues.
if (mScale == 1.0f)
mRenderer->setMatrix(trans, true);
else
mRenderer->setMatrix(trans, false);
if (mTexture && mOpacity > 0.0f) {
if (Settings::getInstance()->getBool("DebugImage")) {

View file

@ -132,7 +132,6 @@ void NinePatchComponent::render(const glm::mat4& parentTrans)
glm::mat4 trans {parentTrans * getTransform()};
if (mTexture && mVertices != nullptr) {
trans[3] = glm::round(trans[3]);
mRenderer->setMatrix(trans);
mVertices->opacity = mOpacity;
mTexture->bind();

View file

@ -202,7 +202,12 @@ void TextComponent::render(const glm::mat4& parentTrans)
mRenderer->drawRect(0.0f, 0.0f, mSize.x, mSize.y, 0x0000FF33, 0x0000FF33);
trans = glm::translate(trans, glm::vec3 {0.0f, std::round(yOff), 0.0f});
mRenderer->setMatrix(trans);
// Don't round vertices if scaled as it may lead to single-pixel alignment issues.
if (mScale == 1.0f)
mRenderer->setMatrix(trans, true);
else
mRenderer->setMatrix(trans, false);
// Draw the text area, where the text actually is located.
if (Settings::getInstance()->getBool("DebugText")) {

View file

@ -9,7 +9,6 @@
#ifndef ES_CORE_COMPONENTS_CAROUSEL_COMPONENT_H
#define ES_CORE_COMPONENTS_CAROUSEL_COMPONENT_H
#include "Log.h"
#include "Sound.h"
#include "animations/LambdaAnimation.h"
#include "components/IList.h"

View file

@ -196,7 +196,7 @@ public:
const unsigned int numVertices,
const BlendFactor srcBlendFactor = BlendFactor::SRC_ALPHA,
const BlendFactor dstBlendFactor = BlendFactor::ONE_MINUS_SRC_ALPHA) = 0;
virtual void setMatrix(const glm::mat4& matrix) = 0;
virtual void setMatrix(const glm::mat4& matrix, bool roundVertices = true) = 0;
virtual void setScissor(const Rect& scissor) = 0;
virtual void setSwapInterval() = 0;
virtual void swapBuffers() = 0;

View file

@ -275,10 +275,12 @@ void RendererOpenGL::destroyContext()
mSDLContext = nullptr;
}
void RendererOpenGL::setMatrix(const glm::mat4& matrix)
void RendererOpenGL::setMatrix(const glm::mat4& matrix, bool roundVertices)
{
// Set matrix for use with shader.
mTrans = getProjectionMatrix() * matrix;
mTrans = matrix;
if (roundVertices)
mTrans[3] = glm::round(mTrans[3]);
mTrans = getProjectionMatrix() * mTrans;
}
void RendererOpenGL::setScissor(const Rect& scissor)

View file

@ -38,7 +38,7 @@ public:
bool createContext() override;
void destroyContext() override;
void setMatrix(const glm::mat4& matrix) override;
void setMatrix(const glm::mat4& matrix, bool roundVertices = true) override;
void setScissor(const Rect& scissor) override;
void setSwapInterval() override;
void swapBuffers() override;