From c6b5aba2497009502edc5d9b17964aff2b33e26d Mon Sep 17 00:00:00 2001 From: mp3butcher Date: Thu, 8 Feb 2018 23:35:43 +0100 Subject: [PATCH 1/2] regroup and add missing funcs related to immutable texture storage --- include/osg/GLExtensions | 14 +++++++++++--- src/osg/GLExtensions.cpp | 36 +++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index ddc6cdb8d..2b8d702f7 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -538,7 +538,17 @@ class OSG_EXPORT GLExtensions : public osg::Referenced isNonPowerOfTwoTextureMipMappedSupported; } - void (GL_APIENTRY * glTexStorage2D) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); + ///immutable texture storage and texture view + void (GL_APIENTRY * glTexStorage1D) (GLenum target, GLsizei numMipmapLevels, GLenum internalformat, GLsizei width); + void (GL_APIENTRY * glTextureStorage1D) (GLuint texture, GLsizei numMipmapLevels, GLenum internalformat, GLsizei width); + void (GL_APIENTRY * glTexStorage2D) (GLenum target, GLsizei numMipmapLevels, GLenum internalformat, GLsizei width, GLsizei height); + void (GL_APIENTRY * glTextureStorage2D) (GLuint texture, GLsizei numMipmapLevels, GLenum internalformat, GLsizei width, GLsizei height); + void (GL_APIENTRY * glTexStorage3D) ( GLenum target, GLsizei numMipmapLevels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); + void (GL_APIENTRY * glTextureStorage3D) ( GLuint texture, GLsizei numMipmapLevels,GLenum internalformat,GLsizei width,GLsizei height,GLsizei depth); + void (GL_APIENTRY * glTexStorage2DMultisample) ( GLenum target, GLsizei numSamples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); + void (GL_APIENTRY * glTexStorage3DMultisample) ( GLenum target, GLsizei numSamples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); + void (GL_APIENTRY * glTextureView) ( GLuint texture, GLenum target, GLuint orig, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); + void (GL_APIENTRY * glCompressedTexImage2D) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); void (GL_APIENTRY * glCompressedTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data); void (GL_APIENTRY * glGetCompressedTexImage) (GLenum target, GLint level, GLvoid *data); @@ -557,8 +567,6 @@ class OSG_EXPORT GLExtensions : public osg::Referenced void (GL_APIENTRY * glTexImage3D) ( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); void (GL_APIENTRY * glTexSubImage3D) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); - void (GL_APIENTRY * glTexStorage3D) ( GLenum target, GLsizei numMipmapLevels,GLenum sizedInternalFormat,GLsizei width,GLsizei height,GLsizei depth); - void (GL_APIENTRY * glTextureStorage3D) ( GLuint texture, GLsizei numMipmapLevels,GLenum sizedInternalFormat,GLsizei width,GLsizei height,GLsizei depth); void (GL_APIENTRY * glCopyTexSubImage3D) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); void (GL_APIENTRY * glCompressedTexImage3D) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data); diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index 345b0fb3a..8aeef336c 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -913,18 +913,6 @@ GLExtensions::GLExtensions(unsigned int in_contextID): { maxTextureSize = osg_max_size; } - - setGLExtensionFuncPtr(glTexStorage2D,"glTexStorage2D","glTexStorage2DARB", validContext); - setGLExtensionFuncPtr(glCompressedTexImage2D,"glCompressedTexImage2D","glCompressedTexImage2DARB", validContext); - setGLExtensionFuncPtr(glCompressedTexSubImage2D,"glCompressedTexSubImage2D","glCompressedTexSubImage2DARB", validContext); - setGLExtensionFuncPtr(glGetCompressedTexImage,"glGetCompressedTexImage","glGetCompressedTexImageARB", validContext);; - setGLExtensionFuncPtr(glTexImage2DMultisample, "glTexImage2DMultisample", "glTexImage2DMultisampleARB", validContext); - - setGLExtensionFuncPtr(glTexParameterIiv, "glTexParameterIiv", "glTexParameterIivARB", "glTexParameterIivEXT", validContext); - setGLExtensionFuncPtr(glTexParameterIuiv, "glTexParameterIuiv", "glTexParameterIuivARB", "glTexParameterIuivEXT", validContext); - - setGLExtensionFuncPtr(glBindImageTexture, "glBindImageTexture", "glBindImageTextureARB", validContext); - isTextureMaxLevelSupported = (glVersion >= 1.2f); isTextureStorageEnabled = validContext && ((glVersion >= 4.2f) || isGLExtensionSupported(contextID, "GL_ARB_texture_storage")); @@ -939,6 +927,27 @@ GLExtensions::GLExtensions(unsigned int in_contextID): } } + setGLExtensionFuncPtr(glTexStorage1D,"glTexStorage1D","glTexStorage1DARB", validContext); + setGLExtensionFuncPtr(glTextureStorage1D,"glTextureStorage1D","glTextureStorage1DARB", validContext); + setGLExtensionFuncPtr(glTexStorage2D,"glTexStorage2D","glTexStorage2DARB", validContext); + setGLExtensionFuncPtr(glTextureStorage2D,"glTextureStorage2D","glTextureStorage2DARB", validContext); + setGLExtensionFuncPtr(glTexStorage3D, "glTexStorage3D","glTexStorage3DEXT", validContext); + setGLExtensionFuncPtr(glTextureStorage3D, "glTextureStorage3D","glTextureStorage3DEXT", validContext); + setGLExtensionFuncPtr(glTexStorage2DMultisample, "glTextureStorage2DMultisample","glTextureStorage2DMultisampleEXT", validContext); + setGLExtensionFuncPtr(glTexStorage3DMultisample, "glTextureStorage3DMultisample","glTextureStorage3DMultisampleEXT", validContext); + setGLExtensionFuncPtr(glTextureView, "glTextureView","glTextureViewEXT", validContext); + + setGLExtensionFuncPtr(glCompressedTexImage2D,"glCompressedTexImage2D","glCompressedTexImage2DARB", validContext); + setGLExtensionFuncPtr(glCompressedTexSubImage2D,"glCompressedTexSubImage2D","glCompressedTexSubImage2DARB", validContext); + setGLExtensionFuncPtr(glGetCompressedTexImage,"glGetCompressedTexImage","glGetCompressedTexImageARB", validContext);; + setGLExtensionFuncPtr(glTexImage2DMultisample, "glTexImage2DMultisample", "glTexImage2DMultisampleARB", validContext); + + setGLExtensionFuncPtr(glTexParameterIiv, "glTexParameterIiv", "glTexParameterIivARB", "glTexParameterIivEXT", validContext); + setGLExtensionFuncPtr(glTexParameterIuiv, "glTexParameterIuiv", "glTexParameterIuivARB", "glTexParameterIuivEXT", validContext); + + setGLExtensionFuncPtr(glBindImageTexture, "glBindImageTexture", "glBindImageTextureARB", validContext); + + // Texture3D extensions isTexture3DFast = validContext && (OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture3D")); @@ -950,8 +959,6 @@ GLExtensions::GLExtensions(unsigned int in_contextID): setGLExtensionFuncPtr(glTexImage3D, "glTexImage3D","glTexImage3DEXT", validContext); setGLExtensionFuncPtr(glTexSubImage3D, "glTexSubImage3D","glTexSubImage3DEXT", validContext); - setGLExtensionFuncPtr(glTexStorage3D, "glTexStorage3D","glTexStorage3DEXT", validContext); - setGLExtensionFuncPtr(glTextureStorage3D, "glTextureStorage3D","glTextureStorage3DEXT", validContext); setGLExtensionFuncPtr(glCompressedTexImage3D, "glCompressedTexImage3D","glCompressedTexImage3DARB", validContext); setGLExtensionFuncPtr(glCompressedTexSubImage3D, "glCompressedTexSubImage3D","glCompressedTexSubImage3DARB", validContext); @@ -1382,4 +1389,3 @@ bool GLExtensions::getFragDataLocation( const char* fragDataName, GLuint& locati location = loc; return true; } - From 7be09e8dcd1ed63eb501c12bb7c8df6f6902783b Mon Sep 17 00:00:00 2001 From: mp3butcher Date: Thu, 8 Feb 2018 23:43:53 +0100 Subject: [PATCH 2/2] fix the particular case when no image assigned (immutable texture storage had no chance to be used) Note: There are other paths where immutable arent used even if available --- src/osg/Texture1D.cpp | 11 ++++++++--- src/osg/Texture2D.cpp | 9 +++++++-- src/osg/Texture2DMultisample.cpp | 10 +++++++--- src/osg/Texture3D.cpp | 8 +++++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index 38327b07d..3714dc858 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -230,9 +230,14 @@ void Texture1D::apply(State& state) const textureObject->bind(); applyTexParameters(GL_TEXTURE_1D,state); - - // no image present, but dimensions are set so lets create the texture - glTexImage1D( GL_TEXTURE_1D, 0, _internalFormat, + GLExtensions * extensions = state.get(); + bool useTexStorrage = extensions->isTextureStorageEnabled; + // no image present, but dimensions at set so lets create the texture + if(useTexStorrage) + extensions->glTexStorage1D( GL_TEXTURE_1D, (_numMipmapLevels >0)?_numMipmapLevels:1, _internalFormat, + _textureWidth); + else + glTexImage1D( GL_TEXTURE_1D, 0, _internalFormat, _textureWidth, _borderWidth, _sourceFormat ? _sourceFormat : _internalFormat, _sourceType ? _sourceType : GL_UNSIGNED_BYTE, diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index 1090f64e1..bcc336504 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -295,8 +295,14 @@ void Texture2D::apply(State& state) const applyTexParameters(GL_TEXTURE_2D,state); + GLExtensions * extensions = state.get(); + bool useTexStorrage = extensions->isTextureStorageEnabled; // no image present, but dimensions at set so lets create the texture - glTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, + if(useTexStorrage) + extensions->glTexStorage2D( GL_TEXTURE_2D, (_numMipmapLevels >0)?_numMipmapLevels:1, _internalFormat, + _textureWidth, _textureHeight); + else + glTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, _textureWidth, _textureHeight, _borderWidth, _sourceFormat ? _sourceFormat : _internalFormat, _sourceType ? _sourceType : GL_UNSIGNED_BYTE, @@ -494,4 +500,3 @@ void Texture2D::allocateMipmap(State& state) const state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); } } - diff --git a/src/osg/Texture2DMultisample.cpp b/src/osg/Texture2DMultisample.cpp index c723da906..a5ec6ec2a 100644 --- a/src/osg/Texture2DMultisample.cpp +++ b/src/osg/Texture2DMultisample.cpp @@ -113,8 +113,12 @@ void Texture2DMultisample::apply(State& state) const _borderWidth); textureObject->bind(); - - extensions->glTexImage2DMultisample( getTextureTarget(), + // no image present, but dimensions at set so lets create the texture + if(extensions->isTextureStorageEnabled) + extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, _internalFormat, + _textureWidth, _textureHeight, _fixedsamplelocations); + else + extensions->glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, _internalFormat, _textureWidth, @@ -124,7 +128,7 @@ void Texture2DMultisample::apply(State& state) const } else { - glBindTexture( getTextureTarget(), 0 ); + glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, 0 ); } } diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 5294b5a38..ed14a1d54 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -318,7 +318,13 @@ void Texture3D::apply(State& state) const applyTexParameters(GL_TEXTURE_3D,state); // no image present, but dimensions at set so lets create the texture - extensions->glTexImage3D( GL_TEXTURE_3D, 0, _internalFormat, + bool useTexStorrage = extensions->isTextureStorageEnabled; + // no image present, but dimensions at set so lets create the texture + if(useTexStorrage) + extensions->glTexStorage3D( GL_TEXTURE_3D, (_numMipmapLevels >0)?_numMipmapLevels:1, _internalFormat, + _textureWidth, _textureHeight, _textureDepth); + else + extensions->glTexImage3D( GL_TEXTURE_3D, 0, _internalFormat, _textureWidth, _textureHeight, _textureDepth, _borderWidth, _sourceFormat ? _sourceFormat : _internalFormat,