From 0731dcb60f98aad27b862ea2e2218d0ed5571308 Mon Sep 17 00:00:00 2001 From: Timo Lotterbach Date: Mon, 9 Jan 2012 16:20:15 +0100 Subject: [PATCH] Graphic: Fixing rendering of ScreenShot - X11WindowSystem: The graphicContext has to be activated before the content of FrameBuffer is saved. - GLESGraphicSystem: CodeCleanup. --- .../src/GraphicSystems/GLESGraphicSystem.cpp | 29 ++++++++-------------- .../Graphic/src/WindowSystems/X11WindowSystem.cpp | 7 +++--- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp index c92b0a9..96f5689 100644 --- a/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp +++ b/LayerManagerPlugins/Renderers/Graphic/src/GraphicSystems/GLESGraphicSystem.cpp @@ -431,40 +431,31 @@ void GLESGraphicsystem::saveScreenShotOfFramebuffer(std::string fileToSave) { // clear error if any int error = glGetError(); - LOG_DEBUG("BaseGraphicSystem","taking screenshot and saving it to:" << fileToSave); + LOG_DEBUG("GLESGraphicSystem","taking screenshot and saving it to:" << fileToSave); - GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); // x,y,width,height + LOG_DEBUG("GLESGraphicSystem","Screenshot: " << m_displayWidth << " * " << m_displayHeight); + char *buffer = (char *) malloc( m_displayWidth * m_displayHeight * 4 * sizeof(char)); + glReadPixels(0, 0, m_displayWidth, m_displayHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer); error = glGetError(); if (error != GL_NO_ERROR) { - LOG_DEBUG("BaseGraphicSystem","error getting dimensions"); - } - int WINDOW_WIDTH = viewport[2]; - int WINDOW_HEIGHT = viewport[3]; - LOG_DEBUG("BaseGraphicSystem","Screenshot: " << WINDOW_WIDTH << " * " << WINDOW_HEIGHT); - char *buffer = (char *) malloc( WINDOW_WIDTH * WINDOW_HEIGHT * 4 * sizeof(char)); - glReadPixels(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - error = glGetError(); - if (error != GL_NO_ERROR) - { - LOG_DEBUG("BaseGraphicSystem","error reading pixels for screenshot: " << error); + LOG_DEBUG("GLESGraphicSystem","error reading pixels for screenshot: " << error); } // convert to RGB for bitmap - int pixelcount = WINDOW_WIDTH * WINDOW_HEIGHT; + int pixelcount = m_displayHeight * m_displayWidth; char *rgbbuffer = (char *) malloc(pixelcount * 3 * sizeof(char)); - for (int row = 0; row < WINDOW_HEIGHT; row++) + for (int row = 0; row < m_displayHeight; row++) { - for (int col = 0; col < WINDOW_WIDTH; col++) + for (int col = 0; col < m_displayWidth; col++) { - int offset = row * WINDOW_WIDTH + col; + int offset = row * m_displayWidth + col; rgbbuffer[offset * 3] = buffer[offset * 4 + 2]; rgbbuffer[offset * 3 + 1] = buffer[offset * 4 + 1]; rgbbuffer[offset * 3 + 2] = buffer[offset * 4]; } } - writeBitmap(fileToSave, rgbbuffer, WINDOW_WIDTH, WINDOW_HEIGHT); + writeBitmap(fileToSave, rgbbuffer, m_displayWidth, m_displayHeight); free(buffer); free(rgbbuffer); } diff --git a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp index d3c1c37..64f53d0 100644 --- a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp +++ b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp @@ -584,11 +584,10 @@ void X11WindowSystem::Redraw() void X11WindowSystem::Screenshot() { - graphicSystem->clearBackground(); - /*LOG_INFO("X11WindowSystem","Locking List");*/ m_pScene->lockScene(); - + graphicSystem->clearBackground(); + graphicSystem->activateGraphicContext(); if (takeScreenshot==ScreenshotOfDisplay){ LOG_DEBUG("X11WindowSystem", "Taking screenshot"); RedrawAllLayers(); @@ -615,7 +614,7 @@ void X11WindowSystem::Screenshot() // graphicSystem->swapBuffers(); takeScreenshot = ScreenShotNone; LOG_DEBUG("X11WindowSystem", "Done taking screenshot"); - + graphicSystem->releaseGraphicContext(); m_pScene->unlockScene(); /*LOG_INFO("X11WindowSystem","UnLocking List");*/ } -- 2.7.4