diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 8aa8e07d9..bc2468ced 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -560,23 +560,40 @@ void Canvas::clear(const Color &c) strategy->bindFBO(fbo); } - // Make sure only this canvas is cleared when multi-canvas rendering is set. - if (attachedCanvases.size() > 0) - strategy->setAttachments(); + // We don't need to worry about multiple FBO attachments or global clear + // color state when OpenGL 3.0+ is supported. + 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 - // 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 (depth_stencil != 0) + { + GLint stencilvalue = 0; + 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) - strategy->setAttachments(attachedCanvases); + // Don't use the state-shadowed gl.setClearColor because we want to save + // 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) 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 @@ -623,7 +640,7 @@ void Canvas::drawg(love::graphics::Geometry *geom, float x, float y, float angle bool Canvas::checkCreateStencil() { // Do nothing if we've already created the stencil buffer. - if (depth_stencil) + if (depth_stencil != 0) return true; if (current != this)