Alex Szpakowski avatar Alex Szpakowski committed 733d34e

Slightly improved performance of love.graphics.setCanvases

Comments (0)

Files changed (1)

src/modules/graphics/opengl/Canvas.cpp

 		std::vector<GLenum> drawbuffers;
 		drawbuffers.push_back(GL_COLOR_ATTACHMENT0);
 
-		// attach the canvas framebuffer textures to the currently bound framebuffer
+		// Attach the canvas textures to the currently bound framebuffer.
 		for (size_t i = 0; i < canvases.size(); i++)
 		{
 			glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 + i,
 		std::vector<GLenum> drawbuffers;
 		drawbuffers.push_back(GL_COLOR_ATTACHMENT0_EXT);
 
-		// attach the canvas framebuffer textures to the currently bound framebuffer
+		// Attach the canvas textures to the currently bound framebuffer.
 		for (size_t i = 0; i < canvases.size(); i++)
 		{
 			glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT + i,
 	if (current != NULL)
 		current->stopGrab();
 
-	// bind buffer and clear screen
+	// bind the framebuffer object.
 	glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
 	strategy->bindFBO(fbo);
 	gl.setViewport(OpenGL::Viewport(0, 0, width, height));
 
 void Canvas::startGrab(const std::vector<Canvas *> &canvases)
 {
+	// Whether the new canvas list is different from the old one.
+	// A more thorough check is done below.
+	bool canvaseschanged = canvases.size() != attachedCanvases.size();
+
 	if (canvases.size() > 0)
 	{
 		if (!isMultiCanvasSupported())
 
 		if (canvases[i]->getTextureType() != texture_type)
 			throw love::Exception("All canvas arguments must have the same texture type.");
+
+		if (!canvaseschanged && canvases[i] != attachedCanvases[i])
+			canvaseschanged = true;
 	}
 
 	setupGrab();
 
-	// don't attach anything if there's nothing to attach/detach
-	if (canvases.size() == 0 && attachedCanvases.size() == 0)
+	// Don't attach anything if there's nothing to change.
+	if (!canvaseschanged)
 		return;
 
-	// attach the canvas textures to the active FBO and set up multiple render targets
+	// Attach the canvas textures to the active FBO and set up MRTs.
 	strategy->setAttachments(canvases);
 
-	// retain newly attached canvases
 	for (size_t i = 0; i < canvases.size(); i++)
 		canvases[i]->retain();
 
-	// release any old canvases
 	for (size_t i = 0; i < attachedCanvases.size(); i++)
 		attachedCanvases[i]->release();
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.