@ -172,8 +172,9 @@ void AbstractTexture::bindImplementationMulti(const GLint firstTextureUnit, std:
/* Create array of IDs and also update bindings in state tracker */
/* Create array of IDs and also update bindings in state tracker */
Containers : : Array < GLuint > ids { textures . size ( ) } ;
Containers : : Array < GLuint > ids { textures . size ( ) } ;
Int i { } ;
Int i { } ;
for ( const AbstractTexture * const texture : textures ) {
for ( AbstractTexture * const texture : textures ) {
textureState - > bindings [ firstTextureUnit + i ] . second = ids [ i ] = texture ? texture - > id ( ) : 0 ;
if ( texture ) texture - > createIfNotAlready ( ) ;
textureState - > bindings [ firstTextureUnit + i ] . second = ids [ i ] = texture ? texture - > _id : 0 ;
+ + i ;
+ + i ;
}
}
@ -181,7 +182,7 @@ void AbstractTexture::bindImplementationMulti(const GLint firstTextureUnit, std:
}
}
# endif
# endif
AbstractTexture : : AbstractTexture ( GLenum target ) : _target ( target ) {
AbstractTexture : : AbstractTexture ( GLenum target ) : _target { target } , _created { false } {
glGenTextures ( 1 , & _id ) ;
glGenTextures ( 1 , & _id ) ;
CORRADE_INTERNAL_ASSERT ( _id ! = Implementation : : State : : DisengagedBinding ) ;
CORRADE_INTERNAL_ASSERT ( _id ! = Implementation : : State : : DisengagedBinding ) ;
}
}
@ -197,11 +198,25 @@ AbstractTexture::~AbstractTexture() {
glDeleteTextures ( 1 , & _id ) ;
glDeleteTextures ( 1 , & _id ) ;
}
}
std : : string AbstractTexture : : label ( ) const {
inline void AbstractTexture : : createIfNotAlready ( ) {
if ( _created ) return ;
/* glGen*() does not create the object, just reserves the name. Some
commands ( such as glBindTextures ( ) or glObjectLabel ( ) ) operate with IDs
directly and they require the object to be created . Binding the texture
to desired target finally creates it . Also all EXT DSA functions
implicitly create it . */
bindInternal ( ) ;
CORRADE_INTERNAL_ASSERT ( _created ) ;
}
std : : string AbstractTexture : : label ( ) {
createIfNotAlready ( ) ;
return Context : : current ( ) - > state ( ) . debug - > getLabelImplementation ( GL_TEXTURE , _id ) ;
return Context : : current ( ) - > state ( ) . debug - > getLabelImplementation ( GL_TEXTURE , _id ) ;
}
}
AbstractTexture & AbstractTexture : : setLabelInternal ( const Containers : : ArrayReference < const char > label ) {
AbstractTexture & AbstractTexture : : setLabelInternal ( const Containers : : ArrayReference < const char > label ) {
createIfNotAlready ( ) ;
Context : : current ( ) - > state ( ) . debug - > labelImplementation ( GL_TEXTURE , _id , label ) ;
Context : : current ( ) - > state ( ) . debug - > labelImplementation ( GL_TEXTURE , _id , label ) ;
return * this ;
return * this ;
}
}
@ -224,15 +239,19 @@ void AbstractTexture::bindImplementationDefault(GLint textureUnit) {
if ( textureState - > currentTextureUnit ! = textureUnit )
if ( textureState - > currentTextureUnit ! = textureUnit )
glActiveTexture ( GL_TEXTURE0 + ( textureState - > currentTextureUnit = textureUnit ) ) ;
glActiveTexture ( GL_TEXTURE0 + ( textureState - > currentTextureUnit = textureUnit ) ) ;
/* Binding the texture finally creates it */
_created = true ;
glBindTexture ( _target , _id ) ;
glBindTexture ( _target , _id ) ;
}
}
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : bindImplementationMulti ( GLint textureUnit ) {
void AbstractTexture : : bindImplementationMulti ( GLint textureUnit ) {
createIfNotAlready ( ) ;
glBindTextures ( textureUnit , 1 , & _id ) ;
glBindTextures ( textureUnit , 1 , & _id ) ;
}
}
void AbstractTexture : : bindImplementationDSA ( GLint textureUnit ) {
void AbstractTexture : : bindImplementationDSA ( GLint textureUnit ) {
_created = true ;
glBindMultiTextureEXT ( GL_TEXTURE0 + textureUnit , _target , _id ) ;
glBindMultiTextureEXT ( GL_TEXTURE0 + textureUnit , _target , _id ) ;
}
}
# endif
# endif
@ -359,6 +378,7 @@ void AbstractTexture::mipmapImplementationDefault() {
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : mipmapImplementationDSA ( ) {
void AbstractTexture : : mipmapImplementationDSA ( ) {
_created = true ;
glGenerateTextureMipmapEXT ( _id , _target ) ;
glGenerateTextureMipmapEXT ( _id , _target ) ;
}
}
# endif
# endif
@ -383,6 +403,9 @@ void AbstractTexture::bindInternal() {
/* Bind the texture to internal unit if not already, update state tracker */
/* Bind the texture to internal unit if not already, update state tracker */
if ( textureState - > bindings [ internalTextureUnit ] . second = = _id ) return ;
if ( textureState - > bindings [ internalTextureUnit ] . second = = _id ) return ;
textureState - > bindings [ internalTextureUnit ] = { _target , _id } ;
textureState - > bindings [ internalTextureUnit ] = { _target , _id } ;
/* Binding the texture finally creates it */
_created = true ;
glBindTexture ( _target , _id ) ;
glBindTexture ( _target , _id ) ;
}
}
@ -764,6 +787,7 @@ void AbstractTexture::parameterImplementationDefault(GLenum parameter, GLint val
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : parameterImplementationDSA ( GLenum parameter , GLint value ) {
void AbstractTexture : : parameterImplementationDSA ( GLenum parameter , GLint value ) {
_created = true ;
glTextureParameteriEXT ( _id , _target , parameter , value ) ;
glTextureParameteriEXT ( _id , _target , parameter , value ) ;
}
}
# endif
# endif
@ -775,6 +799,7 @@ void AbstractTexture::parameterImplementationDefault(GLenum parameter, GLfloat v
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : parameterImplementationDSA ( GLenum parameter , GLfloat value ) {
void AbstractTexture : : parameterImplementationDSA ( GLenum parameter , GLfloat value ) {
_created = true ;
glTextureParameterfEXT ( _id , _target , parameter , value ) ;
glTextureParameterfEXT ( _id , _target , parameter , value ) ;
}
}
# endif
# endif
@ -787,6 +812,7 @@ void AbstractTexture::parameterImplementationDefault(GLenum parameter, const GLi
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : parameterImplementationDSA ( GLenum parameter , const GLint * values ) {
void AbstractTexture : : parameterImplementationDSA ( GLenum parameter , const GLint * values ) {
_created = true ;
glTextureParameterivEXT ( _id , _target , parameter , values ) ;
glTextureParameterivEXT ( _id , _target , parameter , values ) ;
}
}
# endif
# endif
@ -799,6 +825,7 @@ void AbstractTexture::parameterImplementationDefault(GLenum parameter, const GLf
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : parameterImplementationDSA ( GLenum parameter , const GLfloat * values ) {
void AbstractTexture : : parameterImplementationDSA ( GLenum parameter , const GLfloat * values ) {
_created = true ;
glTextureParameterfvEXT ( _id , _target , parameter , values ) ;
glTextureParameterfvEXT ( _id , _target , parameter , values ) ;
}
}
# endif
# endif
@ -810,6 +837,7 @@ void AbstractTexture::parameterIImplementationDefault(GLenum parameter, const GL
}
}
void AbstractTexture : : parameterIImplementationDSA ( GLenum parameter , const GLuint * values ) {
void AbstractTexture : : parameterIImplementationDSA ( GLenum parameter , const GLuint * values ) {
_created = true ;
glTextureParameterIuivEXT ( _id , _target , parameter , values ) ;
glTextureParameterIuivEXT ( _id , _target , parameter , values ) ;
}
}
@ -819,6 +847,7 @@ void AbstractTexture::parameterIImplementationDefault(GLenum parameter, const GL
}
}
void AbstractTexture : : parameterIImplementationDSA ( GLenum parameter , const GLint * values ) {
void AbstractTexture : : parameterIImplementationDSA ( GLenum parameter , const GLint * values ) {
_created = true ;
glTextureParameterIivEXT ( _id , _target , parameter , values ) ;
glTextureParameterIivEXT ( _id , _target , parameter , values ) ;
}
}
# endif
# endif
@ -837,6 +866,7 @@ void AbstractTexture::getLevelParameterImplementationDefault(GLenum target, GLin
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : getLevelParameterImplementationDSA ( GLenum target , GLint level , GLenum parameter , GLint * values ) {
void AbstractTexture : : getLevelParameterImplementationDSA ( GLenum target , GLint level , GLenum parameter , GLint * values ) {
_created = true ;
glGetTextureLevelParameterivEXT ( _id , target , level , parameter , values ) ;
glGetTextureLevelParameterivEXT ( _id , target , level , parameter , values ) ;
}
}
# endif
# endif
@ -860,6 +890,7 @@ void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels
}
}
void AbstractTexture : : storageImplementationDSA ( GLenum target , GLsizei levels , TextureFormat internalFormat , const Math : : Vector < 1 , GLsizei > & size ) {
void AbstractTexture : : storageImplementationDSA ( GLenum target , GLsizei levels , TextureFormat internalFormat , const Math : : Vector < 1 , GLsizei > & size ) {
_created = true ;
glTextureStorage1DEXT ( _id , target , levels , GLenum ( internalFormat ) , size [ 0 ] ) ;
glTextureStorage1DEXT ( _id , target , levels , GLenum ( internalFormat ) , size [ 0 ] ) ;
}
}
# endif
# endif
@ -920,6 +951,7 @@ void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : storageImplementationDSA ( GLenum target , GLsizei levels , TextureFormat internalFormat , const Vector2i & size ) {
void AbstractTexture : : storageImplementationDSA ( GLenum target , GLsizei levels , TextureFormat internalFormat , const Vector2i & size ) {
_created = true ;
glTextureStorage2DEXT ( _id , target , levels , GLenum ( internalFormat ) , size . x ( ) , size . y ( ) ) ;
glTextureStorage2DEXT ( _id , target , levels , GLenum ( internalFormat ) , size . x ( ) , size . y ( ) ) ;
}
}
# endif
# endif
@ -974,6 +1006,7 @@ void AbstractTexture::storageImplementationDefault(GLenum target, GLsizei levels
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : storageImplementationDSA ( GLenum target , GLsizei levels , TextureFormat internalFormat , const Vector3i & size ) {
void AbstractTexture : : storageImplementationDSA ( GLenum target , GLsizei levels , TextureFormat internalFormat , const Vector3i & size ) {
_created = true ;
glTextureStorage3DEXT ( _id , target , levels , GLenum ( internalFormat ) , size . x ( ) , size . y ( ) , size . z ( ) ) ;
glTextureStorage3DEXT ( _id , target , levels , GLenum ( internalFormat ) , size . x ( ) , size . y ( ) , size . z ( ) ) ;
}
}
# endif
# endif
@ -994,6 +1027,7 @@ void AbstractTexture::storageMultisampleImplementationDefault(const GLenum targe
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : storageMultisampleImplementationDSA ( const GLenum target , const GLsizei samples , const TextureFormat internalFormat , const Vector2i & size , const GLboolean fixedSampleLocations ) {
void AbstractTexture : : storageMultisampleImplementationDSA ( const GLenum target , const GLsizei samples , const TextureFormat internalFormat , const Vector2i & size , const GLboolean fixedSampleLocations ) {
_created = true ;
glTextureStorage2DMultisampleEXT ( _id , target , samples , GLenum ( internalFormat ) , size . x ( ) , size . y ( ) , fixedSampleLocations ) ;
glTextureStorage2DMultisampleEXT ( _id , target , samples , GLenum ( internalFormat ) , size . x ( ) , size . y ( ) , fixedSampleLocations ) ;
}
}
@ -1008,6 +1042,7 @@ void AbstractTexture::storageMultisampleImplementationDefault(const GLenum targe
}
}
void AbstractTexture : : storageMultisampleImplementationDSA ( const GLenum target , const GLsizei samples , const TextureFormat internalFormat , const Vector3i & size , const GLboolean fixedSampleLocations ) {
void AbstractTexture : : storageMultisampleImplementationDSA ( const GLenum target , const GLsizei samples , const TextureFormat internalFormat , const Vector3i & size , const GLboolean fixedSampleLocations ) {
_created = true ;
glTextureStorage3DMultisampleEXT ( _id , target , samples , GLenum ( internalFormat ) , size . x ( ) , size . y ( ) , size . z ( ) , fixedSampleLocations ) ;
glTextureStorage3DMultisampleEXT ( _id , target , samples , GLenum ( internalFormat ) , size . x ( ) , size . y ( ) , size . z ( ) , fixedSampleLocations ) ;
}
}
# endif
# endif
@ -1019,6 +1054,7 @@ void AbstractTexture::getImageImplementationDefault(const GLenum target, const G
}
}
void AbstractTexture : : getImageImplementationDSA ( const GLenum target , const GLint level , const ColorFormat format , const ColorType type , const std : : size_t , GLvoid * const data ) {
void AbstractTexture : : getImageImplementationDSA ( const GLenum target , const GLint level , const ColorFormat format , const ColorType type , const std : : size_t , GLvoid * const data ) {
_created = true ;
glGetTextureImageEXT ( _id , target , level , GLenum ( format ) , GLenum ( type ) , data ) ;
glGetTextureImageEXT ( _id , target , level , GLenum ( format ) , GLenum ( type ) , data ) ;
}
}
@ -1035,6 +1071,7 @@ void AbstractTexture::imageImplementationDefault(GLenum target, GLint level, Tex
}
}
void AbstractTexture : : imageImplementationDSA ( GLenum target , GLint level , TextureFormat internalFormat , const Math : : Vector < 1 , GLsizei > & size , ColorFormat format , ColorType type , const GLvoid * data ) {
void AbstractTexture : : imageImplementationDSA ( GLenum target , GLint level , TextureFormat internalFormat , const Math : : Vector < 1 , GLsizei > & size , ColorFormat format , ColorType type , const GLvoid * data ) {
_created = true ;
glTextureImage1DEXT ( _id , target , level , GLint ( internalFormat ) , size [ 0 ] , 0 , GLenum ( format ) , GLenum ( type ) , data ) ;
glTextureImage1DEXT ( _id , target , level , GLint ( internalFormat ) , size [ 0 ] , 0 , GLenum ( format ) , GLenum ( type ) , data ) ;
}
}
# endif
# endif
@ -1046,6 +1083,7 @@ void AbstractTexture::imageImplementationDefault(GLenum target, GLint level, Tex
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : imageImplementationDSA ( GLenum target , GLint level , TextureFormat internalFormat , const Vector2i & size , ColorFormat format , ColorType type , const GLvoid * data ) {
void AbstractTexture : : imageImplementationDSA ( GLenum target , GLint level , TextureFormat internalFormat , const Vector2i & size , ColorFormat format , ColorType type , const GLvoid * data ) {
_created = true ;
glTextureImage2DEXT ( _id , target , level , GLint ( internalFormat ) , size . x ( ) , size . y ( ) , 0 , GLenum ( format ) , GLenum ( type ) , data ) ;
glTextureImage2DEXT ( _id , target , level , GLint ( internalFormat ) , size . x ( ) , size . y ( ) , 0 , GLenum ( format ) , GLenum ( type ) , data ) ;
}
}
# endif
# endif
@ -1070,6 +1108,7 @@ void AbstractTexture::imageImplementationDefault(GLenum target, GLint level, Tex
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : imageImplementationDSA ( GLenum target , GLint level , TextureFormat internalFormat , const Vector3i & size , ColorFormat format , ColorType type , const GLvoid * data ) {
void AbstractTexture : : imageImplementationDSA ( GLenum target , GLint level , TextureFormat internalFormat , const Vector3i & size , ColorFormat format , ColorType type , const GLvoid * data ) {
_created = true ;
glTextureImage3DEXT ( _id , target , level , GLint ( internalFormat ) , size . x ( ) , size . y ( ) , size . z ( ) , 0 , GLenum ( format ) , GLenum ( type ) , data ) ;
glTextureImage3DEXT ( _id , target , level , GLint ( internalFormat ) , size . x ( ) , size . y ( ) , size . z ( ) , 0 , GLenum ( format ) , GLenum ( type ) , data ) ;
}
}
# endif
# endif
@ -1081,6 +1120,7 @@ void AbstractTexture::subImageImplementationDefault(GLenum target, GLint level,
}
}
void AbstractTexture : : subImageImplementationDSA ( GLenum target , GLint level , const Math : : Vector < 1 , GLint > & offset , const Math : : Vector < 1 , GLsizei > & size , ColorFormat format , ColorType type , const GLvoid * data ) {
void AbstractTexture : : subImageImplementationDSA ( GLenum target , GLint level , const Math : : Vector < 1 , GLint > & offset , const Math : : Vector < 1 , GLsizei > & size , ColorFormat format , ColorType type , const GLvoid * data ) {
_created = true ;
glTextureSubImage1DEXT ( _id , target , level , offset [ 0 ] , size [ 0 ] , GLenum ( format ) , GLenum ( type ) , data ) ;
glTextureSubImage1DEXT ( _id , target , level , offset [ 0 ] , size [ 0 ] , GLenum ( format ) , GLenum ( type ) , data ) ;
}
}
# endif
# endif
@ -1092,6 +1132,7 @@ void AbstractTexture::subImageImplementationDefault(GLenum target, GLint level,
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : subImageImplementationDSA ( GLenum target , GLint level , const Vector2i & offset , const Vector2i & size , ColorFormat format , ColorType type , const GLvoid * data ) {
void AbstractTexture : : subImageImplementationDSA ( GLenum target , GLint level , const Vector2i & offset , const Vector2i & size , ColorFormat format , ColorType type , const GLvoid * data ) {
_created = true ;
glTextureSubImage2DEXT ( _id , target , level , offset . x ( ) , offset . y ( ) , size . x ( ) , size . y ( ) , GLenum ( format ) , GLenum ( type ) , data ) ;
glTextureSubImage2DEXT ( _id , target , level , offset . x ( ) , offset . y ( ) , size . x ( ) , size . y ( ) , GLenum ( format ) , GLenum ( type ) , data ) ;
}
}
# endif
# endif
@ -1116,6 +1157,7 @@ void AbstractTexture::subImageImplementationDefault(GLenum target, GLint level,
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : subImageImplementationDSA ( GLenum target , GLint level , const Vector3i & offset , const Vector3i & size , ColorFormat format , ColorType type , const GLvoid * data ) {
void AbstractTexture : : subImageImplementationDSA ( GLenum target , GLint level , const Vector3i & offset , const Vector3i & size , ColorFormat format , ColorType type , const GLvoid * data ) {
_created = true ;
glTextureSubImage3DEXT ( _id , target , level , offset . x ( ) , offset . y ( ) , offset . z ( ) , size . x ( ) , size . y ( ) , size . z ( ) , GLenum ( format ) , GLenum ( type ) , data ) ;
glTextureSubImage3DEXT ( _id , target , level , offset . x ( ) , offset . y ( ) , offset . z ( ) , size . x ( ) , size . y ( ) , size . z ( ) , GLenum ( format ) , GLenum ( type ) , data ) ;
}
}
# endif
# endif
@ -1124,6 +1166,7 @@ void AbstractTexture::invalidateImageImplementationNoOp(GLint) {}
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : invalidateImageImplementationARB ( GLint level ) {
void AbstractTexture : : invalidateImageImplementationARB ( GLint level ) {
createIfNotAlready ( ) ;
glInvalidateTexImage ( _id , level ) ;
glInvalidateTexImage ( _id , level ) ;
}
}
# endif
# endif
@ -1132,6 +1175,7 @@ void AbstractTexture::invalidateSubImageImplementationNoOp(GLint, const Vector3i
# ifndef MAGNUM_TARGET_GLES
# ifndef MAGNUM_TARGET_GLES
void AbstractTexture : : invalidateSubImageImplementationARB ( GLint level , const Vector3i & offset , const Vector3i & size ) {
void AbstractTexture : : invalidateSubImageImplementationARB ( GLint level , const Vector3i & offset , const Vector3i & size ) {
createIfNotAlready ( ) ;
glInvalidateTexSubImage ( _id , level , offset . x ( ) , offset . y ( ) , offset . z ( ) , size . x ( ) , size . y ( ) , size . z ( ) ) ;
glInvalidateTexSubImage ( _id , level , offset . x ( ) , offset . y ( ) , offset . z ( ) , size . x ( ) , size . y ( ) , size . z ( ) ) ;
}
}
# endif
# endif