From 1c543cd26b360d94796a288d9276ec0bb2390824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Sep 2014 22:15:00 +0200 Subject: [PATCH] ARB_direct_state_access support for creating textures. --- src/Magnum/AbstractTexture.cpp | 16 ++++++++++++++-- src/Magnum/AbstractTexture.h | 5 +++++ src/Magnum/BufferTexture.h | 7 +++++-- src/Magnum/CubeMapTexture.h | 7 +++++-- src/Magnum/CubeMapTextureArray.h | 7 +++++-- src/Magnum/Implementation/TextureState.cpp | 12 ++++++++++++ src/Magnum/Implementation/TextureState.h | 1 + src/Magnum/MultisampleTexture.h | 9 ++++++--- src/Magnum/RectangleTexture.h | 7 +++++-- src/Magnum/Texture.h | 9 ++++++--- src/Magnum/TextureArray.h | 8 +++++--- 11 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/Magnum/AbstractTexture.cpp b/src/Magnum/AbstractTexture.cpp index a563911fc..e6fe1e761 100644 --- a/src/Magnum/AbstractTexture.cpp +++ b/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; diff --git a/src/Magnum/AbstractTexture.h b/src/Magnum/AbstractTexture.h index 247bc6788..6fc7e3db3 100644 --- a/src/Magnum/AbstractTexture.h +++ b/src/Magnum/AbstractTexture.h @@ -379,6 +379,11 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject { static void MAGNUM_LOCAL bindImplementationMulti(GLint firstTextureUnit, Containers::ArrayReference 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); diff --git a/src/Magnum/BufferTexture.h b/src/Magnum/BufferTexture.h index 2ce20a191..79a9f25c0 100644 --- a/src/Magnum/BufferTexture.h +++ b/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) {} diff --git a/src/Magnum/CubeMapTexture.h b/src/Magnum/CubeMapTexture.h index 61a34cff8..a29e42a51 100644 --- a/src/Magnum/CubeMapTexture.h +++ b/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) {} diff --git a/src/Magnum/CubeMapTextureArray.h b/src/Magnum/CubeMapTextureArray.h index e067c98b9..4762af11f 100644 --- a/src/Magnum/CubeMapTextureArray.h +++ b/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) {} diff --git a/src/Magnum/Implementation/TextureState.cpp b/src/Magnum/Implementation/TextureState.cpp index 0e3399229..0edf4ff3d 100644 --- a/src/Magnum/Implementation/TextureState.cpp +++ b/src/Magnum/Implementation/TextureState.cpp @@ -57,6 +57,18 @@ TextureState::TextureState(Context& context, std::vector& extension , bufferOffsetAlignment(0) #endif { + /* Create implementation */ + #ifndef MAGNUM_TARGET_GLES + if(context.isExtensionSupported()) { + 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()) { diff --git a/src/Magnum/Implementation/TextureState.h b/src/Magnum/Implementation/TextureState.h index 79650690a..fbe4988fd 100644 --- a/src/Magnum/Implementation/TextureState.h +++ b/src/Magnum/Implementation/TextureState.h @@ -41,6 +41,7 @@ struct TextureState { void(*unbindImplementation)(GLint); void(*bindMultiImplementation)(GLint, Containers::ArrayReference); + void(AbstractTexture::*createImplementation)(); void(AbstractTexture::*bindImplementation)(GLint); void(AbstractTexture::*parameteriImplementation)(GLenum, GLint); void(AbstractTexture::*parameterfImplementation)(GLenum, GLfloat); diff --git a/src/Magnum/MultisampleTexture.h b/src/Magnum/MultisampleTexture.h index 90cc63268..a22eb4170 100644 --- a/src/Magnum/MultisampleTexture.h +++ b/src/Magnum/MultisampleTexture.h @@ -113,9 +113,12 @@ template 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()) {} diff --git a/src/Magnum/RectangleTexture.h b/src/Magnum/RectangleTexture.h index cf98b51e9..1b61b727b 100644 --- a/src/Magnum/RectangleTexture.h +++ b/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) {} diff --git a/src/Magnum/Texture.h b/src/Magnum/Texture.h index 5df42e37c..736441b76 100644 --- a/src/Magnum/Texture.h +++ b/src/Magnum/Texture.h @@ -159,9 +159,12 @@ template 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()) {} diff --git a/src/Magnum/TextureArray.h b/src/Magnum/TextureArray.h index b4f6b1582..f240deab2 100644 --- a/src/Magnum/TextureArray.h +++ b/src/Magnum/TextureArray.h @@ -110,9 +110,11 @@ template 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()) {}