Skip to content

Commit

Permalink
Ensure the proper default framebuffer is bound when activating a Rend…
Browse files Browse the repository at this point in the history
…erWindow. Fixes #1471.
  • Loading branch information
binary1248 authored and eXpl0it3r committed Oct 1, 2018
1 parent 5e10e1f commit 8554d21
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions include/SFML/Graphics/RenderWindow.hpp
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions src/SFML/Graphics/RenderWindow.cpp
Expand Up @@ -34,22 +34,25 @@
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);
}


////////////////////////////////////////////////////////////
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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<GLint*>(&m_defaultFrameBuffer)));
}

// Just initialize the render target part
RenderTarget::initialize();
}
Expand Down

0 comments on commit 8554d21

Please sign in to comment.