Commits

Alex Szpakowski committed fe714c6

Fixed rendering to multiple canvases, removed some redundant OpenGL calls when switching between canvases

Comments (0)

Files changed (4)

src/modules/graphics/opengl/Canvas.cpp

 	}
 }
 
-static int maxFBOColorAttachments = 0;
-static int maxDrawBuffers = 0;
-
 Canvas::Canvas(int width, int height, TextureType texture_type, int fsaa)
 	: fbo(0)
     , resolve_fbo(0)
 	if (current == this)
 		return;
 
-	// cleanup after previous fbo
-	if (current != NULL)
-		current->stopGrab();
+	// cleanup after previous Canvas
+	if (current != nullptr)
+	{
+		systemViewport = current->systemViewport;
+		current->stopGrab(true);
+	}
+	else
+		systemViewport = gl.getViewport();
+
+	// indicate we are using this Canvas.
+	current = this;
 
 	// bind the framebuffer object.
-	systemViewport = gl.getViewport();
 	strategy->bindFBO(fbo);
 	gl.setViewport(OpenGL::Viewport(0, 0, width, height));
 
 	// Switch back to modelview matrix
 	glMatrixMode(GL_MODELVIEW);
 
-	// indicate we are using this fbo
-	current = this;
-
 	if (fsaa_buffer != 0)
 		fsaa_dirty = true;
 }
 		if (!isMultiCanvasSupported())
 			throw love::Exception("Multi-canvas rendering is not supported on this system.");
 
-		if (canvases.size()+1 > size_t(maxDrawBuffers) || canvases.size()+1 > size_t(maxFBOColorAttachments))
+		if ((int) canvases.size() + 1 > gl.getMaxRenderTargets())
 			throw love::Exception("This system can't simultaniously render to %d canvases.", canvases.size()+1);
 
 		if (fsaa_samples != 0)
 	attachedCanvases.clear();
 }
 
-void Canvas::stopGrab()
+void Canvas::stopGrab(bool switchingToOtherCanvas)
 {
 	// i am not grabbing. leave me alone
 	if (current != this)
 		return;
 
-	// bind default
-	strategy->bindFBO(0);
 	glMatrixMode(GL_PROJECTION);
 	glPopMatrix();
 	glMatrixMode(GL_MODELVIEW);
 
-	current = nullptr;
-
-	gl.setViewport(systemViewport);
+	// bind default
+	if (!switchingToOtherCanvas)
+	{
+		strategy->bindFBO(0);
+		current = nullptr;
+		gl.setViewport(systemViewport);
+	}
 }
 
 void Canvas::clear(Color c)

src/modules/graphics/opengl/Canvas.h

 	 **/
 	void startGrab(const std::vector<Canvas *> &canvases);
 	void startGrab();
-	void stopGrab();
+	void stopGrab(bool switchingToOtherCanvas = false);
 
 	void clear(Color c);
 

src/modules/graphics/opengl/SpriteBatch.cpp

 	if ((index == -1 && next >= size) || index < -1 || index >= size)
 		return -1;
 
+	Vertex sprite[4];
+
 	// Needed for colors.
 	memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4);
 
 	if ((index == -1 && next >= size) || index < -1 || index >= next)
 		return -1;
 
+	Vertex sprite[4];
+
 	// Needed for colors.
 	memcpy(sprite, quad->getVertices(), sizeof(Vertex) * 4);
 

src/modules/graphics/opengl/SpriteBatch.h

 	// The next free element.
 	int next;
 
-	Vertex sprite[4];
-
 	// Current color. This color, if present, will be applied to the next
 	// added sprite.
 	Color *color;