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 <tuple>
#include <Corrade/Containers/Array.h>
#ifndef MAGNUM_TARGET_WEBGL
#include <Corrade/Containers/String.h>
@ -245,7 +244,7 @@ AbstractTexture::~AbstractTexture() {
/* Remove all image bindings */
for(auto& binding: Context::current().state().texture.imageBindings) {
/* MSVC 2015 needs the parentheses around */
if(std::get<0>(binding) == _id) binding = {};
if(binding.id == _id) binding = {};
}
#endif
@ -281,10 +280,10 @@ void AbstractTexture::unbindImage(const Int imageUnit) {
Implementation::TextureState& textureState = Context::current().state().texture;
/* 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 */
std::get<0>(textureState.imageBindings[imageUnit]) = 0;
textureState.imageBindings[imageUnit].id = 0;
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};
bool different = false;
for(std::size_t i = 0; i != textures.size(); ++i) {
const std::tuple<GLuint, GLint, GLboolean, GLint, GLenum> state = textures && textures[i] ?
std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>(textures[i]->_id, 0, true, 0, GL_READ_WRITE) :
std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>(0, 0, false, 0, GL_READ_ONLY);
const Implementation::TextureState::ImageBinding state = textures && textures[i] ?
Implementation::TextureState::ImageBinding{textures[i]->_id, 0, true, 0, GL_READ_WRITE} :
Implementation::TextureState::ImageBinding{0, 0, false, 0, GL_READ_ONLY};
if(textures) {
if(textures[i]) {
textures[i]->createIfNotAlready();
}
ids[i] = std::get<0>(state);
ids[i] = state.id;
}
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) {
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(textureState.imageBindings[imageUnit] == state) return;

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

@ -25,7 +25,6 @@
#include "State.h"
#include <tuple>
#include <Corrade/Containers/ArrayTuple.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<std::pair<GLenum, GLuint>> textureBindings;
#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
#ifndef MAGNUM_TARGET_GLES2
Containers::ArrayView<TransformFeedbackState> transformFeedbackStateView;

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

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

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

@ -25,8 +25,8 @@
DEALINGS IN THE SOFTWARE.
*/
#include <utility> /* std::pair */
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Utility/StlForwardTuple.h>
#include "Magnum/Magnum.h"
#include "Magnum/GL/GL.h"
@ -51,10 +51,32 @@
namespace Magnum { namespace GL { namespace Implementation {
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,
Containers::ArrayView<std::pair<GLenum, GLuint>> bindings,
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Containers::ArrayView<std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>> imageBindings,
Containers::ArrayView<ImageBinding> imageBindings,
#endif
Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions);
@ -171,7 +193,7 @@ struct TextureState {
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
/* Texture object ID, level, layered, layer, access */
Containers::ArrayView<std::tuple<GLuint, GLint, GLboolean, GLint, GLenum>> imageBindings;
Containers::ArrayView<ImageBinding> imageBindings;
#endif
};

Loading…
Cancel
Save