Renamed the textureSize shader uniform to texSize to avoid collision with the GLSL keyword

Also some additional minor renderer code cleanup
This commit is contained in:
Leon Styhre 2023-08-31 17:11:32 +02:00
parent 28b2c068a8
commit 8c9ebc2dcd
9 changed files with 38 additions and 34 deletions

View file

@ -355,12 +355,12 @@ void ImageComponent::setDimming(float dimming)
mDimming = dimming; mDimming = dimming;
} }
void ImageComponent::setClipRegion(const glm::vec4& clipRegion) void ImageComponent::setClipRegion(const glm::vec4& clipRegionArg)
{ {
if (mVertices[0].clipregion == clipRegion) if (mVertices[0].clipRegion == clipRegionArg)
return; return;
mClipRegion = clipRegion; mClipRegion = clipRegionArg;
if (mClipRegion == glm::vec4 {0.0f, 0.0f, 0.0f, 0.0f}) { if (mClipRegion == glm::vec4 {0.0f, 0.0f, 0.0f, 0.0f}) {
if (mVertices[0].shaderFlags & Renderer::ShaderFlags::CLIPPING) { if (mVertices[0].shaderFlags & Renderer::ShaderFlags::CLIPPING) {
@ -377,10 +377,10 @@ void ImageComponent::setClipRegion(const glm::vec4& clipRegion)
mVertices[3].shaderFlags |= Renderer::ShaderFlags::CLIPPING; mVertices[3].shaderFlags |= Renderer::ShaderFlags::CLIPPING;
} }
mVertices[0].clipregion = clipRegion; mVertices[0].clipRegion = mClipRegion;
mVertices[1].clipregion = clipRegion; mVertices[1].clipRegion = mClipRegion;
mVertices[2].clipregion = clipRegion; mVertices[2].clipRegion = mClipRegion;
mVertices[3].clipregion = clipRegion; mVertices[3].clipRegion = mClipRegion;
} }
void ImageComponent::setFlipX(bool state) void ImageComponent::setFlipX(bool state)

View file

@ -88,7 +88,7 @@ public:
void setOpacity(float opacity) override; void setOpacity(float opacity) override;
void setSaturation(float saturation) override; void setSaturation(float saturation) override;
void setDimming(float dimming) override; void setDimming(float dimming) override;
void setClipRegion(const glm::vec4& clipRegion); void setClipRegion(const glm::vec4& clipRegionArg);
void setCornerRadius(float radius) { mCornerRadius = radius; } void setCornerRadius(float radius) { mCornerRadius = radius; }
void setCornerAntiAliasing(bool state) { mCornerAntiAliasing = state; } void setCornerAntiAliasing(bool state) { mCornerAntiAliasing = state; }

View file

@ -63,7 +63,7 @@ public:
glm::vec2 position; glm::vec2 position;
glm::vec2 texcoord; glm::vec2 texcoord;
unsigned int color; unsigned int color;
glm::vec4 clipregion; glm::vec4 clipRegion;
float brightness; float brightness;
float opacity; float opacity;
float saturation; float saturation;
@ -75,7 +75,11 @@ public:
unsigned int shaderFlags; unsigned int shaderFlags;
Vertex() Vertex()
: brightness {0.0f} : position {0.0f, 0.0f}
, texcoord {0.0f, 0.0f}
, color {0x00000000}
, clipRegion {0.0f, 0.0f, 0.0f, 0.0f}
, brightness {0.0f}
, opacity {1.0f} , opacity {1.0f}
, saturation {1.0f} , saturation {1.0f}
, dimming {1.0f} , dimming {1.0f}
@ -87,14 +91,15 @@ public:
{ {
} }
Vertex(const glm::vec2& position, Vertex(const glm::vec2& positionArg,
const glm::vec2& textureCoord, const glm::vec2& texcoordArg,
const unsigned int color, const unsigned int colorArg,
const glm::vec4& clipRegion = glm::vec4 {0.0f, 0.0f, 0.0f, 0.0f}) const glm::vec4& clipRegionArg = glm::vec4 {0.0f, 0.0f, 0.0f, 0.0f},
: position(position) const glm::vec2& shadowOffsetArg = glm::vec2 {0.0f, 0.0f})
, texcoord(textureCoord) : position {positionArg}
, color(color) , texcoord {texcoordArg}
, clipregion(clipRegion) , color {colorArg}
, clipRegion {clipRegionArg}
, brightness {0.0f} , brightness {0.0f}
, opacity {1.0f} , opacity {1.0f}
, saturation {1.0f} , saturation {1.0f}

View file

@ -500,7 +500,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices,
mCoreShader->setAttribPointers(); mCoreShader->setAttribPointers();
GL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * numVertices, vertices, GL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * numVertices, vertices,
GL_DYNAMIC_DRAW)); GL_DYNAMIC_DRAW));
mCoreShader->setClipRegion(vertices->clipregion); mCoreShader->setClipRegion(vertices->clipRegion);
mCoreShader->setBrightness(vertices->brightness); mCoreShader->setBrightness(vertices->brightness);
mCoreShader->setOpacity(vertices->opacity); mCoreShader->setOpacity(vertices->opacity);
mCoreShader->setSaturation(vertices->saturation); mCoreShader->setSaturation(vertices->saturation);

View file

@ -123,7 +123,7 @@ void ShaderOpenGL::getVariableLocations(GLuint programID)
mShaderPosition = glGetAttribLocation(mProgramID, "positionVertex"); mShaderPosition = glGetAttribLocation(mProgramID, "positionVertex");
mShaderTextureCoord = glGetAttribLocation(mProgramID, "texCoordVertex"); mShaderTextureCoord = glGetAttribLocation(mProgramID, "texCoordVertex");
mShaderColor = glGetAttribLocation(mProgramID, "colorVertex"); mShaderColor = glGetAttribLocation(mProgramID, "colorVertex");
mShaderTextureSize = glGetUniformLocation(mProgramID, "textureSize"); mShaderTextureSize = glGetUniformLocation(mProgramID, "texSize");
mShaderClipRegion = glGetUniformLocation(mProgramID, "clipRegion"); mShaderClipRegion = glGetUniformLocation(mProgramID, "clipRegion");
mShaderBrightness = glGetUniformLocation(mProgramID, "brightness"); mShaderBrightness = glGetUniformLocation(mProgramID, "brightness");
mShaderOpacity = glGetUniformLocation(mProgramID, "opacity"); mShaderOpacity = glGetUniformLocation(mProgramID, "opacity");

View file

@ -96,8 +96,8 @@ private:
GLint mShaderPosition; GLint mShaderPosition;
GLint mShaderTextureCoord; GLint mShaderTextureCoord;
GLint mShaderColor; GLint mShaderColor;
GLint mShaderClipRegion;
GLint mShaderTextureSize; GLint mShaderTextureSize;
GLint mShaderClipRegion;
GLint mShaderBrightness; GLint mShaderBrightness;
GLint mShaderOpacity; GLint mShaderOpacity;
GLint mShaderSaturation; GLint mShaderSaturation;

View file

@ -252,7 +252,7 @@ void Font::renderTextCache(TextCache* cache)
if (clipRegion) { if (clipRegion) {
it->verts[0].shaderFlags |= Renderer::ShaderFlags::CLIPPING; it->verts[0].shaderFlags |= Renderer::ShaderFlags::CLIPPING;
it->verts[0].clipregion = cache->clipRegion; it->verts[0].clipRegion = cache->clipRegion;
} }
mRenderer->bindTexture(*it->textureIdPtr); mRenderer->bindTexture(*it->textureIdPtr);

View file

@ -37,7 +37,7 @@ in vec2 position;
in vec2 texCoord; in vec2 texCoord;
in vec4 color; in vec4 color;
uniform vec2 textureSize; uniform vec2 texSize;
uniform vec4 clipRegion; uniform vec4 clipRegion;
uniform float brightness; uniform float brightness;
uniform float saturation; uniform float saturation;
@ -79,13 +79,12 @@ void main()
if (0x0u != (shaderFlags & 0x20u) || 0x0u != (shaderFlags & 0x40u)) { if (0x0u != (shaderFlags & 0x20u) || 0x0u != (shaderFlags & 0x40u)) {
float radius = cornerRadius; float radius = cornerRadius;
// Don't go beyond half the width and height. // Don't go beyond half the width and height.
if (radius > textureSize.x / 2.0) if (radius > texSize.x / 2.0)
radius = textureSize.x / 2.0; radius = texSize.x / 2.0;
if (radius > textureSize.y / 2.0) if (radius > texSize.y / 2.0)
radius = textureSize.y / 2.0; radius = texSize.y / 2.0;
vec2 q = abs(position - textureSize / 2.0) - vec2 q = abs(position - texSize / 2.0) - (vec2(texSize.x / 2.0, texSize.y / 2.0) - radius);
(vec2(textureSize.x / 2.0, textureSize.y / 2.0) - radius);
float pixelDistance = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius; float pixelDistance = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius;
if (pixelDistance > 0.0) { if (pixelDistance > 0.0) {

View file

@ -31,14 +31,14 @@ uniform mat4 MVPMatrix;
in vec2 positionVertex; in vec2 positionVertex;
in vec2 texCoordVertex; in vec2 texCoordVertex;
in vec4 colorVertex; in vec4 colorVertex;
uniform vec2 textureSize; uniform vec2 texSize;
out vec2 texCoord; out vec2 texCoord;
out vec2 onex; out vec2 onex;
out vec2 oney; out vec2 oney;
out vec4 colorShift; out vec4 colorShift;
#define SourceSize vec4(textureSize, 1.0 / textureSize) #define SourceSize vec4(texSize, 1.0 / texSize)
void main() void main()
{ {
@ -56,7 +56,7 @@ void main()
precision mediump float; precision mediump float;
#endif #endif
uniform vec2 textureSize; uniform vec2 texSize;
uniform float opacity; uniform float opacity;
uniform float brightness; uniform float brightness;
uniform float saturation; uniform float saturation;
@ -111,9 +111,9 @@ void main()
vec4 SourceSize; vec4 SourceSize;
if (rotated) if (rotated)
SourceSize = vec4(textureSize.yx, 1.0 / textureSize.yx); SourceSize = vec4(texSize.yx, 1.0 / texSize.yx);
else else
SourceSize = vec4(textureSize.xy, 1.0 / textureSize.xy); SourceSize = vec4(texSize.xy, 1.0 / texSize.xy);
vec2 coords = (texCoord * SourceSize.xy); vec2 coords = (texCoord * SourceSize.xy);
vec2 pixel_center = floor(coords) + vec2(0.5, 0.5); vec2 pixel_center = floor(coords) + vec2(0.5, 0.5);