Merge branch 'OpenSceneGraph-3.6-TexStorage' into OpenSceneGraph-3.6

This commit is contained in:
Robert Osfield 2018-09-03 10:16:45 +01:00
commit 61967a7d1a
10 changed files with 232 additions and 109 deletions

View File

@ -365,11 +365,21 @@ class OSG_EXPORT GLExtensions : public osg::Referenced
void (GL_APIENTRY * glUniformMatrix4x3dv)( GLint location, GLsizei count, GLboolean transpose, const GLdouble* value );
void (GL_APIENTRY * glGetActiveAtomicCounterBufferiv)( GLuint program, GLuint bufferIndex, GLenum pname, GLint* params );
void (GL_APIENTRY * glDispatchCompute)( GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ );
GLuint64 (GL_APIENTRY* glGetTextureHandle)(GLint texture);
// ARB_bindless_texture
GLuint64 (GL_APIENTRY* glGetTextureHandle)(GLuint texture);
GLuint64 (GL_APIENTRY* glGetTextureSamplerHandle)(GLuint texture, GLuint sampler);
void (GL_APIENTRY* glMakeTextureHandleResident)(GLuint64 handle);
void (GL_APIENTRY* glMakeTextureHandleNonResident)(GLuint64 handle);
void (GL_APIENTRY* glUniformHandleui64)(GLint location, GLuint64 handle);
GLboolean (GL_APIENTRY* glIsTextureHandleResident)(GLuint64 handle);
GLuint64 (GL_APIENTRY* glGetImageHandle)(GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format);
void (GL_APIENTRY* glMakeImageHandleResident)(GLuint64 handle);
void (GL_APIENTRY* glMakeImageHandleNonResident)(GLuint64 handle);
GLboolean (GL_APIENTRY* glIsImageHandleResident)(GLuint64 handle);
void (GL_APIENTRY* glUniformHandleui64)(GLint location, GLuint64 handle);
void (GL_APIENTRY* glUniformHandleuiv64)(GLint location, GLsizei count, GLuint64 *handles);
void (GL_APIENTRY* glProgramUniformHandleui64)(GLuint program, GLint location, GLuint64 handle);
void (GL_APIENTRY* glProgramUniformHandleuiv64)(GLuint program, GLint location, GLsizei count, GLuint64 *handles);
// Buffer Object extensions
bool isBufferObjectSupported;
@ -538,7 +548,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 +577,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);

View File

@ -902,18 +902,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"));
@ -928,6 +916,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"));
@ -939,8 +948,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);
@ -960,12 +967,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 &&
@ -1043,9 +1059,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));

View File

@ -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="<<useTexStorage<<", sizedInternalFormat="<<sizedInternalFormat<<std::endl;
GLenum texStoragesizedInternalFormat = extensions->isTextureStorageEnabled && extensions->isTexStorage2DSupported() && (_borderWidth==0) ? selectSizedInternalFormat(image) : 0;
if (useTexStorage && sizedInternalFormat!=0)
if (texStoragesizedInternalFormat!=0)
{
if (getTextureTarget()==GL_TEXTURE_CUBE_MAP)
{
if (target==GL_TEXTURE_CUBE_MAP_POSITIVE_X)
{
extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, numMipmapLevels, sizedInternalFormat, width, height);
// only allocate on first face image
extensions->glTexStorage2D(GL_TEXTURE_CUBE_MAP, numMipmapLevels, texStoragesizedInternalFormat, width, height);
}
}
else
{
extensions->glTexStorage2D(target, numMipmapLevels, sizedInternalFormat, width, height);
extensions->glTexStorage2D(target, numMipmapLevels, texStoragesizedInternalFormat, width, height);
}
if( !compressed_image )

View File

@ -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<GLExtensions>();
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);
applyTexParameters(GL_TEXTURE_1D,state);
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);
// no image present, but dimensions are set so lets create the texture
glTexImage1D( GL_TEXTURE_1D, 0, _internalFormat,
_textureWidth, _borderWidth,
_sourceFormat ? _sourceFormat : _internalFormat,
internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
}
if (_readPBuffer.valid())
{

View File

@ -243,6 +243,7 @@ void Texture2D::apply(State& state) const
}
else if (_image.valid() && _image->data())
{
GLExtensions * extensions = state.get<GLExtensions>();
// keep the image around at least till we go out of scope.
osg::ref_ptr<osg::Image> 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
GLExtensions * extensions = state.get<GLExtensions>();
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,
_sourceFormat ? _sourceFormat : _internalFormat,
internalFormat,
_sourceType ? _sourceType : GL_UNSIGNED_BYTE,
0);
}
if (_readPBuffer.valid())
{

View File

@ -336,18 +336,29 @@ 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
if(texStorageSizedInternalFormat!=0)
{
extensions->glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, textureDepth);
}
else
{
int sourceFormat = _sourceFormat ? _sourceFormat : _internalFormat;
if( isCompressedInternalFormat( sourceFormat ) &&
@ -371,7 +382,7 @@ void Texture2DArray::apply(State& state) const
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);
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

View File

@ -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();
extensions->glTexImage2DMultisample( getTextureTarget(),
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( GL_TEXTURE_2D_MULTISAMPLE,
_numSamples,
_internalFormat,
_textureWidth,
_textureHeight,
_fixedsamplelocations );
}
}
else
{
glBindTexture( getTextureTarget(), 0 );
glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, 0 );
}
}

View File

@ -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
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())
{

View File

@ -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,13 +339,24 @@ 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);
if(texStorageSizedInternalFormat!=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

View File

@ -231,7 +231,7 @@ void TextureRectangle::apply(State& state) const
}
else if (_image.valid() && _image->data())
{
GLExtensions * extensions = state.get<GLExtensions>();
// keep the image around at least till we go out of scope.
osg::ref_ptr<osg::Image> 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
GLExtensions * extensions = state.get<GLExtensions>();
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())
{