From 274b6894affb2ecd3d53c371c4aebcc294604f00 Mon Sep 17 00:00:00 2001 From: mp3butcher Date: Sun, 19 Aug 2018 22:46:10 +0200 Subject: [PATCH 1/9] remove redondant variable and test --- src/osg/Texture.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index ec3948f1f..f50e5f045 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -2310,22 +2310,21 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima int width = inwidth; int height = inheight; - bool useTexStorage = extensions->isTextureStorageEnabled && extensions->isTexStorage2DSupported() && (_borderWidth==0); - GLenum sizedInternalFormat = useTexStorage ? selectSizedInternalFormat(image) : 0; - OSG_NOTICE<<"New path useTexStorage="<= 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); @@ -971,12 +978,21 @@ GLExtensions::GLExtensions(unsigned int in_contextID): maxLayerCount = 0; if (validContext) glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &maxLayerCount); - // Bindless textures + // ARB_bindless_texture setGLExtensionFuncPtr(glGetTextureHandle, "glGetTextureHandle", "glGetTextureHandleARB","glGetTextureHandleNV", validContext); + setGLExtensionFuncPtr(glGetTextureSamplerHandle, "glGetTextureSamplerHandle","glGetTextureSamplerHandleARB", "glGetTextureSamplerHandleNV", validContext); setGLExtensionFuncPtr(glMakeTextureHandleResident, "glMakeTextureHandleResident", "glMakeTextureHandleResidentARB","glMakeTextureHandleResidentNV", validContext); setGLExtensionFuncPtr(glMakeTextureHandleNonResident, "glMakeTextureHandleNonResident", "glMakeTextureHandleNonResidentARB", "glMakeTextureHandleNonResidentNV",validContext); - setGLExtensionFuncPtr(glUniformHandleui64, "glUniformHandleui64", "glUniformHandleui64ARB","glUniformHandleui64NV", validContext); setGLExtensionFuncPtr(glIsTextureHandleResident, "glIsTextureHandleResident","glIsTextureHandleResidentARB", "glIsTextureHandleResidentNV", validContext); + setGLExtensionFuncPtr(glGetImageHandle, "glGetImageHandle","glGetImageHandleARB", "glGetImageHandleNV", validContext); + setGLExtensionFuncPtr(glMakeImageHandleResident, "glMakeImageHandleResident","glMakeImageHandleResidentARB", "glMakeImageHandleResidentNV", validContext); + setGLExtensionFuncPtr(glMakeImageHandleNonResident, "glMakeImageHandleNonResident","glMakeImageHandleNonResidentARB", "glMakeImageHandleNonResidentNV", validContext); + setGLExtensionFuncPtr(glIsImageHandleResident, "glIsImageHandleResident","glIsImageHandleResidentARB", "glIsImageHandleResidentNV", validContext); + setGLExtensionFuncPtr(glUniformHandleui64, "glUniformHandleui64", "glUniformHandleui64ARB","glUniformHandleui64NV", validContext); + setGLExtensionFuncPtr(glUniformHandleuiv64, "glUniformHandleuiv64","glUniformHandleuiv64ARB", "glUniformHandleuiv64NV", validContext); + setGLExtensionFuncPtr(glProgramUniformHandleui64, "glProgramUniformHandleui64","glProgramUniformHandleui64ARB", "glProgramUniformHandleui64NV", validContext); + setGLExtensionFuncPtr(glProgramUniformHandleuiv64, "glProgramUniformHandleuiv64","glProgramUniformHandleuiv64ARB", "glProgramUniformHandleuiv64NV", validContext); + // Blending isBlendColorSupported = validContext && @@ -1054,9 +1070,7 @@ GLExtensions::GLExtensions(unsigned int in_contextID): isPointSpriteSupported = validContext && (OSG_GLES2_FEATURES || OSG_GLES3_FEATURES || OSG_GL3_FEATURES || isGLExtensionSupported(contextID, "GL_ARB_point_sprite") || isGLExtensionSupported(contextID, "GL_OES_point_sprite") || isGLExtensionSupported(contextID, "GL_NV_point_sprite")); - isPointSpriteModeSupported = isPointSpriteSupported && !OSG_GL3_FEATURES; - isPointSpriteCoordOriginSupported = validContext && (OSG_GL3_FEATURES || (glVersion >= 2.0f)); From e043c3db33642a33d843e629a5f4e1eee24f0683 Mon Sep 17 00:00:00 2001 From: mp3butcher Date: Mon, 20 Aug 2018 05:10:11 +0200 Subject: [PATCH 3/9] complete TexStorage support --- src/osg/Texture1D.cpp | 26 +++++++++++---- src/osg/Texture2D.cpp | 38 +++++++++++++++------- src/osg/Texture2DArray.cpp | 56 ++++++++++++++++++++++---------- src/osg/Texture2DMultisample.cpp | 27 ++++++++------- src/osg/Texture3D.cpp | 28 +++++++++++----- src/osg/TextureCubeMap.cpp | 33 ++++++++++++++----- src/osg/TextureRectangle.cpp | 38 +++++++++++++++------- 7 files changed, 169 insertions(+), 77 deletions(-) diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index dd0a28ad6..f316968ef 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -230,18 +230,30 @@ void Texture1D::apply(State& state) const } else if ( (_textureWidth!=0) && (_internalFormat!=0) ) { - textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D,_numMipmapLevels,_internalFormat,_textureWidth,1,1,0); + // no image present, but dimensions at set so lets create the texture + GLExtensions * extensions = state.get(); + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled ? selectSizedInternalFormat() : 0; + if (texStorageSizedInternalFormat!=0) + { + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, 1, 1, 0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_1D, state); - textureObject->bind(); + extensions->glTexStorage1D( GL_TEXTURE_1D, (_numMipmapLevels >0)?_numMipmapLevels:1, texStorageSizedInternalFormat, _textureWidth); + } + else + { + GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat; + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_1D, _numMipmapLevels, internalFormat, _textureWidth, 1, 1, 0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_1D, state); - applyTexParameters(GL_TEXTURE_1D,state); - - // no image present, but dimensions are set so lets create the texture - glTexImage1D( GL_TEXTURE_1D, 0, _internalFormat, + glTexImage1D( GL_TEXTURE_1D, 0, _internalFormat, _textureWidth, _borderWidth, - _sourceFormat ? _sourceFormat : _internalFormat, + internalFormat, _sourceType ? _sourceType : GL_UNSIGNED_BYTE, 0); + } if (_readPBuffer.valid()) { diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index 06ca1aed3..950bc9061 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -243,6 +243,7 @@ void Texture2D::apply(State& state) const } else if (_image.valid() && _image->data()) { + GLExtensions * extensions = state.get(); // keep the image around at least till we go out of scope. osg::ref_ptr image = _image; @@ -253,7 +254,10 @@ void Texture2D::apply(State& state) const // compute the dimensions of the texture. computeRequiredTextureDimensions(state,*image,_textureWidth, _textureHeight, _numMipmapLevels); - textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth); + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat(_image) : 0; + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, + texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat : _internalFormat, + _textureWidth, _textureHeight, 1, _borderWidth); textureObject->bind(); @@ -293,18 +297,30 @@ void Texture2D::apply(State& state) const } else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) { - textureObject = generateAndAssignTextureObject(contextID,GL_TEXTURE_2D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,_borderWidth); - - textureObject->bind(); - - applyTexParameters(GL_TEXTURE_2D,state); // no image present, but dimensions at set so lets create the texture - glTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, - _textureWidth, _textureHeight, _borderWidth, - _sourceFormat ? _sourceFormat : _internalFormat, - _sourceType ? _sourceType : GL_UNSIGNED_BYTE, - 0); + GLExtensions * extensions = state.get(); + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat() : 0; + if (texStorageSizedInternalFormat!=0) + { + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, _borderWidth); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_2D, state); + extensions->glTexStorage2D( GL_TEXTURE_2D, (_numMipmapLevels >0)?_numMipmapLevels:1, texStorageSizedInternalFormat, + _textureWidth, _textureHeight); + } + else + { + GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat; + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_2D, _numMipmapLevels, internalFormat, _textureWidth, _textureHeight, 1, _borderWidth); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_2D, state); + glTexImage2D( GL_TEXTURE_2D, 0, _internalFormat, + _textureWidth, _textureHeight, _borderWidth, + internalFormat, + _sourceType ? _sourceType : GL_UNSIGNED_BYTE, + 0); + } if (_readPBuffer.valid()) { diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 5c78b171b..0778d3b10 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -336,42 +336,53 @@ void Texture2DArray::apply(State& state) const // compute the internal texture format, this set the _internalFormat to an appropriate value. computeInternalFormat(); + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat(_images[0]) : 0; + // compute the dimensions of the texture. computeRequiredTextureDimensions(state,*_images[0],_textureWidth, _textureHeight, _numMipmapLevels); // create texture object textureObject = generateAndAssignTextureObject( - contextID, GL_TEXTURE_2D_ARRAY,_numMipmapLevels, _internalFormat, _textureWidth, _textureHeight, textureDepth,0); + contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, + texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat : _internalFormat, + _textureWidth, _textureHeight, textureDepth,0); // bind texture textureObject->bind(); + applyTexParameters(GL_TEXTURE_2D_ARRAY, state); // First we need to allocate the texture memory - int sourceFormat = _sourceFormat ? _sourceFormat : _internalFormat; - - if( isCompressedInternalFormat( sourceFormat ) && - sourceFormat == _internalFormat && - extensions->isCompressedTexImage3DSupported() ) + if(texStorageSizedInternalFormat!=0) { - extensions->glCompressedTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, - _textureWidth, _textureHeight, textureDepth, _borderWidth, - _images[0]->getImageSizeInBytes() * textureDepth, - 0); + extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, textureDepth); } else { + int sourceFormat = _sourceFormat ? _sourceFormat : _internalFormat; + + if( isCompressedInternalFormat( sourceFormat ) && + sourceFormat == _internalFormat && + extensions->isCompressedTexImage3DSupported() ) + { + extensions->glCompressedTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, + _textureWidth, _textureHeight, textureDepth, _borderWidth, + _images[0]->getImageSizeInBytes() * textureDepth, + 0); + } + else + { // Override compressed source format with safe GL_RGBA value which not generate error // We can safely do this as source format is not important when source data is NULL if( isCompressedInternalFormat( sourceFormat ) ) sourceFormat = GL_RGBA; - extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, - _textureWidth, _textureHeight, textureDepth, _borderWidth, - sourceFormat, _sourceType ? _sourceType : GL_UNSIGNED_BYTE, - 0); + extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, + _textureWidth, _textureHeight, textureDepth, _borderWidth, + sourceFormat, _sourceType ? _sourceType : GL_UNSIGNED_BYTE, + 0); + } } - // For certain we have to manually allocate memory for mipmaps if images are compressed // if not allocated OpenGL will produce errors on mipmap upload. // I have not tested if this is necessary for plain texture formats but @@ -430,19 +441,28 @@ void Texture2DArray::apply(State& state) const else if ( (_textureWidth > 0) && (_textureHeight > 0) && (_textureDepth > 0) && (_internalFormat!=0) ) { // generate texture + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled ? selectSizedInternalFormat() : 0; + textureObject = generateAndAssignTextureObject( - contextID, GL_TEXTURE_2D_ARRAY,_numMipmapLevels,_internalFormat, _textureWidth, _textureHeight, _textureDepth,0); + contextID, GL_TEXTURE_2D_ARRAY, _numMipmapLevels, + texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat :_internalFormat, + _textureWidth, _textureHeight, _textureDepth, 0); textureObject->bind(); + applyTexParameters(GL_TEXTURE_2D_ARRAY,state); - extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, + if (texStorageSizedInternalFormat!=0) + { + extensions->glTexStorage3D( GL_TEXTURE_2D_ARRAY, (_numMipmapLevels >0)?_numMipmapLevels:1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth); + } + else + extensions->glTexImage3D( GL_TEXTURE_2D_ARRAY, 0, _internalFormat, _textureWidth, _textureHeight, _textureDepth, _borderWidth, _sourceFormat ? _sourceFormat : _internalFormat, _sourceType ? _sourceType : GL_UNSIGNED_BYTE, 0); - } // nothing before, so just unbind the texture target diff --git a/src/osg/Texture2DMultisample.cpp b/src/osg/Texture2DMultisample.cpp index c723da906..94e5b53ae 100644 --- a/src/osg/Texture2DMultisample.cpp +++ b/src/osg/Texture2DMultisample.cpp @@ -102,29 +102,32 @@ void Texture2DMultisample::apply(State& state) const } else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_numSamples!=0) ) { - textureObject = generateAndAssignTextureObject( - contextID, - getTextureTarget(), - 1, - _internalFormat, - _textureWidth, - _textureHeight, - 1, - _borderWidth); + // no image present, but dimensions at set so lets create the texture + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat() : 0; + if (texStorageSizedInternalFormat!=0) + { + textureObject = generateAndAssignTextureObject(contextID, getTextureTarget(), 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0); + textureObject->bind(); - textureObject->bind(); + extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _fixedsamplelocations); + } + else + { + textureObject = generateAndAssignTextureObject(contextID, getTextureTarget(), 1, _internalFormat, _textureWidth, _textureHeight, 1, _borderWidth); + textureObject->bind(); - extensions->glTexImage2DMultisample( getTextureTarget(), + extensions->glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, _internalFormat, _textureWidth, _textureHeight, _fixedsamplelocations ); + } } else { - glBindTexture( getTextureTarget(), 0 ); + glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, 0 ); } } diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 1fc2f26c1..eee22cc6f 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -315,20 +315,30 @@ void Texture3D::apply(State& state) const } else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_textureDepth!=0) && (_internalFormat!=0) ) { - textureObject = generateAndAssignTextureObject( - contextID,GL_TEXTURE_3D,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,_textureDepth,0); - - textureObject->bind(); - - applyTexParameters(GL_TEXTURE_3D,state); - // no image present, but dimensions at set so lets create the texture - extensions->glTexImage3D( GL_TEXTURE_3D, 0, _internalFormat, + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled ? selectSizedInternalFormat() : 0; + if (texStorageSizedInternalFormat!=0) + { + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_3D, _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth,0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_3D, state); + + extensions->glTexStorage3D( GL_TEXTURE_3D, (_numMipmapLevels >0)?_numMipmapLevels:1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _textureDepth); + } + else + { + GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat; + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_3D, _numMipmapLevels, internalFormat, _textureWidth, _textureHeight, _textureDepth,0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_3D, state); + + extensions->glTexImage3D( GL_TEXTURE_3D, 0, _internalFormat, _textureWidth, _textureHeight, _textureDepth, _borderWidth, - _sourceFormat ? _sourceFormat : _internalFormat, + internalFormat, _sourceType ? _sourceType : GL_UNSIGNED_BYTE, 0); + } if (_readPBuffer.valid()) { diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index ed43d2b2c..3c4134fe3 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -293,8 +293,12 @@ void TextureCubeMap::apply(State& state) const _textureWidth = _textureHeight = minimum( _textureWidth , _textureHeight ); } + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat(_images[0]) : 0; + textureObject = generateAndAssignTextureObject( - contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); + contextID, GL_TEXTURE_CUBE_MAP, _numMipmapLevels, + texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat : _internalFormat, + _textureWidth, _textureHeight, 1, 0); textureObject->bind(); @@ -335,22 +339,33 @@ void TextureCubeMap::apply(State& state) const } else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) { + + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat() : 0; + textureObject = generateAndAssignTextureObject( - contextID,GL_TEXTURE_CUBE_MAP,_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); + contextID, GL_TEXTURE_CUBE_MAP, _numMipmapLevels, + texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat : _internalFormat, + _textureWidth, _textureHeight, 1, 0); textureObject->bind(); applyTexParameters(GL_TEXTURE_CUBE_MAP,state); - for (int n=0; n<6; n++) + if(texStorageSizedInternalFormat!=0) { - // no image present, but dimensions at set so less create the texture - glTexImage2D( faceTarget[n], 0, _internalFormat, - _textureWidth, _textureHeight, _borderWidth, - _sourceFormat ? _sourceFormat : _internalFormat, - _sourceType ? _sourceType : GL_UNSIGNED_BYTE, - 0); + extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, _numMipmapLevels==0 ? 1 : _numMipmapLevels, texStorageSizedInternalFormat, _textureWidth, _textureHeight); + } + else + for (int n=0; n<6; n++) + { + // no image present, but dimensions at set so less create the texture + glTexImage2D( faceTarget[n], 0, _internalFormat, + _textureWidth, _textureHeight, _borderWidth, + _sourceFormat ? _sourceFormat : _internalFormat, + _sourceType ? _sourceType : GL_UNSIGNED_BYTE, + 0); + } } else diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index 4a60e166d..27c5dfff2 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -231,7 +231,7 @@ void TextureRectangle::apply(State& state) const } else if (_image.valid() && _image->data()) { - + GLExtensions * extensions = state.get(); // keep the image around at least till we go out of scope. osg::ref_ptr image = _image; @@ -239,11 +239,16 @@ void TextureRectangle::apply(State& state) const // compute the internal texture format, this set the _internalFormat to an appropriate value. computeInternalFormat(); + //get sizedInternalFormat if TexStorage available + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat(image) : 0; + _textureWidth = image->s(); _textureHeight = image->t(); textureObject = generateAndAssignTextureObject( - contextID,GL_TEXTURE_RECTANGLE,1,_internalFormat,_textureWidth,_textureHeight,1,0); + contextID, GL_TEXTURE_RECTANGLE, 1, + texStorageSizedInternalFormat!=0 ? texStorageSizedInternalFormat : _internalFormat, + _textureWidth, _textureHeight, 1, 0); textureObject->bind(); @@ -268,19 +273,30 @@ void TextureRectangle::apply(State& state) const } else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) ) { - textureObject = generateAndAssignTextureObject( - contextID,GL_TEXTURE_RECTANGLE,0,_internalFormat,_textureWidth,_textureHeight,1,0); - - textureObject->bind(); - - applyTexParameters(GL_TEXTURE_RECTANGLE,state); - // no image present, but dimensions at set so lets create the texture - glTexImage2D( GL_TEXTURE_RECTANGLE, 0, _internalFormat, + GLExtensions * extensions = state.get(); + GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled ? selectSizedInternalFormat() : 0; + if (texStorageSizedInternalFormat!=0) + { + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_RECTANGLE, 0, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_RECTANGLE, state); + + extensions->glTexStorage2D( GL_TEXTURE_RECTANGLE, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight); + } + else + { + GLenum internalFormat = _sourceFormat ? _sourceFormat : _internalFormat; + textureObject = generateAndAssignTextureObject(contextID, GL_TEXTURE_RECTANGLE, 0, internalFormat, _textureWidth, _textureHeight, 1, 0); + textureObject->bind(); + applyTexParameters(GL_TEXTURE_RECTANGLE, state); + + glTexImage2D( GL_TEXTURE_RECTANGLE, 0, _internalFormat, _textureWidth, _textureHeight, _borderWidth, - _sourceFormat ? _sourceFormat : _internalFormat, + internalFormat, _sourceType ? _sourceType : GL_UNSIGNED_BYTE, 0); + } if (_readPBuffer.valid()) { From 250dcc5b6cf3dafae21b0bda2683a408cf8ac402 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 21 Aug 2018 09:19:50 +0100 Subject: [PATCH 4/9] Replaced GL_RGBA32F with GL_RGBA32F_ARB to fix Windows build --- src/osg/Texture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index f50e5f045..9f569c39f 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -151,7 +151,7 @@ InternalPixelRelations sizedInternalFormats[] = { , { GL_RGB5_A1 , GL_RGBA , GL_UNSIGNED_INT_2_10_10_10_REV } // , { GL_RGBA16F , GL_RGBA , GL_HALF_FLOAT } , { GL_RGBA16F , GL_RGBA , GL_FLOAT } - , { GL_RGBA32F , GL_RGBA , GL_FLOAT } + , { GL_RGBA32F_ARB , GL_RGBA , GL_FLOAT } , { GL_SRGB8 , GL_RGB , GL_UNSIGNED_BYTE } , { GL_SRGB8_ALPHA8 , GL_RGBA , GL_UNSIGNED_BYTE } From dd9312ae35f4742f526634bcc4eb331df4a3d724 Mon Sep 17 00:00:00 2001 From: plevy Date: Tue, 21 Aug 2018 09:38:03 -0400 Subject: [PATCH 5/9] Change GL_RGBA16F to GL_RGBA16F_ARB to fix Windows Build Change GL_RGBA16F to GL_RGBA16F_ARB to fix Windows build. --- src/osg/Texture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 9f569c39f..7dedf844d 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -150,7 +150,7 @@ InternalPixelRelations sizedInternalFormats[] = { , { GL_RGB5_A1 , GL_RGBA , GL_UNSIGNED_INT_10_10_10_2 } , { GL_RGB5_A1 , GL_RGBA , GL_UNSIGNED_INT_2_10_10_10_REV } // , { GL_RGBA16F , GL_RGBA , GL_HALF_FLOAT } - , { GL_RGBA16F , GL_RGBA , GL_FLOAT } + , { GL_RGBA16F_ARB , GL_RGBA , GL_FLOAT } , { GL_RGBA32F_ARB , GL_RGBA , GL_FLOAT } , { GL_SRGB8 , GL_RGB , GL_UNSIGNED_BYTE } From 4f7f34a6b0af9c74e2cb871e87f7fd44606504fc Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 22 Aug 2018 10:42:18 +0100 Subject: [PATCH 6/9] Merged fix for PointSprite modes validity checks from master. --- src/osg/State.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/osg/State.cpp b/src/osg/State.cpp index d41cc362d..5f31760cf 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -285,6 +286,18 @@ void State::initializeExtensionProcs() } } + // set the validity of Modes + if (false) + { + bool pointSpriteModeValid = _glExtensions->isPointSpriteModeSupported; + + #if defined( OSG_GLES1_AVAILABLE ) //point sprites don't exist on es 2.0 + setModeValidity(GL_POINT_SPRITE_OES, pointSpriteModeValid); + #else + setModeValidity(GL_POINT_SPRITE_ARB, pointSpriteModeValid); + #endif + } + _extensionProcsInitialized = true; From d18c498322e24bd2162c0b37d175f3ee2c8e4916 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 22 Aug 2018 11:13:11 +0100 Subject: [PATCH 7/9] Enabled point sprite validty modes. --- src/osg/State.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 5f31760cf..5cd5b3eca 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -287,7 +287,6 @@ void State::initializeExtensionProcs() } // set the validity of Modes - if (false) { bool pointSpriteModeValid = _glExtensions->isPointSpriteModeSupported; From 77fd07eaa9e90167ae78a397ac9c53e535d3fde5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 28 Aug 2018 11:22:57 +0100 Subject: [PATCH 8/9] Replaced the glSGetProcAddressARB code with the dlsym() usage as the NVidia driver looks to be returning non NULL pointers for invalid function names. --- src/osg/GLExtensions.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index 76118d0d6..ed0cd8d61 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -399,17 +399,6 @@ OSG_INIT_SINGLETON_PROXY(GLExtensionDisableStringInitializationProxy, osg::getGL #elif defined (__linux__) - typedef void (*__GLXextFuncPtr)(void); - typedef __GLXextFuncPtr (*GetProcAddressARBProc)(const char*); - - #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) - static GetProcAddressARBProc s_glXGetProcAddressARB = convertPointerType(dlsym(0, "glXGetProcAddressARB")); - if (s_glXGetProcAddressARB) - { - return convertPointerType((s_glXGetProcAddressARB)(funcName)); - } - #endif - return dlsym(0, funcName); #elif defined (__QNX__) From 006ca64f4bb2917ae638ce75b8f6d4eafc460d0a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 3 Sep 2018 09:37:36 +0100 Subject: [PATCH 9/9] Added reset of _stateset to prevent the releaseGLObjects calling release on th StateSet from the destructor --- src/osg/Drawable.cpp | 1 + src/osg/Geometry.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 5c2b5551b..604cfca0d 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -256,6 +256,7 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop): Drawable::~Drawable() { + _stateset = 0; Drawable::releaseGLObjects(); } diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 4c58ea069..69fb840cf 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -82,6 +82,7 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): Geometry::~Geometry() { + _stateset = 0; Geometry::releaseGLObjects(); }