diff --git a/src/framework/graphics/framebuffer.cpp b/src/framework/graphics/framebuffer.cpp index bf4adbcd..3efd6b63 100644 --- a/src/framework/graphics/framebuffer.cpp +++ b/src/framework/graphics/framebuffer.cpp @@ -79,6 +79,9 @@ FrameBuffer::FrameBuffer(int width, int height) // otherwise fallback to copy texture from screen implementation m_fallbackOldImp = true; } + + if(m_fallbackOldImp) + logInfo("Framebuffers not supported, falling back to old implementation."); } FrameBuffer::~FrameBuffer() @@ -92,13 +95,23 @@ void FrameBuffer::bind() if(!m_fallbackOldImp) { // bind framebuffer oglBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fbo); + } else { + int screenWidth = g_graphics.getScreenSize().width(); + int screenHeight = g_graphics.getScreenSize().height(); + + if(!m_screenBackup || m_screenBackup->getSize() != g_graphics.getScreenSize()) + m_screenBackup = TexturePtr(new Texture(screenWidth, screenHeight, 4)); + + // save screen state + glBindTexture(GL_TEXTURE_2D, m_screenBackup->getId()); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screenWidth, screenHeight); } // setup framebuffer viewport glViewport(0, 0, m_texture->getWidth(), m_texture->getHeight()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0.0f, m_texture->getWidth(), 0, m_texture->getHeight(), -1, 1); + glOrtho(0.0f, m_texture->getWidth(), m_texture->getHeight(), 0, -1, 1); // back to model view glMatrixMode(GL_MODELVIEW); @@ -127,13 +140,14 @@ void FrameBuffer::unbind() // restore graphics viewport g_graphics.restoreViewport(); - // clear screen + // restore screen glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); + g_graphics.drawTexturedRect(Rect(Point(0,0), g_graphics.getScreenSize()), m_screenBackup, Rect(), true); } } void FrameBuffer::draw(const Rect& screenCoords, const Rect& framebufferCoords) { - g_graphics.drawTexturedRect(screenCoords, m_texture, framebufferCoords); + g_graphics.drawTexturedRect(screenCoords, m_texture, framebufferCoords, true); } diff --git a/src/framework/graphics/framebuffer.h b/src/framework/graphics/framebuffer.h index 7e414f9c..10ffeaaa 100644 --- a/src/framework/graphics/framebuffer.h +++ b/src/framework/graphics/framebuffer.h @@ -44,6 +44,7 @@ public: private: TexturePtr m_texture; + TexturePtr m_screenBackup; uint m_fbo; bool m_fallbackOldImp; }; diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index 648290e8..63953416 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -132,7 +132,8 @@ void Graphics::endRender() void Graphics::drawTexturedRect(const Rect& screenCoords, const TexturePtr& texture, - const Rect& textureCoords) + const Rect& textureCoords, + bool upsideDown) { if(screenCoords.isEmpty() || texture->getId() == 0) return; @@ -151,13 +152,23 @@ void Graphics::drawTexturedRect(const Rect& screenCoords, if(textureCoords.isEmpty()) { textureRight = texture->getWidth() / (float)textureSize.width(); - textureBottom = texture->getHeight() / (float)textureSize.height(); - textureTop = 0.0f; + if(upsideDown) { + textureBottom = 0.0f; + textureTop = texture->getHeight() / (float)textureSize.height(); + } else { + textureBottom = texture->getHeight() / (float)textureSize.height(); + textureTop = 0.0f; + } textureLeft = 0.0f; } else { textureRight = (textureCoords.right() + 1) / (float)textureSize.width(); - textureBottom = (textureCoords.bottom() + 1) / (float)textureSize.height(); - textureTop = textureCoords.top() / (float)textureSize.height(); + if(upsideDown) { + textureTop = (textureCoords.bottom() + 1) / (float)textureSize.height(); + textureBottom = textureCoords.top() / (float)textureSize.height(); + } else { + textureBottom = (textureCoords.bottom() + 1) / (float)textureSize.height(); + textureTop = textureCoords.top() / (float)textureSize.height(); + } textureLeft = textureCoords.left() / (float)textureSize.width(); } diff --git a/src/framework/graphics/graphics.h b/src/framework/graphics/graphics.h index 82e2aa16..fcc26feb 100644 --- a/src/framework/graphics/graphics.h +++ b/src/framework/graphics/graphics.h @@ -56,7 +56,8 @@ public: // drawing API void drawTexturedRect(const Rect& screenCoords, const TexturePtr& texture, - const Rect& textureCoords = Rect()); + const Rect& textureCoords = Rect(), + bool upsideDown = false); void drawRepeatedTexturedRect(const Rect& screenCoords, const TexturePtr& texture,