diff --git a/src/modules/graphics/Canvas.cpp b/src/modules/graphics/Canvas.cpp index 96f59594a..82fbc46cc 100644 --- a/src/modules/graphics/Canvas.cpp +++ b/src/modules/graphics/Canvas.cpp @@ -99,7 +99,7 @@ void Canvas::draw(Graphics *gfx, Quad *q, const Matrix4 &t) void Canvas::drawLayer(Graphics *gfx, int layer, Quad *quad, const Matrix4 &m) { - if (gfx->isCanvasActive(this)) + if (gfx->isCanvasActive(this, layer)) throw love::Exception("Cannot render a Canvas to itself!"); Texture::drawLayer(gfx, layer, quad, m); diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 1542312e6..ea3ef460b 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -452,15 +452,31 @@ bool Graphics::isCanvasActive() const bool Graphics::isCanvasActive(love::graphics::Canvas *canvas) const { - const auto &curRTs = states.back().renderTargets; + const auto &rts = states.back().renderTargets; - for (const auto &rt : curRTs.colors) + for (const auto &rt : rts.colors) { if (rt.canvas.get() == canvas) return true; } - if (curRTs.depthStencil.canvas.get() == canvas) + if (rts.depthStencil.canvas.get() == canvas) + return true; + + return false; +} + +bool Graphics::isCanvasActive(Canvas *canvas, int slice) const +{ + const auto &rts = states.back().renderTargets; + + for (const auto &rt : rts.colors) + { + if (rt.canvas.get() == canvas && rt.slice == slice) + return true; + } + + if (rts.depthStencil.canvas.get() == canvas && rts.depthStencil.slice == slice) return true; return false; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 77c008c0d..c568ad7f1 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -467,6 +467,7 @@ public: RenderTargets getCanvas() const; bool isCanvasActive() const; bool isCanvasActive(Canvas *canvas) const; + bool isCanvasActive(Canvas *canvas, int slice) const; /** * Scissor defines a box such that everything outside that box is discarded