Commits

Alex Szpakowski committed 496f625

The graphics viewport is now properly restored when switching from an active Canvas to no Canvas (resolves issue #817)

Comments (0)

Files changed (3)

src/modules/graphics/opengl/Canvas.cpp

 FramebufferStrategyEXT strategyEXT;
 
 Canvas *Canvas::current = NULL;
+OpenGL::Viewport Canvas::systemViewport = OpenGL::Viewport();
 
 static void getStrategy()
 {
 		current->stopGrab();
 
 	// bind the framebuffer object.
-	glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
+	systemViewport = gl.getViewport();
 	strategy->bindFBO(fbo);
 	gl.setViewport(OpenGL::Viewport(0, 0, width, height));
 
 	strategy->bindFBO(0);
 	glMatrixMode(GL_PROJECTION);
 	glPopMatrix();
-	glPopAttrib();
+	glMatrixMode(GL_MODELVIEW);
+	gl.setViewport(systemViewport);
 	current = NULL;
 }
 

src/modules/graphics/opengl/Canvas.h

 	static Canvas *current;
 	static void bindDefaultCanvas();
 
+	// The viewport dimensions of the system (default) framebuffer.
+	static OpenGL::Viewport systemViewport;
+
 	GLuint getTextureName() const
 	{
 		return img;

src/modules/graphics/opengl/Graphics.cpp

 	if (!isCreated())
 		return;
 
-	// Set the viewport to top-left corner
+	// We want to affect the main screen, not any Canvas that's currently active
+	// (not that any *should* be active when this is called.)
+	Canvas *c = Canvas::current;
+	Canvas::bindDefaultCanvas();
+
+	// Set the viewport to top-left corner.
 	gl.setViewport(OpenGL::Viewport(0, 0, width, height));
 
+	// If a canvas was bound before this function was called, it needs to be
+	// made aware of the new system viewport size.
+	Canvas::systemViewport = gl.getViewport();
+
 	// Reset the projection matrix
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
 	glOrtho(0.0, width, height, 0.0, -1.0, 1.0);
 
 	glMatrixMode(GL_MODELVIEW);
+
+	// Restore the previously active Canvas.
+	if (c != nullptr)
+		c->startGrab(c->getAttachedCanvases());
 }
 
 bool Graphics::setMode(int width, int height)