mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Canvas:clear() when multiple canvases are active is now more efficient when GL3+ is supported
This commit is contained in:
@@ -560,23 +560,40 @@ void Canvas::clear(const Color &c)
|
|||||||
strategy->bindFBO(fbo);
|
strategy->bindFBO(fbo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure only this canvas is cleared when multi-canvas rendering is set.
|
// We don't need to worry about multiple FBO attachments or global clear
|
||||||
if (attachedCanvases.size() > 0)
|
// color state when OpenGL 3.0+ is supported.
|
||||||
strategy->setAttachments();
|
if (GLEE_VERSION_3_0)
|
||||||
|
{
|
||||||
|
GLuint glcolor[] = {c.r, c.g, c.b, c.a};
|
||||||
|
glClearBufferuiv(GL_COLOR, 0, glcolor);
|
||||||
|
|
||||||
// Don't use the state-shadowed gl.setClearColor because we want to save the
|
if (depth_stencil != 0)
|
||||||
// previous clear color.
|
{
|
||||||
glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
|
GLint stencilvalue = 0;
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClearBufferiv(GL_STENCIL, 0, &stencilvalue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// glClear will clear all active draw buffers, so we need to temporarily
|
||||||
|
// detach any other canvases (when MRT is being used.)
|
||||||
|
if (attachedCanvases.size() > 0)
|
||||||
|
strategy->setAttachments();
|
||||||
|
|
||||||
if (attachedCanvases.size() > 0)
|
// Don't use the state-shadowed gl.setClearColor because we want to save
|
||||||
strategy->setAttachments(attachedCanvases);
|
// the previous clear color.
|
||||||
|
glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
||||||
|
if (attachedCanvases.size() > 0)
|
||||||
|
strategy->setAttachments(attachedCanvases);
|
||||||
|
|
||||||
|
// Restore the global clear color.
|
||||||
|
gl.setClearColor(gl.getClearColor());
|
||||||
|
}
|
||||||
|
|
||||||
if (current != this)
|
if (current != this)
|
||||||
strategy->bindFBO(previous);
|
strategy->bindFBO(previous);
|
||||||
|
|
||||||
// Restore the previous clear color.
|
|
||||||
gl.setClearColor(gl.getClearColor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
|
||||||
@@ -623,7 +640,7 @@ void Canvas::drawg(love::graphics::Geometry *geom, float x, float y, float angle
|
|||||||
bool Canvas::checkCreateStencil()
|
bool Canvas::checkCreateStencil()
|
||||||
{
|
{
|
||||||
// Do nothing if we've already created the stencil buffer.
|
// Do nothing if we've already created the stencil buffer.
|
||||||
if (depth_stencil)
|
if (depth_stencil != 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (current != this)
|
if (current != this)
|
||||||
|
|||||||
Reference in New Issue
Block a user