Browse Source

Allow calling love.graphics.drawLayer(arraycanvas, layer) when rendering to a different layer of the same Canvas.

--HG--
branch : minor
Alex Szpakowski 8 years ago
parent
commit
fd64999748

+ 1 - 1
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)
 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!");
 		throw love::Exception("Cannot render a Canvas to itself!");
 
 
 	Texture::drawLayer(gfx, layer, quad, m);
 	Texture::drawLayer(gfx, layer, quad, m);

+ 19 - 3
src/modules/graphics/Graphics.cpp

@@ -452,15 +452,31 @@ bool Graphics::isCanvasActive() const
 
 
 bool Graphics::isCanvasActive(love::graphics::Canvas *canvas) 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)
 		if (rt.canvas.get() == canvas)
 			return true;
 			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 true;
 
 
 	return false;
 	return false;

+ 1 - 0
src/modules/graphics/Graphics.h

@@ -467,6 +467,7 @@ public:
 	RenderTargets getCanvas() const;
 	RenderTargets getCanvas() const;
 	bool isCanvasActive() const;
 	bool isCanvasActive() const;
 	bool isCanvasActive(Canvas *canvas) 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
 	 * Scissor defines a box such that everything outside that box is discarded