Browse Source

GL: drop std::pair from texture state tracker internals.

Apparently even `= {}` was broken for std::pair once, not to mention the
unnecessary extra overhead with this type not being trivially copyable.
Good riddance.
pull/499/head
Vladimír Vondruš 3 years ago
parent
commit
e0210a1007
  1. 26
      src/Magnum/GL/AbstractTexture.cpp
  2. 4
      src/Magnum/GL/Buffer.cpp
  3. 3
      src/Magnum/GL/Implementation/State.cpp
  4. 4
      src/Magnum/GL/Implementation/TextureState.cpp
  5. 6
      src/Magnum/GL/Implementation/TextureState.h

26
src/Magnum/GL/AbstractTexture.cpp

@ -119,13 +119,11 @@ void AbstractTexture::unbind(const Int textureUnit) {
Implementation::TextureState& textureState = Context::current().state().texture;
/* If given texture unit is already unbound, nothing to do */
if(textureState.bindings[textureUnit].second == 0) return;
if(textureState.bindings[textureUnit].second() == 0) return;
/* Unbind the texture, reset state tracker */
Context::current().state().texture.unbindImplementation(textureUnit);
/* libstdc++ since GCC 6.3 can't handle just = {} (ambiguous overload of
operator=) */
textureState.bindings[textureUnit] = std::pair<GLenum, GLuint>{};
textureState.bindings[textureUnit] = {};
}
void AbstractTexture::unbindImplementationDefault(const GLint textureUnit) {
@ -135,8 +133,8 @@ void AbstractTexture::unbindImplementationDefault(const GLint textureUnit) {
if(textureState.currentTextureUnit != textureUnit)
glActiveTexture(GL_TEXTURE0 + (textureState.currentTextureUnit = textureUnit));
CORRADE_INTERNAL_ASSERT(textureState.bindings[textureUnit].first != 0);
glBindTexture(textureState.bindings[textureUnit].first, 0);
CORRADE_INTERNAL_ASSERT(textureState.bindings[textureUnit].first() != 0);
glBindTexture(textureState.bindings[textureUnit].first(), 0);
}
#ifndef MAGNUM_TARGET_GLES
@ -146,7 +144,7 @@ void AbstractTexture::unbindImplementationMulti(const GLint textureUnit) {
}
void AbstractTexture::unbindImplementationDSA(const GLint textureUnit) {
CORRADE_INTERNAL_ASSERT(Context::current().state().texture.bindings[textureUnit].first != 0);
CORRADE_INTERNAL_ASSERT(Context::current().state().texture.bindings[textureUnit].first() != 0);
glBindTextureUnit(textureUnit, 0);
}
#endif
@ -184,9 +182,9 @@ void AbstractTexture::bindImplementationMulti(const GLint firstTextureUnit, Cont
ids[i] = id;
}
if(textureState.bindings[firstTextureUnit + i].second != id) {
if(textureState.bindings[firstTextureUnit + i].second() != id) {
different = true;
textureState.bindings[firstTextureUnit + i].second = id;
textureState.bindings[firstTextureUnit + i].second() = id;
}
}
@ -235,9 +233,7 @@ AbstractTexture::~AbstractTexture() {
/* Remove all bindings */
for(auto& binding: Context::current().state().texture.bindings) {
/* MSVC 2015 needs the parentheses around */
/* libstdc++ since GCC 6.3 can't handle just = {} (ambiguous overload
of operator=) */
if(binding.second == _id) binding = std::pair<GLenum, GLuint>{};
if(binding.second() == _id) binding = {};
}
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
@ -335,7 +331,7 @@ void AbstractTexture::bind(Int textureUnit) {
Implementation::TextureState& textureState = Context::current().state().texture;
/* If already bound in given texture unit, nothing to do */
if(textureState.bindings[textureUnit].second == _id) return;
if(textureState.bindings[textureUnit].second() == _id) return;
/* Update state tracker, bind the texture to the unit */
textureState.bindings[textureUnit] = {_target, _id};
@ -525,7 +521,7 @@ void AbstractTexture::bindInternal() {
Implementation::TextureState& textureState = Context::current().state().texture;
/* If the texture is already bound in current unit, nothing to do */
if(textureState.bindings[textureState.currentTextureUnit].second == _id)
if(textureState.bindings[textureState.currentTextureUnit].second() == _id)
return;
/* Set internal unit as active if not already, update state tracker */
@ -535,7 +531,7 @@ void AbstractTexture::bindInternal() {
glActiveTexture(GL_TEXTURE0 + (textureState.currentTextureUnit = internalTextureUnit));
/* If already bound in given texture unit, nothing to do */
if(textureState.bindings[internalTextureUnit].second == _id) return;
if(textureState.bindings[internalTextureUnit].second() == _id) return;
/* Update state tracker, bind the texture to the unit. Not directly calling
glBindTexture() here because we may need to include various

4
src/Magnum/GL/Buffer.cpp

@ -603,9 +603,7 @@ void Buffer::textureWorkaroundAppleBefore() {
/* Unbind the texture, reset state tracker */
glBindTexture(GL_TEXTURE_BUFFER, 0);
/* libstdc++ since GCC 6.3 can't handle just = {} (ambiguous overload
of operator=) */
textureState.bindings[textureUnit] = std::pair<GLenum, GLuint>{};
textureState.bindings[textureUnit] = {};
textureState.bufferTextureBound.set(textureUnit, false);
}
}

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

@ -26,6 +26,7 @@
#include "State.h"
#include <Corrade/Containers/ArrayTuple.h>
#include <Corrade/Containers/Pair.h>
#include <Corrade/Utility/Assert.h>
#include "Magnum/GL/Context.h"
@ -83,7 +84,7 @@ std::pair<Containers::ArrayTuple, State&> State::allocate(Context& context, std:
Containers::ArrayView<ShaderState> shaderStateView;
Containers::ArrayView<ShaderProgramState> shaderProgramStateView;
Containers::ArrayView<TextureState> textureStateView;
Containers::ArrayView<std::pair<GLenum, GLuint>> textureBindings;
Containers::ArrayView<Containers::Pair<GLenum, GLuint>> textureBindings;
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Containers::ArrayView<TextureState::ImageBinding> imageBindings;
#endif

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

@ -43,7 +43,7 @@ namespace Magnum { namespace GL { namespace Implementation {
using namespace Containers::Literals;
TextureState::TextureState(Context& context,
Containers::ArrayView<std::pair<GLenum, GLuint>> bindings,
Containers::ArrayView<Containers::Pair<GLenum, GLuint>> bindings,
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Containers::ArrayView<ImageBinding> imageBindings,
#endif
@ -547,7 +547,7 @@ TextureState::TextureState(Context& context,
}
void TextureState::reset() {
for(std::pair<GLenum, GLuint>& i: bindings)
for(Containers::Pair<GLenum, GLuint>& i: bindings)
i = {{}, State::DisengagedBinding};
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
for(ImageBinding& i: imageBindings)

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

@ -25,7 +25,7 @@
DEALINGS IN THE SOFTWARE.
*/
#include <utility> /* std::pair */
#include <Corrade/Containers/Pair.h>
#include <Corrade/Containers/ArrayView.h>
#include "Magnum/Magnum.h"
@ -74,7 +74,7 @@ struct TextureState {
#endif
explicit TextureState(Context& context,
Containers::ArrayView<std::pair<GLenum, GLuint>> bindings,
Containers::ArrayView<Containers::Pair<GLenum, GLuint>> bindings,
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Containers::ArrayView<ImageBinding> imageBindings,
#endif
@ -187,7 +187,7 @@ struct TextureState {
/* Texture type, texture object ID. While not true, for simplicity this
assumes that each slot can have just one ID bound, not one ID per
texture type. */
Containers::ArrayView<std::pair<GLenum, GLuint>> bindings;
Containers::ArrayView<Containers::Pair<GLenum, GLuint>> bindings;
#if defined(CORRADE_TARGET_APPLE) && !defined(MAGNUM_TARGET_GLES)
Math::BitVector<80> bufferTextureBound;
#endif

Loading…
Cancel
Save