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

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

@ -26,6 +26,7 @@
#include "State.h" #include "State.h"
#include <Corrade/Containers/ArrayTuple.h> #include <Corrade/Containers/ArrayTuple.h>
#include <Corrade/Containers/Pair.h>
#include <Corrade/Utility/Assert.h> #include <Corrade/Utility/Assert.h>
#include "Magnum/GL/Context.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<ShaderState> shaderStateView;
Containers::ArrayView<ShaderProgramState> shaderProgramStateView; Containers::ArrayView<ShaderProgramState> shaderProgramStateView;
Containers::ArrayView<TextureState> textureStateView; 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) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
Containers::ArrayView<TextureState::ImageBinding> imageBindings; Containers::ArrayView<TextureState::ImageBinding> imageBindings;
#endif #endif

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

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

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

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

Loading…
Cancel
Save