diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 86e314d8d..edddc9250 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -783,7 +783,7 @@ Text *Graphics::newText(Font *font, const std::string &text) void Graphics::setColor(Color c) { - gl.setColor(c); + glVertexAttrib4f(ATTRIB_CONSTANTCOLOR, c.r/255.0f, c.g/255.0f, c.b/255.0f, c.a/255.0f); states.back().color = c; } diff --git a/src/modules/graphics/opengl/Mesh.cpp b/src/modules/graphics/opengl/Mesh.cpp index f157b3815..2e4f5cdb1 100644 --- a/src/modules/graphics/opengl/Mesh.cpp +++ b/src/modules/graphics/opengl/Mesh.cpp @@ -654,7 +654,7 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo { glDisableVertexAttribArray(attrib); if (attrib == ATTRIB_COLOR) - gl.setColor(gl.getColor()); + glVertexAttrib4f(ATTRIB_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); } } diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index a98ba93d5..2b9cbf15d 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -86,9 +86,9 @@ void OpenGL::setupContext() initMaxValues(); - state.color = Color(255, 255, 255, 255); GLfloat glcolor[4] = {1.0f, 1.0f, 1.0f, 1.0f}; glVertexAttrib4fv(ATTRIB_COLOR, glcolor); + glVertexAttrib4fv(ATTRIB_CONSTANTCOLOR, glcolor); // Get the current viewport. glGetIntegerv(GL_VIEWPORT, (GLint *) &state.viewport.x); @@ -317,10 +317,11 @@ void OpenGL::prepareDraw() TempDebugGroup debuggroup("Prepare OpenGL draw"); Shader *shader = Shader::current; + if (shader != nullptr) { - // Make sure the active shader has the correct values for its - // love-provided uniforms. + // Make sure the active shader has the correct values for its love- + // provided uniforms. shader->checkSetScreenParams(); } @@ -374,19 +375,6 @@ void OpenGL::drawElements(GLenum mode, GLsizei count, GLenum type, const void *i ++stats.drawCalls; } -void OpenGL::setColor(const Color &c) -{ - GLfloat glc[] = {c.r / 255.0f, c.g / 255.0f, c.b / 255.0f, c.a / 255.0f}; - glVertexAttrib4fv(ATTRIB_COLOR, glc); - - state.color = c; -} - -Color OpenGL::getColor() const -{ - return state.color; -} - void OpenGL::setViewport(const OpenGL::Viewport &v) { glViewport(v.x, v.y, v.w, v.h); diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index 466c9aa33..9dcd7c5fb 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -56,6 +56,7 @@ enum VertexAttribID ATTRIB_POS = 0, ATTRIB_TEXCOORD, ATTRIB_COLOR, + ATTRIB_CONSTANTCOLOR, ATTRIB_MAX_ENUM }; @@ -196,16 +197,6 @@ public: void drawArrays(GLenum mode, GLint first, GLsizei count); void drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices); - /** - * Sets the current constant color. - **/ - void setColor(const Color &c); - - /** - * Gets the current constant color. - **/ - Color getColor() const; - /** * Sets the OpenGL rendering viewport to the specified rectangle. * The y-coordinate starts at the top. @@ -356,9 +347,6 @@ private: // Tracked OpenGL state. struct { - // Current constant color. - Color color; - // Texture unit state (currently bound texture for each texture unit.) std::vector boundTextures; diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index a29bd4966..e176acd85 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/src/modules/graphics/opengl/ParticleSystem.cpp @@ -854,8 +854,6 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo OpenGL::TempDebugGroup debuggroup("ParticleSystem draw"); - Color curcolor = gl.getColor(); - static Matrix t; t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky); @@ -916,7 +914,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo glDisableVertexAttribArray(ATTRIB_POS); glDisableVertexAttribArray(ATTRIB_COLOR); - gl.setColor(curcolor); + glVertexAttrib4f(ATTRIB_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); } void ParticleSystem::update(float dt) diff --git a/src/modules/graphics/opengl/Polyline.cpp b/src/modules/graphics/opengl/Polyline.cpp index ad3b003f5..de4ed478c 100644 --- a/src/modules/graphics/opengl/Polyline.cpp +++ b/src/modules/graphics/opengl/Polyline.cpp @@ -379,9 +379,8 @@ void Polyline::draw() if (overdraw) { // prepare colors: - Color c = gl.getColor(); Color *colors = new Color[overdraw_vertex_count]; - fill_color_array(colors, c); + fill_color_array(colors); glEnableVertexAttribArray(ATTRIB_COLOR); glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, colors); @@ -393,10 +392,9 @@ void Polyline::draw() gl.drawArrays(draw_mode, 0, (int) overdraw_vertex_count); glDisableVertexAttribArray(ATTRIB_COLOR); + glVertexAttrib4f(ATTRIB_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); delete[] colors; - - gl.setColor(c); } glDisableVertexAttribArray(ATTRIB_POS); @@ -405,23 +403,21 @@ void Polyline::draw() delete[] indices; } -void Polyline::fill_color_array(Color *colors, const Color &c) +void Polyline::fill_color_array(Color *colors) { for (size_t i = 0; i < overdraw_vertex_count; ++i) { - colors[i] = c; // avoids branching. equiv to if (i%2 == 1) colors[i].a = 0; - colors[i].a *= GLubyte((i+1) % 2); + colors[i] = {255, 255, 255, GLubyte(255 * ((i+1) % 2))}; } } -void NoneJoinPolyline::fill_color_array(Color *colors, const Color &c) +void NoneJoinPolyline::fill_color_array(Color *colors) { for (size_t i = 0; i < overdraw_vertex_count; ++i) { - colors[i] = c; // if (i % 4 == 1 || i % 4 == 2) colors[i].a = 0 - colors[i].a *= GLubyte((i+1) % 4 < 2); + colors[i] = {255, 255, 255, GLubyte(255 * ((i+1) % 4 < 2))}; } } diff --git a/src/modules/graphics/opengl/Polyline.h b/src/modules/graphics/opengl/Polyline.h index 759202e50..383d5925e 100644 --- a/src/modules/graphics/opengl/Polyline.h +++ b/src/modules/graphics/opengl/Polyline.h @@ -71,7 +71,7 @@ public: protected: virtual void render_overdraw(const std::vector &normals, float pixel_size, bool is_looping); - virtual void fill_color_array(Color *colors, const Color &c); + virtual void fill_color_array(Color *colors); /** Calculate line boundary points. * @@ -120,7 +120,7 @@ public: protected: virtual void render_overdraw(const std::vector &normals, float pixel_size, bool is_looping); - virtual void fill_color_array(Color *colors, const Color &c); + virtual void fill_color_array(Color *colors); virtual void renderEdge(std::vector &anchors, std::vector &normals, Vector &s, float &len_s, Vector &ns, const Vector &q, const Vector &r, float hw); diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index d9e79637e..e3439f747 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -282,7 +282,7 @@ bool Shader::loadVolatile() throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str()); } - // Retreive all active uniform variables in this shader from OpenGL. + // Get all active uniform variables in this shader from OpenGL. mapActiveUniforms(); for (int i = 0; i < int(ATTRIB_MAX_ENUM); i++) @@ -869,6 +869,7 @@ StringMap::Entry Shader::attribNameEntries[] = {"VertexPosition", ATTRIB_POS}, {"VertexTexCoord", ATTRIB_TEXCOORD}, {"VertexColor", ATTRIB_COLOR}, + {"ConstantColor", ATTRIB_CONSTANTCOLOR}, }; StringMap Shader::attribNames(Shader::attribNameEntries, sizeof(Shader::attribNameEntries)); diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index c57dc902e..95375a62b 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -236,8 +236,6 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float array_buf->unmap(buffer_used_offset, buffer_used_size); buffer_used_offset = buffer_used_size = 0; - Color curcolor = gl.getColor(); - // Apply per-sprite color, if a color is set. if (color) { @@ -260,7 +258,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float if (color) { glDisableVertexAttribArray(ATTRIB_COLOR); - gl.setColor(curcolor); + glVertexAttrib4f(ATTRIB_COLOR, 1.0f, 1.0f, 1.0f, 1.0f); } } diff --git a/src/modules/graphics/opengl/wrap_Graphics.lua b/src/modules/graphics/opengl/wrap_Graphics.lua index f1dbd4edd..fd8072d7e 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.lua +++ b/src/modules/graphics/opengl/wrap_Graphics.lua @@ -71,6 +71,7 @@ GLSL.VERTEX = { attribute vec4 VertexPosition; attribute vec4 VertexTexCoord; attribute vec4 VertexColor; +attribute vec4 ConstantColor; varying vec4 VaryingTexCoord; varying vec4 VaryingColor; @@ -82,7 +83,7 @@ uniform mediump float love_PointSize; FOOTER = [[ void main() { VaryingTexCoord = VertexTexCoord; - VaryingColor = VertexColor; + VaryingColor = VertexColor * ConstantColor; #ifdef GL_ES gl_PointSize = love_PointSize; #endif