Browse Source

GL: state reset needs to unbind PBOs when entering external code.

Qt is not PBO-aware and it messes with its state when resizing a window.
pull/432/head
Vladimír Vondruš 6 years ago
parent
commit
e5075803eb
  1. 3
      doc/changelog.dox
  2. 11
      src/Magnum/GL/Context.cpp
  3. 46
      src/Magnum/GL/Context.h

3
doc/changelog.dox

@ -300,6 +300,9 @@ See also:
- @ref GL::DynamicAttribute can now describe matrix attributes similarly to - @ref GL::DynamicAttribute can now describe matrix attributes similarly to
@ref GL::Attribute, previously this was possible only by specifying each @ref GL::Attribute, previously this was possible only by specifying each
column vector separately column vector separately
- Added @ref GL::Context::State::UnbindPixelBuffer that's now implicitly
included in @ref GL::Context::State::EnterExternal to make Magnum work
correctly with 3rd party code that's not aware of PBOs.
@subsubsection changelog-latest-changes-math Math library @subsubsection changelog-latest-changes-math Math library

11
src/Magnum/GL/Context.cpp

@ -1008,6 +1008,17 @@ Version Context::supportedVersion(std::initializer_list<Version> versions) const
} }
void Context::resetState(const States states) { void Context::resetState(const States states) {
#ifndef MAGNUM_TARGET_GLES2
/* Unbind a PBO (if any) to avoid confusing external GL code that is not
aware of those. Doing this before all buffer state is reset so we can
reuse the knowledge in our state tracker and unbind only if Magnum
actually bound a PBO before. */
if(states & State::UnbindPixelBuffer) {
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
}
#endif
if(states & State::Buffers) if(states & State::Buffers)
_state->buffer->reset(); _state->buffer->reset();
if(states & State::Framebuffers) if(states & State::Framebuffers)

46
src/Magnum/GL/Context.h

@ -267,11 +267,23 @@ class MAGNUM_GL_EXPORT Context {
/** Reset tracked buffer-related bindings and state */ /** Reset tracked buffer-related bindings and state */
Buffers = 1 << 0, Buffers = 1 << 0,
#ifndef MAGNUM_TARGET_GLES2
/**
* Unbind currently bound PBO.
*
* Not all third-party code is aware of PBOs, and if a PBO is bound
* when Magnum transfers control to an unaware code, it can cause
* various issues with textures. This is a similar, but rarer,
* case to @ref State::MeshVao / @ref State::BindScratchVao.
*/
UnbindPixelBuffer = 1 << 1,
#endif
/** Reset tracked framebuffer-related bindings and state */ /** Reset tracked framebuffer-related bindings and state */
Framebuffers = 1 << 1, Framebuffers = 1 << 2,
/** Reset tracked mesh-related bindings */ /** Reset tracked mesh-related bindings */
Meshes = 1 << 2, Meshes = 1 << 3,
/** /**
* Unbind currently bound VAO. * Unbind currently bound VAO.
@ -285,7 +297,7 @@ class MAGNUM_GL_EXPORT Context {
* with @ref State::MeshVao included unbounds any currently bound * with @ref State::MeshVao included unbounds any currently bound
* VAO to fix such case. * VAO to fix such case.
*/ */
MeshVao = 1 << 3, MeshVao = 1 << 4,
/** /**
* Bind a "scratch" VAO on core profile. * Bind a "scratch" VAO on core profile.
@ -298,40 +310,46 @@ class MAGNUM_GL_EXPORT Context {
* Does nothing on compatibility profile and ES / WebGL platforms, * Does nothing on compatibility profile and ES / WebGL platforms,
* as using the default VAO is allowed there. * as using the default VAO is allowed there.
*/ */
BindScratchVao = 1 << 4, BindScratchVao = 1 << 5,
/** Reset tracked pixel storage-related state */ /** Reset tracked pixel storage-related state */
PixelStorage = 1 << 5, PixelStorage = 1 << 6,
/** Reset tracked renderer-related state */ /** Reset tracked renderer-related state */
Renderer = 1 << 6, Renderer = 1 << 7,
/** Reset tracked shader-related bindings */ /** Reset tracked shader-related bindings */
Shaders = 1 << 7, Shaders = 1 << 8,
/** Reset tracked texture-related bindings and state */ /** Reset tracked texture-related bindings and state */
Textures = 1 << 8, Textures = 1 << 9,
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
/** Reset tracked transform feedback-related bindings */ /** Reset tracked transform feedback-related bindings */
TransformFeedback = 1 << 9, TransformFeedback = 1 << 10,
#endif #endif
/** /**
* Reset state on entering section with external OpenGL code. * Reset state on entering section with external OpenGL code.
* *
* Resets all state that could cause external code to accidentally * Resets all state that could cause external code to accidentally
* modify Magnum objects. This includes only @ref State::MeshVao. * modify Magnum objects. This includes @ref State::MeshVao and
* In some pathological cases you may want to enable * @ref State::UnbindPixelBuffer. In some pathological cases you
* @ref State::BindScratchVao as well. * may want to enable @ref State::BindScratchVao as well.
*/ */
EnterExternal = MeshVao, EnterExternal = MeshVao
#ifndef MAGNUM_TARGET_GLES2
|UnbindPixelBuffer
#endif
,
/** /**
* Reset state on exiting section with external OpenGL code. * Reset state on exiting section with external OpenGL code.
* *
* Resets Magnum state tracker to avoid being confused by external * Resets Magnum state tracker to avoid being confused by external
* state changes. This resets all states. * state changes. This resets all states, however
* @ref UnbindPixelBuffer is excluded as Magnum's state tracker
* will ensure no PBO is bound when calling related OpenGL APIs.
*/ */
ExitExternal = Buffers|Framebuffers|Meshes|MeshVao|PixelStorage|Renderer|Shaders|Textures ExitExternal = Buffers|Framebuffers|Meshes|MeshVao|PixelStorage|Renderer|Shaders|Textures
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2

Loading…
Cancel
Save