Browse Source

GL: drop a silly <tuple> from state tracker internals.

Using a tuple was very useful, helpful and exciting as I had to make an
explicit comment about what element is what, and then having to remember
the order in all places that accessed the tuple.

Using a struct however is rather boring as the fields are just named
there, I don't need any complex std::get<4>() and extra comments
explaining what is where and it's just not so adventurous anymore. The
build time of a non-deprecated MagnumGL library also dropped from 5.9
seconds to 5.85. SAD!
pull/240/merge
Vladimír Vondruš 4 years ago
parent
commit
5f54cc4702
  1. 17
      src/Magnum/GL/AbstractTexture.cpp
  2. 3
      src/Magnum/GL/Implementation/State.cpp
  3. 7
      src/Magnum/GL/Implementation/TextureState.cpp
  4. 28
      src/Magnum/GL/Implementation/TextureState.h

17
src/Magnum/GL/AbstractTexture.cpp

@ -25,7 +25,6 @@
#include "AbstractTexture.h" #include "AbstractTexture.h"
#include <tuple>
#include <Corrade/Containers/Array.h> #include <Corrade/Containers/Array.h>
#ifndef MAGNUM_TARGET_WEBGL #ifndef MAGNUM_TARGET_WEBGL
#include <Corrade/Containers/String.h> #include <Corrade/Containers/String.h>
@ -245,7 +244,7 @@ AbstractTexture::~AbstractTexture() {
/* Remove all image bindings */ /* Remove all image bindings */
for(auto& binding: Context::current().state().texture.imageBindings) { for(auto& binding: Context::current().state().texture.imageBindings) {
/* MSVC 2015 needs the parentheses around */ /* MSVC 2015 needs the parentheses around */
if(std::get<0>(binding) == _id) binding = {}; if(binding.id == _id) binding = {};
} }
#endif #endif
@ -281,10 +280,10 @@ void AbstractTexture::unbindImage(const Int imageUnit) {
Implementation::TextureState& textureState = Context::current().state().texture; Implementation::TextureState& textureState = Context::current().state().texture;
/* If already unbound in given image unit, nothing to do */ /* If already unbound in given image unit, nothing to do */
if(std::get<0>(textureState.imageBindings[imageUnit]) == 0) return; if(textureState.imageBindings[imageUnit].id == 0) return;
/* Update state tracker, bind the texture to the unit */ /* Update state tracker, bind the texture to the unit */
std::get<0>(textureState.imageBindings[imageUnit]) = 0; textureState.imageBindings[imageUnit].id = 0;
glBindImageTexture(imageUnit, 0, 0, false, 0, GL_READ_ONLY, GL_RGBA8); glBindImageTexture(imageUnit, 0, 0, false, 0, GL_READ_ONLY, GL_RGBA8);
} }
@ -297,15 +296,15 @@ void AbstractTexture::bindImages(const Int firstImageUnit, Containers::ArrayView
Containers::Array<GLuint> ids{textures ? textures.size() : 0}; Containers::Array<GLuint> ids{textures ? textures.size() : 0};
bool different = false; bool different = false;
for(std::size_t i = 0; i != textures.size(); ++i) { for(std::size_t i = 0; i != textures.size(); ++i) {
const std::tuple<GLuint, GLint, GLboolean, GLint, GLenum> state = textures && textures[i] ? const Implementation::TextureState::ImageBinding state = textures && textures[i] ?
std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>(textures[i]->_id, 0, true, 0, GL_READ_WRITE) : Implementation::TextureState::ImageBinding{textures[i]->_id, 0, true, 0, GL_READ_WRITE} :
std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>(0, 0, false, 0, GL_READ_ONLY); Implementation::TextureState::ImageBinding{0, 0, false, 0, GL_READ_ONLY};
if(textures) { if(textures) {
if(textures[i]) { if(textures[i]) {
textures[i]->createIfNotAlready(); textures[i]->createIfNotAlready();
} }
ids[i] = std::get<0>(state); ids[i] = state.id;
} }
if(textureState.imageBindings[firstImageUnit + i] != state) { if(textureState.imageBindings[firstImageUnit + i] != state) {
@ -321,7 +320,7 @@ void AbstractTexture::bindImages(const Int firstImageUnit, Containers::ArrayView
void AbstractTexture::bindImageInternal(const Int imageUnit, const Int level, const bool layered, const Int layer, const ImageAccess access, const ImageFormat format) { void AbstractTexture::bindImageInternal(const Int imageUnit, const Int level, const bool layered, const Int layer, const ImageAccess access, const ImageFormat format) {
Implementation::TextureState& textureState = Context::current().state().texture; Implementation::TextureState& textureState = Context::current().state().texture;
const std::tuple<GLuint, GLint, GLboolean, GLint, GLenum> state{_id, level, layered, layer, GLenum(access)}; const Implementation::TextureState::ImageBinding state{_id, level, layered, layer, GLenum(access)};
/* If already bound in given texture unit, nothing to do */ /* If already bound in given texture unit, nothing to do */
if(textureState.imageBindings[imageUnit] == state) return; if(textureState.imageBindings[imageUnit] == state) return;

3
src/Magnum/GL/Implementation/State.cpp

@ -25,7 +25,6 @@
#include "State.h" #include "State.h"
#include <tuple>
#include <Corrade/Containers/ArrayTuple.h> #include <Corrade/Containers/ArrayTuple.h>
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
@ -86,7 +85,7 @@ std::pair<Containers::ArrayTuple, State&> State::allocate(Context& context, std:
Containers::ArrayView<TextureState> textureStateView; Containers::ArrayView<TextureState> textureStateView;
Containers::ArrayView<std::pair<GLenum, GLuint>> textureBindings; Containers::ArrayView<std::pair<GLenum, GLuint>> textureBindings;
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Containers::ArrayView<std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>> imageBindings; Containers::ArrayView<TextureState::ImageBinding> imageBindings;
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
Containers::ArrayView<TransformFeedbackState> transformFeedbackStateView; Containers::ArrayView<TransformFeedbackState> transformFeedbackStateView;

7
src/Magnum/GL/Implementation/TextureState.cpp

@ -25,7 +25,6 @@
#include "TextureState.h" #include "TextureState.h"
#include <tuple>
#include <Corrade/Containers/StringView.h> #include <Corrade/Containers/StringView.h>
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
@ -46,7 +45,7 @@ using namespace Containers::Literals;
TextureState::TextureState(Context& context, TextureState::TextureState(Context& context,
Containers::ArrayView<std::pair<GLenum, GLuint>> bindings, Containers::ArrayView<std::pair<GLenum, GLuint>> bindings,
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Containers::ArrayView<std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>> imageBindings, Containers::ArrayView<ImageBinding> imageBindings,
#endif #endif
Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions): Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions):
maxSize{}, maxSize{},
@ -551,8 +550,8 @@ void TextureState::reset() {
for(std::pair<GLenum, GLuint>& i: bindings) for(std::pair<GLenum, GLuint>& i: bindings)
i = {{}, State::DisengagedBinding}; i = {{}, State::DisengagedBinding};
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
for(std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>& i: imageBindings) for(ImageBinding& i: imageBindings)
i = std::make_tuple(State::DisengagedBinding, 0, false, 0, 0); i = {State::DisengagedBinding, 0, false, 0, 0};
#endif #endif
} }

28
src/Magnum/GL/Implementation/TextureState.h

@ -25,8 +25,8 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <utility> /* std::pair */
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include <Corrade/Utility/StlForwardTuple.h>
#include "Magnum/Magnum.h" #include "Magnum/Magnum.h"
#include "Magnum/GL/GL.h" #include "Magnum/GL/GL.h"
@ -51,10 +51,32 @@
namespace Magnum { namespace GL { namespace Implementation { namespace Magnum { namespace GL { namespace Implementation {
struct TextureState { struct TextureState {
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
struct ImageBinding {
GLuint id;
GLint level;
GLboolean layered;
GLint layer;
GLenum access;
/* Used inside AbstractTexture to check if the state changed */
bool operator==(const ImageBinding& other) {
return other.id == id &&
other.level == level &&
other.layered == layered &&
other.layer == layer &&
other.access == access;
}
bool operator!=(const ImageBinding& other) {
return !operator==(other);
}
};
#endif
explicit TextureState(Context& context, explicit TextureState(Context& context,
Containers::ArrayView<std::pair<GLenum, GLuint>> bindings, Containers::ArrayView<std::pair<GLenum, GLuint>> bindings,
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Containers::ArrayView<std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>> imageBindings, Containers::ArrayView<ImageBinding> imageBindings,
#endif #endif
Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions); Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions);
@ -171,7 +193,7 @@ struct TextureState {
#endif #endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
/* Texture object ID, level, layered, layer, access */ /* Texture object ID, level, layered, layer, access */
Containers::ArrayView<std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>> imageBindings; Containers::ArrayView<ImageBinding> imageBindings;
#endif #endif
}; };

Loading…
Cancel
Save