From 8c9ebc2dcd557e46f233aff3e814513b803b5931 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 31 Aug 2023 17:11:32 +0200 Subject: [PATCH] Renamed the textureSize shader uniform to texSize to avoid collision with the GLSL keyword Also some additional minor renderer code cleanup --- es-core/src/components/ImageComponent.cpp | 14 ++++++------- es-core/src/components/ImageComponent.h | 2 +- es-core/src/renderers/Renderer.h | 25 ++++++++++++++--------- es-core/src/renderers/RendererOpenGL.cpp | 2 +- es-core/src/renderers/ShaderOpenGL.cpp | 2 +- es-core/src/renderers/ShaderOpenGL.h | 2 +- es-core/src/resources/Font.cpp | 2 +- resources/shaders/glsl/core.glsl | 13 ++++++------ resources/shaders/glsl/scanlines.glsl | 10 ++++----- 9 files changed, 38 insertions(+), 34 deletions(-) diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index c7b9f0ad5..2ed6965b8 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -355,12 +355,12 @@ void ImageComponent::setDimming(float 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; - mClipRegion = clipRegion; + mClipRegion = clipRegionArg; if (mClipRegion == glm::vec4 {0.0f, 0.0f, 0.0f, 0.0f}) { 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[0].clipregion = clipRegion; - mVertices[1].clipregion = clipRegion; - mVertices[2].clipregion = clipRegion; - mVertices[3].clipregion = clipRegion; + mVertices[0].clipRegion = mClipRegion; + mVertices[1].clipRegion = mClipRegion; + mVertices[2].clipRegion = mClipRegion; + mVertices[3].clipRegion = mClipRegion; } void ImageComponent::setFlipX(bool state) diff --git a/es-core/src/components/ImageComponent.h b/es-core/src/components/ImageComponent.h index 4ba4121f2..ed2747fc4 100644 --- a/es-core/src/components/ImageComponent.h +++ b/es-core/src/components/ImageComponent.h @@ -88,7 +88,7 @@ public: void setOpacity(float opacity) override; void setSaturation(float saturation) 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 setCornerAntiAliasing(bool state) { mCornerAntiAliasing = state; } diff --git a/es-core/src/renderers/Renderer.h b/es-core/src/renderers/Renderer.h index 5c65e274d..25949538b 100644 --- a/es-core/src/renderers/Renderer.h +++ b/es-core/src/renderers/Renderer.h @@ -63,7 +63,7 @@ public: glm::vec2 position; glm::vec2 texcoord; unsigned int color; - glm::vec4 clipregion; + glm::vec4 clipRegion; float brightness; float opacity; float saturation; @@ -75,7 +75,11 @@ public: unsigned int shaderFlags; 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} , saturation {1.0f} , dimming {1.0f} @@ -87,14 +91,15 @@ public: { } - Vertex(const glm::vec2& position, - const glm::vec2& textureCoord, - const unsigned int color, - const glm::vec4& clipRegion = glm::vec4 {0.0f, 0.0f, 0.0f, 0.0f}) - : position(position) - , texcoord(textureCoord) - , color(color) - , clipregion(clipRegion) + Vertex(const glm::vec2& positionArg, + const glm::vec2& texcoordArg, + const unsigned int colorArg, + const glm::vec4& clipRegionArg = glm::vec4 {0.0f, 0.0f, 0.0f, 0.0f}, + const glm::vec2& shadowOffsetArg = glm::vec2 {0.0f, 0.0f}) + : position {positionArg} + , texcoord {texcoordArg} + , color {colorArg} + , clipRegion {clipRegionArg} , brightness {0.0f} , opacity {1.0f} , saturation {1.0f} diff --git a/es-core/src/renderers/RendererOpenGL.cpp b/es-core/src/renderers/RendererOpenGL.cpp index 188f39985..c6c18968a 100644 --- a/es-core/src/renderers/RendererOpenGL.cpp +++ b/es-core/src/renderers/RendererOpenGL.cpp @@ -500,7 +500,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices, mCoreShader->setAttribPointers(); GL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * numVertices, vertices, GL_DYNAMIC_DRAW)); - mCoreShader->setClipRegion(vertices->clipregion); + mCoreShader->setClipRegion(vertices->clipRegion); mCoreShader->setBrightness(vertices->brightness); mCoreShader->setOpacity(vertices->opacity); mCoreShader->setSaturation(vertices->saturation); diff --git a/es-core/src/renderers/ShaderOpenGL.cpp b/es-core/src/renderers/ShaderOpenGL.cpp index 3c7a3a13e..4511fc2cf 100644 --- a/es-core/src/renderers/ShaderOpenGL.cpp +++ b/es-core/src/renderers/ShaderOpenGL.cpp @@ -123,7 +123,7 @@ void ShaderOpenGL::getVariableLocations(GLuint programID) mShaderPosition = glGetAttribLocation(mProgramID, "positionVertex"); mShaderTextureCoord = glGetAttribLocation(mProgramID, "texCoordVertex"); mShaderColor = glGetAttribLocation(mProgramID, "colorVertex"); - mShaderTextureSize = glGetUniformLocation(mProgramID, "textureSize"); + mShaderTextureSize = glGetUniformLocation(mProgramID, "texSize"); mShaderClipRegion = glGetUniformLocation(mProgramID, "clipRegion"); mShaderBrightness = glGetUniformLocation(mProgramID, "brightness"); mShaderOpacity = glGetUniformLocation(mProgramID, "opacity"); diff --git a/es-core/src/renderers/ShaderOpenGL.h b/es-core/src/renderers/ShaderOpenGL.h index c995100c4..338464e92 100644 --- a/es-core/src/renderers/ShaderOpenGL.h +++ b/es-core/src/renderers/ShaderOpenGL.h @@ -96,8 +96,8 @@ private: GLint mShaderPosition; GLint mShaderTextureCoord; GLint mShaderColor; - GLint mShaderClipRegion; GLint mShaderTextureSize; + GLint mShaderClipRegion; GLint mShaderBrightness; GLint mShaderOpacity; GLint mShaderSaturation; diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index e55214c0b..52d419766 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -252,7 +252,7 @@ void Font::renderTextCache(TextCache* cache) if (clipRegion) { it->verts[0].shaderFlags |= Renderer::ShaderFlags::CLIPPING; - it->verts[0].clipregion = cache->clipRegion; + it->verts[0].clipRegion = cache->clipRegion; } mRenderer->bindTexture(*it->textureIdPtr); diff --git a/resources/shaders/glsl/core.glsl b/resources/shaders/glsl/core.glsl index 361d7dc26..98300afac 100644 --- a/resources/shaders/glsl/core.glsl +++ b/resources/shaders/glsl/core.glsl @@ -37,7 +37,7 @@ in vec2 position; in vec2 texCoord; in vec4 color; -uniform vec2 textureSize; +uniform vec2 texSize; uniform vec4 clipRegion; uniform float brightness; uniform float saturation; @@ -79,13 +79,12 @@ void main() if (0x0u != (shaderFlags & 0x20u) || 0x0u != (shaderFlags & 0x40u)) { float radius = cornerRadius; // Don't go beyond half the width and height. - if (radius > textureSize.x / 2.0) - radius = textureSize.x / 2.0; - if (radius > textureSize.y / 2.0) - radius = textureSize.y / 2.0; + if (radius > texSize.x / 2.0) + radius = texSize.x / 2.0; + if (radius > texSize.y / 2.0) + radius = texSize.y / 2.0; - vec2 q = abs(position - textureSize / 2.0) - - (vec2(textureSize.x / 2.0, textureSize.y / 2.0) - radius); + vec2 q = abs(position - texSize / 2.0) - (vec2(texSize.x / 2.0, texSize.y / 2.0) - radius); float pixelDistance = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius; if (pixelDistance > 0.0) { diff --git a/resources/shaders/glsl/scanlines.glsl b/resources/shaders/glsl/scanlines.glsl index fb4fc1422..75c365724 100644 --- a/resources/shaders/glsl/scanlines.glsl +++ b/resources/shaders/glsl/scanlines.glsl @@ -31,14 +31,14 @@ uniform mat4 MVPMatrix; in vec2 positionVertex; in vec2 texCoordVertex; in vec4 colorVertex; -uniform vec2 textureSize; +uniform vec2 texSize; out vec2 texCoord; out vec2 onex; out vec2 oney; out vec4 colorShift; -#define SourceSize vec4(textureSize, 1.0 / textureSize) +#define SourceSize vec4(texSize, 1.0 / texSize) void main() { @@ -56,7 +56,7 @@ void main() precision mediump float; #endif -uniform vec2 textureSize; +uniform vec2 texSize; uniform float opacity; uniform float brightness; uniform float saturation; @@ -111,9 +111,9 @@ void main() vec4 SourceSize; if (rotated) - SourceSize = vec4(textureSize.yx, 1.0 / textureSize.yx); + SourceSize = vec4(texSize.yx, 1.0 / texSize.yx); else - SourceSize = vec4(textureSize.xy, 1.0 / textureSize.xy); + SourceSize = vec4(texSize.xy, 1.0 / texSize.xy); vec2 coords = (texCoord * SourceSize.xy); vec2 pixel_center = floor(coords) + vec2(0.5, 0.5);