From 71f134c64bd184873e1a8608650f8d0c509c4364 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 17 Aug 2018 12:20:59 +0100 Subject: [PATCH] Created a GLenum Texture::selectSizedInternalFormat(const osg::Image* image=0) const method to help clean up set up of glTexStorage. Fixed typo. --- include/osg/Texture | 4 ++- src/osg/Texture.cpp | 76 ++++++++++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index 03532bd16..2462df4cd 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -652,8 +652,10 @@ class OSG_EXPORT Texture : public osg::TextureAttribute /** Get the internal texture format type. */ inline InternalFormatType getInternalFormatType() const { return _internalFormatType; } - class TextureObject; + /* select the size internal format to use based on Image when available or Texture format settings.*/ + GLenum selectSizedInternalFormat(const osg::Image* image=0) const; + class TextureObject; /** return true if the texture image data has been modified and the associated GL texture object needs to be updated.*/ virtual bool isDirty(unsigned int /*contextID*/) const { return false; } diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index e5fe5502f..a51c04db5 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -228,7 +228,7 @@ GLenum assumeSizedInternalFormat(GLint internalFormat, GLenum type) return 0; } -bool isCompressedInternalFormatSupportedByTexStorrage(GLint internalFormat) +bool isCompressedInternalFormatSupportedByTexStorage(GLint internalFormat) { const size_t formatsCount = sizeof(compressedInternalFormats) / sizeof(compressedInternalFormats[0]); @@ -2091,6 +2091,45 @@ bool Texture::areAllTextureObjectsLoaded() const return true; } +GLenum Texture::selectSizedInternalFormat(const osg::Image* image) const +{ + if (_borderWidth!=0) return 0; + + if (image) + { + bool compressed_image = isCompressedInternalFormat((GLenum)image->getPixelFormat()); + + //calculate sized internal format + if(compressed_image) + { + if(isCompressedInternalFormatSupportedByTexStorage(_internalFormat)) + { + return _internalFormat; + } + else + { + return 0; + } + } + else + { + if(isSizedInternalFormat(_internalFormat)) + { + return _internalFormat; + } + else + { + return assumeSizedInternalFormat((GLenum)image->getInternalTextureFormat(), (GLenum)image->getDataType()); + } + } + } + else + { + if (isSizedInternalFormat(_internalFormat)) return _internalFormat; + + return assumeSizedInternalFormat(_internalFormat, (_sourceType!=0) ? _sourceType : GL_UNSIGNED_BYTE); + } +} void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* image, GLsizei inwidth, GLsizei inheight,GLsizei numMipmapLevels) const { @@ -2281,38 +2320,11 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima int width = inwidth; int height = inheight; - bool useTexStorrage = extensions->isTextureStorageEnabled; - GLenum sizedInternalFormat = 0; + bool useTexStorage = extensions->isTextureStorageEnabled && extensions->isTexStorage2DSupported() && (_borderWidth==0); + GLenum sizedInternalFormat = useTexStorage ? selectSizedInternalFormat(image) : 0; + OSG_NOTICE<<"New path useTexStorage="<