-
Notifications
You must be signed in to change notification settings - Fork 439
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
Mixing with raw openGL calls and Context::current().resetState() #626
Comments
To explain this behavior, the state tracker at that point thinks the Mesh object VAO was still bound, while in reality you called
Yes. Buffers, textures, framebuffers, VAOs, currently used shaders, transform feedback. That all is tracked (and the tracked state is reset by this call). However note that the reset isn't resetting the state itself -- that'd be too slow -- it's just resetting the tracker. In other words it causes Magnum to explicitly rebind/reset a particular state next time it gets used, but until then GL isn't touched in any way.
The state reset in this cause leads to the state tracker thinking no known framebuffer is bound (so, not even the default one). Which then unfortunately leads to the GL::Context::current().resetState(GL::Context::State::EnterExternal);
GL::Context::current().resetState(GL::Context::State::ExitExternal);
GL::defaultFramebuffer.bind(); "fixes" this, calling the GL::Context::current().resetState(GL::Context::State::EnterExternal & ~GL::Context::State::Framebuffer);
GL::Context::current().resetState(GL::Context::State::ExitExternal & ~GL::Context::State::Framebuffer); Honestly, I'm not sure what would be the best way to handle this problem inside Magnum, apart from completely ditching the design where Magnum pretends a viewport rect is framebuffer-local state (which in reality it isn't). |
Thanks, I think I understand the behalviour better. Initially I expected that State::EnterExternal and State::ExitExternal would do a full push/pop. and State::ExitExternal would make the tracker think that the default framebuffer is bound again (or whatever state it was in at State::EnterExternal time). (which in my use case it still would be bound because I did not alter that). |
Yes, that's where the problem is. There's about sixty thousand state variables, recording all of them and setting them back to the previous would be extremely costly :/ Instead, the state tracker just resets its internal assumptions -- and expects the "external" code to also not have any assumptions about any state either -- which isn't great from an encapsulation perspective as it leads to corner cases like this, but doesn't cause perf problems. I'll think of this a bit more, maybe the bound framebuffer is a special enough state (due to how |
I am trying to get up and running with using raw openGL inside a simple Application. (I am porting an application that used to use raw SDL to now use Magnum)
I am using the imgui example as a base.
if I use some simple openGL calls:
In the Application::drawEvent()
I get a crash after a frame (or 2?) when imgui is draw with the Mesh object.
So to midigate I started to use Magnum::GL::Context::current().resetState(Magnum::GL::Context::State::EnterExternal);
and Magnum::GL::Context::current().resetState(Magnum::GL::Context::State::ExitExternal);
So now it no longer crashes (Great!)
I have found that using Magnum::GL::Context::current().resetState(); causes some corruption of the framebuffer with imgui or something. because if you add this code:
right after the _imgui.newFrame() call. the application will distort the imgui windows when the application windows is resized by dragging.
I am testing on windows.
In general I should be able to bind different gl buffers / textures as long as I use resetState() right to push/pop my changes?
The text was updated successfully, but these errors were encountered: