Created a GLenum Texture::selectSizedInternalFormat(const osg::Image* image=0) const method to help clean up set up of glTexStorage.

Fixed typo.
This commit is contained in:
Robert Osfield 2018-08-17 12:20:59 +01:00
parent 7328e03d23
commit 71f134c64b
2 changed files with 47 additions and 33 deletions

View File

@ -652,8 +652,10 @@ class OSG_EXPORT Texture : public osg::TextureAttribute
/** Get the internal texture format type. */ /** Get the internal texture format type. */
inline InternalFormatType getInternalFormatType() const { return _internalFormatType; } 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.*/ /** 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; } virtual bool isDirty(unsigned int /*contextID*/) const { return false; }

View File

@ -228,7 +228,7 @@ GLenum assumeSizedInternalFormat(GLint internalFormat, GLenum type)
return 0; return 0;
} }
bool isCompressedInternalFormatSupportedByTexStorrage(GLint internalFormat) bool isCompressedInternalFormatSupportedByTexStorage(GLint internalFormat)
{ {
const size_t formatsCount = sizeof(compressedInternalFormats) / sizeof(compressedInternalFormats[0]); const size_t formatsCount = sizeof(compressedInternalFormats) / sizeof(compressedInternalFormats[0]);
@ -2091,6 +2091,45 @@ bool Texture::areAllTextureObjectsLoaded() const
return true; 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 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 width = inwidth;
int height = inheight; int height = inheight;
bool useTexStorrage = extensions->isTextureStorageEnabled; bool useTexStorage = extensions->isTextureStorageEnabled && extensions->isTexStorage2DSupported() && (_borderWidth==0);
GLenum sizedInternalFormat = 0; GLenum sizedInternalFormat = useTexStorage ? selectSizedInternalFormat(image) : 0;
OSG_NOTICE<<"New path useTexStorage="<<useTexStorage<<", sizedInternalFormat="<<sizedInternalFormat<<std::endl;
if(useTexStorrage) if (useTexStorage && sizedInternalFormat!=0)
{
if(extensions->isTexStorage2DSupported() && _borderWidth == 0)
{
//calculate sized internal format
if(!compressed_image)
{
if(isSizedInternalFormat(_internalFormat))
{
sizedInternalFormat = _internalFormat;
}
else
{
sizedInternalFormat = assumeSizedInternalFormat((GLenum)image->getInternalTextureFormat(), (GLenum)image->getDataType());
}
}
else
{
if(isCompressedInternalFormatSupportedByTexStorrage(_internalFormat))
{
sizedInternalFormat = _internalFormat;
}
}
}
useTexStorrage &= sizedInternalFormat != 0;
}
if(useTexStorrage)
{ {
if (getTextureTarget()==GL_TEXTURE_CUBE_MAP) if (getTextureTarget()==GL_TEXTURE_CUBE_MAP)
{ {