Browse Source

Added *Texture::unbind().

Will be used in fallback implementation of multi-bind.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
580a723d61
  1. 36
      src/Magnum/AbstractTexture.cpp
  2. 23
      src/Magnum/AbstractTexture.h
  3. 7
      src/Magnum/Implementation/TextureState.cpp
  4. 1
      src/Magnum/Implementation/TextureState.h
  5. 4
      src/Magnum/Test/BufferTextureGLTest.cpp
  6. 4
      src/Magnum/Test/CubeMapTextureArrayGLTest.cpp
  7. 4
      src/Magnum/Test/CubeMapTextureGLTest.cpp
  8. 8
      src/Magnum/Test/MultisampleTextureGLTest.cpp
  9. 4
      src/Magnum/Test/RectangleTextureGLTest.cpp
  10. 8
      src/Magnum/Test/TextureArrayGLTest.cpp
  11. 12
      src/Magnum/Test/TextureGLTest.cpp

36
src/Magnum/AbstractTexture.cpp

@ -91,6 +91,42 @@ Int AbstractTexture::maxIntegerSamples() {
}
#endif
void AbstractTexture::unbind(const Int textureUnit) {
Implementation::TextureState* const textureState = Context::current()->state().texture;
/* If given texture unit is already unbound, nothing to do */
if(textureState->bindings[textureUnit].second == 0) return;
/* Unbind the texture, reset state tracker */
Context::current()->state().texture->unbindImplementation(textureUnit);
textureState->bindings[textureUnit] = {};
}
void AbstractTexture::unbindImplementationDefault(const GLint textureUnit) {
Implementation::TextureState* const textureState = Context::current()->state().texture;
/* Activate given texture unit if not already active, update state tracker */
if(textureState->currentTextureUnit != textureUnit)
glActiveTexture(GL_TEXTURE0 + (textureState->currentTextureUnit = textureUnit));
CORRADE_INTERNAL_ASSERT(textureState->bindings[textureUnit].first != 0);
glBindTexture(textureState->bindings[textureUnit].first, 0);
}
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::unbindImplementationMulti(const GLint textureUnit) {
constexpr static const GLuint zero = 0;
glBindTextures(textureUnit, 1, &zero);
}
void AbstractTexture::unbindImplementationDSA(const GLint textureUnit) {
Implementation::TextureState* const textureState = Context::current()->state().texture;
CORRADE_INTERNAL_ASSERT(textureState->bindings[textureUnit].first != 0);
glBindMultiTextureEXT(GL_TEXTURE0 + textureUnit, textureState->bindings[textureUnit].first, 0);
}
#endif
AbstractTexture::AbstractTexture(GLenum target): _target(target) {
glGenTextures(1, &_id);
}

23
src/Magnum/AbstractTexture.h

@ -157,6 +157,21 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
static Int maxIntegerSamples();
#endif
/**
* @brief Unbind any texture from given texture unit
*
* If @extension{ARB,multi_bind} (part of OpenGL 4.4) or
* @extension{EXT,direct_state_access} is not available, the texture
* unit is made active before binding the texture.
* @note This function is meant to be used only internally from
* @ref AbstractShaderProgram subclasses. See its documentation
* for more information.
* @see @ref bind(), @ref Shader::maxCombinedTextureImageUnits(),
* @fn_gl{ActiveTexture}, @fn_gl{BindTexture}, @fn_gl{BindTextures}
* or @fn_gl_extension{BindMultiTexture,EXT,direct_state_access}
*/
static void unbind(Int textureUnit);
/** @brief Copying is not allowed */
AbstractTexture(const AbstractTexture&) = delete;
@ -215,7 +230,7 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
* @note This function is meant to be used only internally from
* @ref AbstractShaderProgram subclasses. See its documentation
* for more information.
* @see @ref Shader::maxCombinedTextureImageUnits(),
* @see @ref unbind(), @ref Shader::maxCombinedTextureImageUnits(),
* @fn_gl{ActiveTexture}, @fn_gl{BindTexture}, @fn_gl{BindTextures}
* or @fn_gl_extension{BindMultiTexture,EXT,direct_state_access}
*/
@ -254,6 +269,12 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
GLenum _target;
private:
static void MAGNUM_LOCAL unbindImplementationDefault(GLint textureUnit);
#ifndef MAGNUM_TARGET_GLES
static void MAGNUM_LOCAL unbindImplementationMulti(GLint textureUnit);
static void MAGNUM_LOCAL unbindImplementationDSA(GLint textureUnit);
#endif
void MAGNUM_LOCAL bindImplementationDefault(GLint textureUnit);
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL bindImplementationMulti(GLint textureUnit);

7
src/Magnum/Implementation/TextureState.cpp

@ -45,13 +45,20 @@ TextureState::TextureState(Context& context, std::vector<std::string>& extension
#ifndef MAGNUM_TARGET_GLES
if(context.isExtensionSupported<Extensions::GL::ARB::multi_bind>()) {
extensions.push_back(Extensions::GL::ARB::multi_bind::string());
unbindImplementation = &AbstractTexture::unbindImplementationMulti;
bindImplementation = &AbstractTexture::bindImplementationMulti;
} else if(context.isExtensionSupported<Extensions::GL::EXT::direct_state_access>()) {
/* Extension name added below */
unbindImplementation = &AbstractTexture::unbindImplementationDSA;
bindImplementation = &AbstractTexture::bindImplementationDSA;
} else
#endif
{
unbindImplementation = &AbstractTexture::unbindImplementationDefault;
bindImplementation = &AbstractTexture::bindImplementationDefault;
}

1
src/Magnum/Implementation/TextureState.h

@ -37,6 +37,7 @@ struct TextureState {
explicit TextureState(Context& context, std::vector<std::string>& extensions);
~TextureState();
void(*unbindImplementation)(GLint);
void(AbstractTexture::*bindImplementation)(GLint);
void(AbstractTexture::*parameteriImplementation)(GLenum, GLint);
void(AbstractTexture::*parameterfImplementation)(GLenum, GLfloat);

4
src/Magnum/Test/BufferTextureGLTest.cpp

@ -70,6 +70,10 @@ void BufferTextureGLTest::bind() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
void BufferTextureGLTest::setBuffer() {

4
src/Magnum/Test/CubeMapTextureArrayGLTest.cpp

@ -97,6 +97,10 @@ void CubeMapTextureArrayGLTest::bind() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
void CubeMapTextureArrayGLTest::sampling() {

4
src/Magnum/Test/CubeMapTextureGLTest.cpp

@ -117,6 +117,10 @@ void CubeMapTextureGLTest::bind() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
void CubeMapTextureGLTest::sampling() {

8
src/Magnum/Test/MultisampleTextureGLTest.cpp

@ -123,6 +123,10 @@ void MultisampleTextureGLTest::bind2D() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
void MultisampleTextureGLTest::bind2DArray() {
@ -133,6 +137,10 @@ void MultisampleTextureGLTest::bind2DArray() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
void MultisampleTextureGLTest::storage2D() {

4
src/Magnum/Test/RectangleTextureGLTest.cpp

@ -98,6 +98,10 @@ void RectangleTextureGLTest::bind() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
void RectangleTextureGLTest::sampling() {

8
src/Magnum/Test/TextureArrayGLTest.cpp

@ -208,6 +208,10 @@ void TextureArrayGLTest::bind1D() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
#endif
@ -221,6 +225,10 @@ void TextureArrayGLTest::bind2D() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
#ifndef MAGNUM_TARGET_GLES

12
src/Magnum/Test/TextureGLTest.cpp

@ -257,6 +257,10 @@ void TextureGLTest::bind1D() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
#endif
@ -265,6 +269,10 @@ void TextureGLTest::bind2D() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
void TextureGLTest::bind3D() {
@ -277,6 +285,10 @@ void TextureGLTest::bind3D() {
texture.bind(15);
MAGNUM_VERIFY_NO_ERROR();
AbstractTexture::unbind(15);
MAGNUM_VERIFY_NO_ERROR();
}
#ifndef MAGNUM_TARGET_GLES

Loading…
Cancel
Save