From a00c006c4494fcf3965449c6c4939b49cc778d74 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 30 Dec 2013 23:52:46 -0400 Subject: [PATCH] The graphics viewport is now properly restored when switching from an active Canvas to no Canvas (resolves issue #817) --- src/modules/graphics/opengl/Canvas.cpp | 6 ++++-- src/modules/graphics/opengl/Canvas.h | 3 +++ src/modules/graphics/opengl/Graphics.cpp | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 0aa4b61cb..324e39fdc 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -343,6 +343,7 @@ FramebufferStrategyPackedEXT strategyPackedEXT; FramebufferStrategyEXT strategyEXT; Canvas *Canvas::current = NULL; +OpenGL::Viewport Canvas::systemViewport = OpenGL::Viewport(); static void getStrategy() { @@ -452,7 +453,7 @@ void Canvas::setupGrab() 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)); @@ -543,7 +544,8 @@ void Canvas::stopGrab() strategy->bindFBO(0); glMatrixMode(GL_PROJECTION); glPopMatrix(); - glPopAttrib(); + glMatrixMode(GL_MODELVIEW); + gl.setViewport(systemViewport); current = NULL; } diff --git a/src/modules/graphics/opengl/Canvas.h b/src/modules/graphics/opengl/Canvas.h index ef5de47c2..7b7a7f12d 100644 --- a/src/modules/graphics/opengl/Canvas.h +++ b/src/modules/graphics/opengl/Canvas.h @@ -112,6 +112,9 @@ public: static Canvas *current; static void bindDefaultCanvas(); + // The viewport dimensions of the system (default) framebuffer. + static OpenGL::Viewport systemViewport; + GLuint getTextureName() const { return img; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index ba519a00e..6bad5be55 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -124,9 +124,18 @@ void Graphics::setViewportSize(int width, int height) 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(); @@ -135,6 +144,10 @@ void Graphics::setViewportSize(int width, int height) 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)