mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Don’t call unnecessary OpenGL APIs in love.graphics.setColor
--HG-- branch : minor
This commit is contained in:
@@ -720,7 +720,6 @@ protected:
|
||||
struct DisplayState
|
||||
{
|
||||
Colorf color = Colorf(1.0, 1.0, 1.0, 1.0);
|
||||
Colorf gammaCorrectedColor = Colorf(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
Colorf backgroundColor = Colorf(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
BlendMode blendMode = BLEND_ALPHA;
|
||||
|
||||
@@ -417,8 +417,9 @@ void Graphics::flushStreamDraws()
|
||||
break;
|
||||
}
|
||||
|
||||
Colorf nc = gl.getConstantColor();
|
||||
if (attribs & ATTRIBFLAG_COLOR)
|
||||
glVertexAttrib4f(ATTRIB_CONSTANTCOLOR, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
gl.setConstantColor(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
|
||||
pushIdentityTransform();
|
||||
|
||||
@@ -445,10 +446,7 @@ void Graphics::flushStreamDraws()
|
||||
popTransform();
|
||||
|
||||
if (attribs & ATTRIB_CONSTANTCOLOR)
|
||||
{
|
||||
Colorf nc = states.back().gammaCorrectedColor;
|
||||
glVertexAttrib4f(ATTRIB_CONSTANTCOLOR, nc.r, nc.g, nc.b, nc.a);
|
||||
}
|
||||
gl.setConstantColor(nc);
|
||||
|
||||
streamBufferState.vertexCount = 0;
|
||||
streamBufferState.indexCount = 0;
|
||||
@@ -1236,10 +1234,9 @@ void Graphics::setColor(Colorf c)
|
||||
|
||||
Colorf nc = c;
|
||||
gammaCorrectColor(nc);
|
||||
glVertexAttrib4f(ATTRIB_CONSTANTCOLOR, nc.r, nc.g, nc.b, nc.a);
|
||||
gl.setConstantColor(nc);
|
||||
|
||||
states.back().color = c;
|
||||
states.back().gammaCorrectedColor = nc;
|
||||
}
|
||||
|
||||
void Graphics::setColorMask(ColorMask mask)
|
||||
|
||||
@@ -76,6 +76,10 @@ OpenGL::OpenGL()
|
||||
, vendor(VENDOR_UNKNOWN)
|
||||
, state()
|
||||
{
|
||||
state.constantColor = Colorf(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
float nan = std::numeric_limits<float>::quiet_NaN();
|
||||
state.lastConstantColor = Colorf(nan, nan, nan, nan);
|
||||
}
|
||||
|
||||
bool OpenGL::initContext()
|
||||
@@ -337,6 +341,13 @@ void OpenGL::prepareDraw()
|
||||
// Make sure the active shader's love-provided uniforms are up to date.
|
||||
if (Shader::current != nullptr)
|
||||
((Shader *)Shader::current)->checkSetBuiltinUniforms();
|
||||
|
||||
if (state.constantColor != state.lastConstantColor)
|
||||
{
|
||||
const Colorf &c = state.constantColor;
|
||||
glVertexAttrib4f(ATTRIB_CONSTANTCOLOR, c.r, c.g, c.b, c.a);
|
||||
state.lastConstantColor = c;
|
||||
}
|
||||
}
|
||||
|
||||
GLenum OpenGL::getGLBufferType(BufferType type)
|
||||
@@ -456,6 +467,16 @@ void OpenGL::setScissor(const Rect &v, bool canvasActive)
|
||||
state.scissor = v;
|
||||
}
|
||||
|
||||
void OpenGL::setConstantColor(const Colorf &color)
|
||||
{
|
||||
state.constantColor = color;
|
||||
}
|
||||
|
||||
const Colorf &OpenGL::getConstantColor() const
|
||||
{
|
||||
return state.constantColor;
|
||||
}
|
||||
|
||||
void OpenGL::setPointSize(float size)
|
||||
{
|
||||
if (GLAD_VERSION_1_0)
|
||||
|
||||
@@ -226,10 +226,6 @@ public:
|
||||
* The y-coordinate starts at the top.
|
||||
**/
|
||||
void setViewport(const Rect &v);
|
||||
|
||||
/**
|
||||
* Gets the current OpenGL rendering viewport rectangle.
|
||||
**/
|
||||
Rect getViewport() const;
|
||||
|
||||
/**
|
||||
@@ -238,24 +234,23 @@ public:
|
||||
**/
|
||||
void setScissor(const Rect &v, bool canvasActive);
|
||||
|
||||
/**
|
||||
* Sets the constant color (vertex attribute). This may be applied
|
||||
* internally at draw-time.
|
||||
**/
|
||||
void setConstantColor(const Colorf &color);
|
||||
const Colorf &getConstantColor() const;
|
||||
|
||||
/**
|
||||
* Sets the global point size.
|
||||
**/
|
||||
void setPointSize(float size);
|
||||
|
||||
/**
|
||||
* Gets the global point size.
|
||||
**/
|
||||
float getPointSize() const;
|
||||
|
||||
/**
|
||||
* Calls glEnable/glDisable(GL_FRAMEBUFFER_SRGB).
|
||||
**/
|
||||
void setFramebufferSRGB(bool enable);
|
||||
|
||||
/**
|
||||
* Equivalent to glIsEnabled(GL_FRAMEBUFFER_SRGB).
|
||||
**/
|
||||
bool hasFramebufferSRGB() const;
|
||||
|
||||
/**
|
||||
@@ -405,6 +400,9 @@ private:
|
||||
|
||||
uint32 enabledAttribArrays;
|
||||
|
||||
Colorf constantColor;
|
||||
Colorf lastConstantColor;
|
||||
|
||||
Rect viewport;
|
||||
Rect scissor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user