From e237ed24325ce3761b18c01dd65607ee1d5cbcb0 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 21 Mar 2015 02:36:13 -0300 Subject: [PATCH] love.graphics.discard now accepts a table of booleans indicating which of the active canvases to discard (matches love.graphics.clear.) --- src/modules/graphics/opengl/Graphics.cpp | 17 ++++++++------- src/modules/graphics/opengl/Graphics.h | 2 +- src/modules/graphics/opengl/wrap_Graphics.cpp | 21 +++++++++++++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index a4bcef928..96f757d16 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -465,18 +465,18 @@ void Graphics::clear(const std::vector &colors) } } -void Graphics::discard(bool color, bool stencil) +void Graphics::discard(const std::vector &colorbuffers, bool stencil) { if (!(GLAD_VERSION_4_3 || GLAD_ARB_invalidate_subdata || GLAD_ES_VERSION_3_0 || GLAD_EXT_discard_framebuffer)) return; std::vector attachments; - attachments.reserve(3); + attachments.reserve(colorbuffers.size()); // glDiscardFramebuffer uses different attachment enums for the default FBO. if (!Canvas::current && gl.getDefaultFBO() == 0) { - if (color) + if (colorbuffers.size() > 0 && colorbuffers[0]) attachments.push_back(GL_COLOR); if (stencil) @@ -487,11 +487,12 @@ void Graphics::discard(bool color, bool stencil) } else { - if (color) + int activecanvascount = (int) states.back().canvases.size(); + + for (int i = 0; i < (int) colorbuffers.size(); i++) { - attachments.push_back(GL_COLOR_ATTACHMENT0); - for (int i = 0; i < (int) states.back().canvases.size() - 1; i++) - attachments.push_back(GL_COLOR_ATTACHMENT1 + i); + if (colorbuffers[i] && i < activecanvascount) + attachments.push_back(GL_COLOR_ATTACHMENT0 + i); } if (stencil) @@ -518,7 +519,7 @@ void Graphics::present() setCanvas(); // Discard the stencil buffer before swapping. - discard(false, true); + discard({}, true); #ifdef LOVE_IOS // Hack: SDL's color renderbuffer needs to be bound when swapBuffers is called. diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index a9ed6d944..133e2110d 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -94,7 +94,7 @@ public: /** * Discards the contents of the screen. **/ - void discard(bool color, bool stencil); + void discard(const std::vector &colorbuffers, bool stencil); /** * Flips buffers. (Rendered geometry is presented on screen). diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 8c9c21157..1f67e5b5a 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -88,9 +88,26 @@ int w_clear(lua_State *L) int w_discard(lua_State *L) { - bool color = luax_optboolean(L, 1, true); + std::vector colorbuffers; + + if (lua_istable(L, 1)) + { + for (size_t i = 1; i <= lua_objlen(L, 1); i++) + { + lua_rawgeti(L, 1, i); + colorbuffers.push_back(luax_optboolean(L, -1, true)); + lua_pop(L, 1); + } + } + else + { + bool discardcolor = luax_optboolean(L, 1, true); + size_t numbuffers = std::max((size_t) 1, instance()->getCanvas().size()); + colorbuffers = std::vector(numbuffers, discardcolor); + } + bool stencil = luax_optboolean(L, 2, true); - instance()->discard(color, stencil); + instance()->discard(colorbuffers, stencil); return 0; }