From 551dc423a29f452b7af4b4528b7d3b369646758d Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 3 Jan 2017 23:49:29 -0400 Subject: [PATCH] Improved performance slightly when love.graphics.setColor is used heavily with automatic batching. --HG-- branch : minor --- src/modules/graphics/opengl/Graphics.cpp | 4 +--- src/modules/graphics/opengl/OpenGL.cpp | 5 +++-- src/modules/graphics/opengl/OpenGL.h | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 3b1acc5e5..e90b460e3 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -1232,9 +1232,7 @@ void Graphics::setColor(Colorf c) c.b = std::min(std::max(c.b, 0.0f), 1.0f); c.a = std::min(std::max(c.a, 0.0f), 1.0f); - Colorf nc = c; - gammaCorrectColor(nc); - gl.setConstantColor(nc); + gl.setConstantColor(c); states.back().color = c; } diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 61ce4d7da..e8679179d 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -344,9 +344,10 @@ void OpenGL::prepareDraw() if (state.constantColor != state.lastConstantColor) { - const Colorf &c = state.constantColor; + state.lastConstantColor = state.constantColor; + Colorf c = state.constantColor; + gammaCorrectColor(c); glVertexAttrib4f(ATTRIB_CONSTANTCOLOR, c.r, c.g, c.b, c.a); - state.lastConstantColor = c; } } diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index 47d5e8682..47056cc3d 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -236,7 +236,7 @@ public: /** * Sets the constant color (vertex attribute). This may be applied - * internally at draw-time. + * internally at draw-time. This gets gamma-corrected internally as well. **/ void setConstantColor(const Colorf &color); const Colorf &getConstantColor() const;