From 1d2485fd282c6cda8605fcc65ef2098f447cd203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 20 Aug 2015 00:25:44 +0200 Subject: [PATCH] Pixel storage support, part 7: state tracking for glPixelStore(). --- src/Magnum/Context.cpp | 6 +++ src/Magnum/Context.h | 11 +++-- src/Magnum/Implementation/RendererState.cpp | 52 +++++++++++++++++++++ src/Magnum/Implementation/RendererState.h | 32 +++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/Magnum/Context.cpp b/src/Magnum/Context.cpp index 25191efc3..80194a847 100644 --- a/src/Magnum/Context.cpp +++ b/src/Magnum/Context.cpp @@ -48,6 +48,7 @@ #include "Implementation/BufferState.h" #include "Implementation/FramebufferState.h" #include "Implementation/MeshState.h" +#include "Implementation/RendererState.h" #include "Implementation/ShaderProgramState.h" #include "Implementation/TextureState.h" #ifndef MAGNUM_TARGET_GLES2 @@ -678,6 +679,11 @@ void Context::resetState(const States states) { if(states & State::Meshes) _state->mesh->reset(); + if(states & State::PixelStorage) { + _state->renderer->unpackPixelStorage.reset(); + _state->renderer->packPixelStorage.reset(); + } + /* Nothing to reset for renderer yet */ if(states & State::Shaders) { diff --git a/src/Magnum/Context.h b/src/Magnum/Context.h index 7b4e1ad2f..1ac5214a6 100644 --- a/src/Magnum/Context.h +++ b/src/Magnum/Context.h @@ -154,18 +154,21 @@ class MAGNUM_EXPORT Context { /** Reset tracked mesh-related bindings */ Meshes = 1 << 2, + /** Reset tracked pixel storage-related state */ + PixelStorage = 1 << 3, + /** Reset tracked renderer-related state */ - Renderer = 1 << 3, + Renderer = 1 << 4, /** Reset tracked shader-related bindings */ - Shaders = 1 << 4, + Shaders = 1 << 5, /** Reset tracked texture-related bindings and state */ - Textures = 1 << 5, + Textures = 1 << 6, #ifndef MAGNUM_TARGET_GLES2 /** Reset tracked transform feedback-related bindings */ - TransformFeedback = 1 << 6 + TransformFeedback = 1 << 7 #endif }; diff --git a/src/Magnum/Implementation/RendererState.cpp b/src/Magnum/Implementation/RendererState.cpp index efbdcf42b..d878f7fe7 100644 --- a/src/Magnum/Implementation/RendererState.cpp +++ b/src/Magnum/Implementation/RendererState.cpp @@ -70,6 +70,58 @@ RendererState::RendererState(Context& context, std::vector& extensi static_cast(context); static_cast(extensions); #endif + + /* In case the extensions are not supported on ES2, row length is + constantly 0 to avoid modifying that state */ + #if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL)) + unpackPixelStorage.disengagedRowLength = PixelStorage::DisengagedValue; + packPixelStorage.disengagedRowLength = PixelStorage::DisengagedValue; + #ifdef MAGNUM_TARGET_GLES2 + if(!context.isExtensionSupported()) + unpackPixelStorage.disengagedRowLength = 0; + if(!context.isExtensionSupported()) + packPixelStorage.disengagedRowLength = 0; + #endif + #endif +} + +RendererState::PixelStorage::PixelStorage(): + #ifndef MAGNUM_TARGET_GLES + swapBytes{false}, + #endif + alignment{4} + #if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL)) + , rowLength{0} + #endif + #ifndef MAGNUM_TARGET_GLES2 + , imageHeight{0}, + skip{0} + #endif + #ifndef MAGNUM_TARGET_GLES + , compressedBlockSize{0}, + compressedBlockDataSize{0} + #endif + {} + +void RendererState::PixelStorage::reset() { + #ifndef MAGNUM_TARGET_GLES + swapBytes = std::nullopt; + #endif + alignment = DisengagedValue; + #if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL)) + /* Resets to 0 instead of DisengagedValue in case the EXT_unpack_subimage/ + NV_pack_image ES2 extension is not supported to avoid modifying that + state */ + rowLength = disengagedRowLength; + #endif + #ifndef MAGNUM_TARGET_GLES2 + imageHeight = DisengagedValue; + skip = Vector3i{DisengagedValue}; + #endif + #ifndef MAGNUM_TARGET_GLES + compressedBlockSize = Vector3i{DisengagedValue}; + compressedBlockDataSize = DisengagedValue; + #endif } }} diff --git a/src/Magnum/Implementation/RendererState.h b/src/Magnum/Implementation/RendererState.h index 581a843de..8abb59351 100644 --- a/src/Magnum/Implementation/RendererState.h +++ b/src/Magnum/Implementation/RendererState.h @@ -29,6 +29,8 @@ #include #include "Magnum/Renderer.h" +#include "Magnum/Math/Vector3.h" +#include "MagnumExternal/Optional/optional.hpp" namespace Magnum { namespace Implementation { @@ -41,6 +43,36 @@ struct RendererState { Renderer::ResetNotificationStrategy resetNotificationStrategy; #endif + + struct PixelStorage { + enum: Int { DisengagedValue = -1 }; + + explicit PixelStorage(); + + void reset(); + + #ifndef MAGNUM_TARGET_GLES + std::optional swapBytes; + #endif + Int alignment; + #if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL)) + Int rowLength; + #endif + #ifndef MAGNUM_TARGET_GLES2 + Int imageHeight; + Vector3i skip; + #endif + #ifndef MAGNUM_TARGET_GLES + Vector3i compressedBlockSize; + Int compressedBlockDataSize; + #endif + + #if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL)) + Int disengagedRowLength; + #endif + }; + + PixelStorage packPixelStorage, unpackPixelStorage; }; }}