Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force OpenGL states to be reset when RenderTarget detects that a new context has to be tracked. #1630

Merged
merged 1 commit into from Jan 2, 2020

Conversation

binary1248
Copy link
Member

Fixes #1625.

Since the FBO RenderTexture implementation makes use of existing contexts where it can in order to reduce context switching, RenderTextures will almost always live in the same context as the context owning RenderTargets such as sf::RenderWindow. This also means that they will share the same OpenGL state. The glStatesSet flag that tracks whether OpenGL states have been set or not does so per-RenderTarget.

When (re-)creating a context the initial states required by SFML will have to be set up. This is normally done in sf::RenderTarget::initialize() when .create() is called on the corresponding object. The problem is that sf::RenderTarget::initialize() is not called on the FBO RenderTextures living on the same context as the RenderTarget on which .create() was called.

As shown in #1625, drawing to an FBO RenderTexture directly after the window owning its context has been re-created will not reset the OpenGL states since the flag was never reset.

This patch forces OpenGL states to be reset whenever the RenderTarget tracking detects a new context in which nothing has been activated before, regardless of whether it is a RenderWindow or a RenderTexture.

Test with code provided in #1625.

…context has to be tracked. In the case a context is re-created, FBO RenderTextures would not trigger resetting of the OpenGL states if they were drawn to first since re-initialization of the RenderTarget only happens when a context owner such as a RenderWindow is re-created. Fixes #1625.
@binary1248 binary1248 self-assigned this Dec 9, 2019
@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.6.0 via automation Dec 9, 2019
@eXpl0it3r eXpl0it3r added this to the 2.6 milestone Dec 9, 2019
@eXpl0it3r eXpl0it3r moved this from Discussion to Review & Testing in SFML 2.6.0 Dec 9, 2019
Copy link
Member

@eXpl0it3r eXpl0it3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the issue with the example code for me.

@eXpl0it3r eXpl0it3r moved this from Review & Testing to Ready in SFML 2.6.0 Jan 2, 2020
@eXpl0it3r eXpl0it3r merged commit bf98acc into master Jan 2, 2020
SFML 2.6.0 automation moved this from Ready to Done Jan 2, 2020
@eXpl0it3r eXpl0it3r deleted the bugfix/fbo_reset_gl_states branch January 2, 2020 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.6.0
  
Done
Development

Successfully merging this pull request may close these issues.

Empty RenderTexture after recreating window
2 participants