Browse Source

ARB_direct_state_access support for creating textures.

pull/69/head
Vladimír Vondruš 12 years ago
parent
commit
1c543cd26b
  1. 16
      src/Magnum/AbstractTexture.cpp
  2. 5
      src/Magnum/AbstractTexture.h
  3. 7
      src/Magnum/BufferTexture.h
  4. 7
      src/Magnum/CubeMapTexture.h
  5. 7
      src/Magnum/CubeMapTextureArray.h
  6. 12
      src/Magnum/Implementation/TextureState.cpp
  7. 1
      src/Magnum/Implementation/TextureState.h
  8. 9
      src/Magnum/MultisampleTexture.h
  9. 7
      src/Magnum/RectangleTexture.h
  10. 9
      src/Magnum/Texture.h
  11. 8
      src/Magnum/TextureArray.h

16
src/Magnum/AbstractTexture.cpp

@ -193,11 +193,23 @@ void AbstractTexture::bindImplementationMulti(const GLint firstTextureUnit, cons
}
#endif
AbstractTexture::AbstractTexture(GLenum target): _target{target}, _created{false} {
glGenTextures(1, &_id);
AbstractTexture::AbstractTexture(GLenum target): _target{target} {
(this->*Context::current()->state().texture->createImplementation)();
CORRADE_INTERNAL_ASSERT(_id != Implementation::State::DisengagedBinding);
}
void AbstractTexture::createImplementationDefault() {
glGenTextures(1, &_id);
_created = false;
}
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::createImplementationDSA() {
glCreateTextures(_target, 1, &_id);
_created = true;
}
#endif
AbstractTexture::~AbstractTexture() {
/* Moved out, nothing to do */
if(!_id) return;

5
src/Magnum/AbstractTexture.h

@ -379,6 +379,11 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
static void MAGNUM_LOCAL bindImplementationMulti(GLint firstTextureUnit, Containers::ArrayReference<AbstractTexture* const> textures);
#endif
void MAGNUM_LOCAL createImplementationDefault();
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL createImplementationDSA();
#endif
void MAGNUM_LOCAL createIfNotAlready();
void MAGNUM_LOCAL bindImplementationDefault(GLint textureUnit);

7
src/Magnum/BufferTexture.h

@ -225,8 +225,11 @@ class MAGNUM_EXPORT BufferTexture: public AbstractTexture {
/**
* @brief Constructor
*
* Creates new OpenGL texture object.
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_BUFFER}
* Creates new OpenGL texture object. If @extension{ARB,direct_state_access}
* (part of OpenGL 4.5) is not supported, the texture is created on
* first use.
* @see @fn_gl{CreateTextures} with @def_gl{TEXTURE_BUFFER}, eventually
* @fn_gl{GenTextures}
*/
explicit BufferTexture(): AbstractTexture(GL_TEXTURE_BUFFER) {}

7
src/Magnum/CubeMapTexture.h

@ -103,8 +103,11 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture {
/**
* @brief Constructor
*
* Creates new OpenGL texture object.
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_CUBE_MAP}
* Creates new OpenGL texture object. If @extension{ARB,direct_state_access}
* (part of OpenGL 4.5) is not supported, the texture is created on
* first use.
* @see @fn_gl{CreateTextures} with @def_gl{TEXTURE_CUBE_MAP},
* eventually @fn_gl{GenTextures}
*/
explicit CubeMapTexture(): AbstractTexture(GL_TEXTURE_CUBE_MAP) {}

7
src/Magnum/CubeMapTextureArray.h

@ -87,8 +87,11 @@ class CubeMapTextureArray: public AbstractTexture {
/**
* @brief Constructor
*
* Creates new OpenGL texture object.
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_CUBE_MAP_ARRAY}
* Creates new OpenGL texture object. If @extension{ARB,direct_state_access}
* (part of OpenGL 4.5) is not supported, the texture is created on
* first use.
* @see @fn_gl{CreateTextures} with @def_gl{TEXTURE_CUBE_MAP_ARRAY},
* eventually @fn_gl{GenTextures}
*/
explicit CubeMapTextureArray(): AbstractTexture(GL_TEXTURE_CUBE_MAP_ARRAY) {}

12
src/Magnum/Implementation/TextureState.cpp

@ -57,6 +57,18 @@ TextureState::TextureState(Context& context, std::vector<std::string>& extension
, bufferOffsetAlignment(0)
#endif
{
/* Create implementation */
#ifndef MAGNUM_TARGET_GLES
if(context.isExtensionSupported<Extensions::GL::ARB::direct_state_access>()) {
extensions.push_back(Extensions::GL::ARB::direct_state_access::string());
createImplementation = &AbstractTexture::createImplementationDSA;
} else
#endif
{
createImplementation = &AbstractTexture::createImplementationDefault;
}
/* Bind implementation */
#ifndef MAGNUM_TARGET_GLES
if(context.isExtensionSupported<Extensions::GL::ARB::multi_bind>()) {

1
src/Magnum/Implementation/TextureState.h

@ -41,6 +41,7 @@ struct TextureState {
void(*unbindImplementation)(GLint);
void(*bindMultiImplementation)(GLint, Containers::ArrayReference<AbstractTexture* const>);
void(AbstractTexture::*createImplementation)();
void(AbstractTexture::*bindImplementation)(GLint);
void(AbstractTexture::*parameteriImplementation)(GLenum, GLint);
void(AbstractTexture::*parameterfImplementation)(GLenum, GLfloat);

9
src/Magnum/MultisampleTexture.h

@ -113,9 +113,12 @@ template<UnsignedInt dimensions> class MultisampleTexture: public AbstractTextur
/**
* @brief Constructor
*
* Creates new OpenGL texture object.
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_2D_MULTISAMPLE} or
* @def_gl{TEXTURE_2D_MULTISAMPLE_ARRAY}
* Creates new OpenGL texture object. If @extension{ARB,direct_state_access}
* (part of OpenGL 4.5) is not supported, the texture is created on
* first use.
* @see @fn_gl{CreateTextures} with @def_gl{TEXTURE_2D_MULTISAMPLE} or
* @def_gl{TEXTURE_2D_MULTISAMPLE_ARRAY}, eventually
* @fn_gl{GenTextures}
*/
explicit MultisampleTexture(): AbstractTexture(Implementation::multisampleTextureTarget<dimensions>()) {}

7
src/Magnum/RectangleTexture.h

@ -83,8 +83,11 @@ class MAGNUM_EXPORT RectangleTexture: public AbstractTexture {
/**
* @brief Constructor
*
* Creates new OpenGL texture object.
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_RECTANGLE}
* Creates new OpenGL texture object. If @extension{ARB,direct_state_access}
* (part of OpenGL 4.5) is not supported, the texture is created on
* first use.
* @see @fn_gl{CreateTextures} with @def_gl{TEXTURE_RECTANGLE},
* eventually @fn_gl{GenTextures}
*/
explicit RectangleTexture(): AbstractTexture(GL_TEXTURE_RECTANGLE) {}

9
src/Magnum/Texture.h

@ -159,9 +159,12 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
/**
* @brief Constructor
*
* Creates new OpenGL texture object.
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_1D}, @def_gl{TEXTURE_2D}
* or @def_gl{TEXTURE_3D}
* Creates new OpenGL texture object. If @extension{ARB,direct_state_access}
* (part of OpenGL 4.5) is not supported, the texture is created on
* first use.
* @see @fn_gl{CreateTextures} with @def_gl{TEXTURE_1D},
* @def_gl{TEXTURE_2D} or @def_gl{TEXTURE_3D}, eventually
* @fn_gl{GenTextures}
*/
explicit Texture(): AbstractTexture(Implementation::textureTarget<dimensions>()) {}

8
src/Magnum/TextureArray.h

@ -110,9 +110,11 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
/**
* @brief Constructor
*
* Creates new OpenGL texture object.
* @see @fn_gl{GenTextures} with @def_gl{TEXTURE_1D_ARRAY} or
* @def_gl{TEXTURE_2D_ARRAY}
* Creates new OpenGL texture object. If @extension{ARB,direct_state_access}
* (part of OpenGL 4.5) is not supported, the texture is created on
* first use.
* @see @fn_gl{CreateTextures} with @def_gl{TEXTURE_1D_ARRAY} or
* @def_gl{TEXTURE_2D_ARRAY}, eventually @fn_gl{GenTextures}
*/
explicit TextureArray(): AbstractTexture(Implementation::textureArrayTarget<dimensions>()) {}

Loading…
Cancel
Save