From 8554d210dfb7d5e385305aef61903286407965be Mon Sep 17 00:00:00 2001 From: binary1248 Date: Sat, 15 Sep 2018 21:36:53 +0200 Subject: [PATCH] Ensure the proper default framebuffer is bound when activating a RenderWindow. Fixes #1471. --- include/SFML/Graphics/RenderWindow.hpp | 7 +++++++ src/SFML/Graphics/RenderWindow.cpp | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/SFML/Graphics/RenderWindow.hpp b/include/SFML/Graphics/RenderWindow.hpp index 2b3b6bce4a..01f07828bd 100644 --- a/include/SFML/Graphics/RenderWindow.hpp +++ b/include/SFML/Graphics/RenderWindow.hpp @@ -177,6 +177,13 @@ class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget /// //////////////////////////////////////////////////////////// virtual void onResize(); + +private: + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + unsigned int m_defaultFrameBuffer; ///< Framebuffer to bind when targeting this window }; } // namespace sf diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index 446e906097..42f4ffeafa 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -34,14 +34,16 @@ namespace sf { //////////////////////////////////////////////////////////// -RenderWindow::RenderWindow() +RenderWindow::RenderWindow() : +m_defaultFrameBuffer(0) { // Nothing to do } //////////////////////////////////////////////////////////// -RenderWindow::RenderWindow(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) +RenderWindow::RenderWindow(VideoMode mode, const String& title, Uint32 style, const ContextSettings& settings) : +m_defaultFrameBuffer(0) { // Don't call the base class constructor because it contains virtual function calls create(mode, title, style, settings); @@ -49,7 +51,8 @@ RenderWindow::RenderWindow(VideoMode mode, const String& title, Uint32 style, co //////////////////////////////////////////////////////////// -RenderWindow::RenderWindow(WindowHandle handle, const ContextSettings& settings) +RenderWindow::RenderWindow(WindowHandle handle, const ContextSettings& settings) : +m_defaultFrameBuffer(0) { // Don't call the base class constructor because it contains virtual function calls create(handle, settings); @@ -83,7 +86,7 @@ bool RenderWindow::setActive(bool active) // try to draw to the default framebuffer of the RenderWindow if (active && result && priv::RenderTextureImplFBO::isAvailable()) { - priv::RenderTextureImplFBO::unbind(); + glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_FRAMEBUFFER, m_defaultFrameBuffer)); return true; } @@ -108,6 +111,13 @@ Image RenderWindow::capture() const //////////////////////////////////////////////////////////// void RenderWindow::onCreate() { + if (priv::RenderTextureImplFBO::isAvailable()) + { + // Retrieve the framebuffer ID we have to bind when targeting the window for rendering + // We assume that this window's context is still active at this point + glCheck(glGetIntegerv(GLEXT_GL_FRAMEBUFFER_BINDING, reinterpret_cast(&m_defaultFrameBuffer))); + } + // Just initialize the render target part RenderTarget::initialize(); }