Browse Source

Pixel storage support, part 7: state tracking for glPixelStore().

pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
1d2485fd28
  1. 6
      src/Magnum/Context.cpp
  2. 11
      src/Magnum/Context.h
  3. 52
      src/Magnum/Implementation/RendererState.cpp
  4. 32
      src/Magnum/Implementation/RendererState.h

6
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) {

11
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
};

52
src/Magnum/Implementation/RendererState.cpp

@ -70,6 +70,58 @@ RendererState::RendererState(Context& context, std::vector<std::string>& extensi
static_cast<void>(context);
static_cast<void>(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<Extensions::GL::EXT::unpack_subimage>())
unpackPixelStorage.disengagedRowLength = 0;
if(!context.isExtensionSupported<Extensions::GL::NV::pack_subimage>())
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
}
}}

32
src/Magnum/Implementation/RendererState.h

@ -29,6 +29,8 @@
#include <vector>
#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<bool> 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;
};
}}

Loading…
Cancel
Save