From cceee38727c51f0edf27c820732441dbaf9ee20e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 9 Dec 2014 10:05:59 +0000 Subject: [PATCH] Moved Texture*::Extensions functionality into GL2Extensions git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14581 16af8721-9629-0410-8352-f15c8da7e697 --- examples/osgmultitexture/osgmultitexture.cpp | 20 +- include/osg/GL2Extensions | 67 +++++++ include/osg/Texture | 198 ------------------- include/osg/Texture2DArray | 80 -------- include/osg/Texture3D | 59 ------ src/osg/GL2Extensions.cpp | 116 +++++++++++ src/osg/Image.cpp | 11 +- src/osg/Texture.cpp | 82 ++++---- src/osg/Texture1D.cpp | 11 +- src/osg/Texture2DArray.cpp | 158 ++------------- src/osg/Texture2DMultisample.cpp | 4 +- src/osg/Texture3D.cpp | 41 ++-- src/osg/TextureBuffer.cpp | 26 +-- src/osg/TextureRectangle.cpp | 6 +- src/osgText/Glyph.cpp | 4 +- 15 files changed, 293 insertions(+), 590 deletions(-) diff --git a/examples/osgmultitexture/osgmultitexture.cpp b/examples/osgmultitexture/osgmultitexture.cpp index 2d32309fd..022b6ad3a 100644 --- a/examples/osgmultitexture/osgmultitexture.cpp +++ b/examples/osgmultitexture/osgmultitexture.cpp @@ -39,22 +39,22 @@ int main( int argc, char **argv ) { // use an ArgumentParser object to manage the program arguments. osg::ArgumentParser arguments(&argc,argv); - + // construct the viewer. osgViewer::Viewer viewer; // load the nodes from the commandline arguments. osg::Node* rootnode = osgDB::readNodeFiles(arguments); - + // if not loaded assume no arguments passed in, try use default mode instead. if (!rootnode) rootnode = osgDB::readNodeFile("cessnafire.osgt"); - + if (!rootnode) { osg::notify(osg::NOTICE)<<"Please specify a model filename on the command line."<setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON); stateset->setTextureAttributeAndModes(1,texgen,osg::StateAttribute::ON); stateset->setTextureAttribute(1,texenv); - + rootnode->setStateSet(stateset); } else @@ -83,21 +83,21 @@ int main( int argc, char **argv ) // run optimization over the scene graph osgUtil::Optimizer optimzer; optimzer.optimize(rootnode); - + // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode ); - + // create the windows and run the threads. viewer.realize(); - for(unsigned int contextID = 0; + for(unsigned int contextID = 0; contextIDgetMaxNumberOfGraphicsContexts(); ++contextID) { - osg::Texture::Extensions* textExt = osg::Texture::getExtensions(contextID,false); + osg::GL2Extensions* textExt = osg::GL2Extensions::Get(contextID,false); if (textExt) { - if (!textExt->isMultiTexturingSupported()) + if (!textExt->isMultiTexturingSupported) { std::cout<<"Warning: multi-texturing not supported by OpenGL drivers, unable to run application."<= 1.2f ); + + isTextureStorageEnabled = isTexStorage2DSupported(); + if ( (ptr = getenv("OSG_GL_TEXTURE_STORAGE")) != 0 && isTexStorage2DSupported()) + { + if (strcmp(ptr,"OFF")==0 || strcmp(ptr,"DISABLE")==0 ) isTextureStorageEnabled = false; + else isTextureStorageEnabled = true; + } + + + // Texture3D extensions + isTexture3DFast = OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture3D"); + + if (isTexture3DFast) isTexture3DSupported = true; + else isTexture3DSupported = strncmp((const char*)glGetString(GL_VERSION),"1.2",3)>=0; + + maxTexture3DSize = 0; + glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &maxTexture3DSize); + + setGLExtensionFuncPtr(glTexImage3D, "glTexImage3D","glTexImage3DEXT"); + setGLExtensionFuncPtr(glTexSubImage3D, "glTexSubImage3D","glTexSubImage3DEXT"); + setGLExtensionFuncPtr(glCompressedTexImage3D, "glCompressedTexImage3D","glCompressedTexImage3DARB"); + setGLExtensionFuncPtr(glCompressedTexSubImage3D, "glCompressedTexSubImage3D","glCompressedTexSubImage3DARB"); + setGLExtensionFuncPtr(glCopyTexSubImage3D, "glCopyTexSubImage3D","glCopyTexSubImage3DEXT"); + + + // Texture2DArray extensions + isTexture2DArraySupported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture_array"); + + max2DSize = 0; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max2DSize); + maxLayerCount = 0; + glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS_EXT, &maxLayerCount); + + } diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index ad0424586..7b95e6c00 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -1053,10 +1053,7 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) // OSG_NOTICE<<"Image::readImageFromCurrentTexture()"<isTexture2DArraySupported()) + if (extensions->isTexture2DArraySupported) { glGetBooleanv(GL_TEXTURE_BINDING_2D_ARRAY_EXT, &binding2DArray); } @@ -1136,14 +1133,14 @@ void Image::readImageFromCurrentTexture(unsigned int contextID, bool copyMipMaps } else if (textureMode==GL_TEXTURE_3D) { - if (extensions3D->isCompressedTexImage3DSupported()) + if (extensions->isCompressedTexImage3DSupported()) { glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_COMPRESSED_ARB,&compressed); } } else if (textureMode==GL_TEXTURE_2D_ARRAY_EXT) { - if (extensions2DArray->isCompressedTexImage3DSupported()) + if (extensions->isCompressedTexImage3DSupported()) { glGetTexLevelParameteriv(textureMode, 0, GL_TEXTURE_COMPRESSED_ARB,&compressed); } diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index d58796da8..c876daf06 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -62,9 +62,6 @@ namespace osg { ApplicationUsageProxy Texture_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_TEXTURE_SIZE","Set the maximum size of textures."); ApplicationUsageProxy Texture_e1(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_GL_TEXTURE_STORAGE","ON|OFF or ENABLE|DISABLE, Enables/disables usage of glTexStorage for textures where supported, default is ENABLED."); -typedef buffered_value< ref_ptr > BufferedExtensions; -static BufferedExtensions s_extensions; - struct InternalPixelRelations { GLenum sizedInternalFormat; @@ -1468,12 +1465,12 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const { const unsigned int contextID = 0; // state.getContextID(); // set to 0 right now, assume same parameters for each graphics context... - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = GL2Extensions::Get(contextID,true); switch(_internalFormatMode) { case(USE_ARB_COMPRESSION): - if (extensions->isTextureCompressionARBSupported()) + if (extensions->isTextureCompressionARBSupported) { switch(image.getPixelFormat()) { @@ -1492,7 +1489,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_S3TC_DXT1_COMPRESSION): - if (extensions->isTextureCompressionS3TCSupported()) + if (extensions->isTextureCompressionS3TCSupported) { switch(image.getPixelFormat()) { @@ -1506,7 +1503,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_S3TC_DXT1c_COMPRESSION): - if (extensions->isTextureCompressionS3TCSupported()) + if (extensions->isTextureCompressionS3TCSupported) { switch(image.getPixelFormat()) { @@ -1520,7 +1517,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_S3TC_DXT1a_COMPRESSION): - if (extensions->isTextureCompressionS3TCSupported()) + if (extensions->isTextureCompressionS3TCSupported) { switch(image.getPixelFormat()) { @@ -1534,7 +1531,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_S3TC_DXT3_COMPRESSION): - if (extensions->isTextureCompressionS3TCSupported()) + if (extensions->isTextureCompressionS3TCSupported) { switch(image.getPixelFormat()) { @@ -1548,7 +1545,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_S3TC_DXT5_COMPRESSION): - if (extensions->isTextureCompressionS3TCSupported()) + if (extensions->isTextureCompressionS3TCSupported) { switch(image.getPixelFormat()) { @@ -1562,7 +1559,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_PVRTC_2BPP_COMPRESSION): - if (extensions->isTextureCompressionPVRTC2BPPSupported()) + if (extensions->isTextureCompressionPVRTC2BPPSupported) { switch(image.getPixelFormat()) { @@ -1576,7 +1573,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_PVRTC_4BPP_COMPRESSION): - if (extensions->isTextureCompressionPVRTC4BPPSupported()) + if (extensions->isTextureCompressionPVRTC4BPPSupported) { switch(image.getPixelFormat()) { @@ -1590,7 +1587,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_ETC_COMPRESSION): - if (extensions->isTextureCompressionETCSupported()) + if (extensions->isTextureCompressionETCSupported) { switch(image.getPixelFormat()) { @@ -1602,7 +1599,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_ETC2_COMPRESSION): - if (extensions->isTextureCompressionETC2Supported()) + if (extensions->isTextureCompressionETC2Supported) { switch(image.getPixelFormat()) { @@ -1620,7 +1617,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_RGTC1_COMPRESSION): - if (extensions->isTextureCompressionRGTCSupported()) + if (extensions->isTextureCompressionRGTCSupported) { switch(image.getPixelFormat()) { @@ -1634,7 +1631,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const break; case(USE_RGTC2_COMPRESSION): - if (extensions->isTextureCompressionRGTCSupported()) + if (extensions->isTextureCompressionRGTCSupported) { switch(image.getPixelFormat()) { @@ -1815,7 +1812,7 @@ void Texture::getCompressedSize(GLenum internalFormat, GLint width, GLint height else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT || internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) blockSize = 16; else if (internalFormat == GL_ETC1_RGB8_OES) - blockSize = 8; + blockSize = 8; else if (internalFormat == GL_COMPRESSED_RGB8_ETC2 || internalFormat == GL_COMPRESSED_SRGB8_ETC2) blockSize = 8; else if (internalFormat == GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 || internalFormat == GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2) @@ -1876,12 +1873,12 @@ void Texture::applyTexParameters(GLenum target, State& state) const // get the contextID (user defined ID of 0 upwards) for the // current OpenGL context. const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); WrapMode ws = _wrap_s, wt = _wrap_t, wr = _wrap_r; // GL_IBM_texture_mirrored_repeat, fall-back REPEAT - if (!extensions->isTextureMirroredRepeatSupported()) + if (!extensions->isTextureMirroredRepeatSupported) { if (ws == MIRROR) ws = REPEAT; @@ -1892,7 +1889,7 @@ void Texture::applyTexParameters(GLenum target, State& state) const } // GL_EXT_texture_edge_clamp, fall-back CLAMP - if (!extensions->isTextureEdgeClampSupported()) + if (!extensions->isTextureEdgeClampSupported) { if (ws == CLAMP_TO_EDGE) ws = CLAMP; @@ -1902,7 +1899,7 @@ void Texture::applyTexParameters(GLenum target, State& state) const wr = CLAMP; } - if(!extensions->isTextureBorderClampSupported()) + if(!extensions->isTextureBorderClampSupported) { if(ws == CLAMP_TO_BORDER) ws = CLAMP; @@ -1921,7 +1918,7 @@ void Texture::applyTexParameters(GLenum target, State& state) const const Image * image = getImage(0); if( image && image->isMipmap() && - extensions->isTextureMaxLevelSupported() && + extensions->isTextureMaxLevelSupported && int( image->getNumMipmapLevels() ) < Image::computeNumberOfMipmapLevels( image->s(), image->t(), image->r() ) ) glTexParameteri( target, GL_TEXTURE_MAX_LEVEL, image->getNumMipmapLevels() - 1 ); @@ -1938,7 +1935,7 @@ void Texture::applyTexParameters(GLenum target, State& state) const glTexParameteri( target, GL_TEXTURE_MAG_FILTER, _mag_filter); // Art: I think anisotropic filtering is not supported by the integer textures - if (extensions->isTextureFilterAnisotropicSupported() && + if (extensions->isTextureFilterAnisotropicSupported && _internalFormatType != SIGNED_INTEGER && _internalFormatType != UNSIGNED_INTEGER) { // note, GL_TEXTURE_MAX_ANISOTROPY_EXT will either be defined @@ -1946,14 +1943,14 @@ void Texture::applyTexParameters(GLenum target, State& state) const glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, _maxAnisotropy); } - if (extensions->isTextureSwizzleSupported()) + if (extensions->isTextureSwizzleSupported) { // note, GL_TEXTURE_SWIZZLE_RGBA will either be defined // by gl.h (or via glext.h) or by include/osg/Texture. glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, _swizzle.ptr()); } - if (extensions->isTextureBorderClampSupported()) + if (extensions->isTextureBorderClampSupported) { #ifndef GL_TEXTURE_BORDER_COLOR @@ -1977,7 +1974,7 @@ void Texture::applyTexParameters(GLenum target, State& state) const // integer textures are not supported by the shadow // GL_TEXTURE_1D_ARRAY_EXT could be included in the check below but its not yet implemented in OSG - if (extensions->isShadowSupported() && + if (extensions->isShadowSupported && (target == GL_TEXTURE_2D || target == GL_TEXTURE_1D || target == GL_TEXTURE_RECTANGLE || target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_2D_ARRAY_EXT ) && _internalFormatType != SIGNED_INTEGER && _internalFormatType != UNSIGNED_INTEGER) { @@ -1989,7 +1986,7 @@ void Texture::applyTexParameters(GLenum target, State& state) const // if ambient value is 0 - it is default behaviour of GL_ARB_shadow // no need for GL_ARB_shadow_ambient in this case - if (extensions->isShadowAmbientSupported() && _shadow_ambient > 0) + if (extensions->isShadowAmbientSupported && _shadow_ambient > 0) { glTexParameterf(target, TEXTURE_COMPARE_FAIL_VALUE_ARB, _shadow_ambient); } @@ -2019,8 +2016,7 @@ void Texture::applyTexParameters(GLenum target, State& state) const void Texture::computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& inwidth, GLsizei& inheight,GLsizei& numMipmapLevels) const { - const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); int width,height; @@ -2036,8 +2032,8 @@ void Texture::computeRequiredTextureDimensions(State& state, const osg::Image& i } // cap the size to what the graphics hardware can handle. - if (width>extensions->maxTextureSize()) width = extensions->maxTextureSize(); - if (height>extensions->maxTextureSize()) height = extensions->maxTextureSize(); + if (width>extensions->maxTextureSize) width = extensions->maxTextureSize; + if (height>extensions->maxTextureSize) height = extensions->maxTextureSize; inwidth = width; inheight = height; @@ -2081,10 +2077,8 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima OSG_NOTICE<<"glTexImage2D pixelFormat = "<getPixelFormat()<(); // select the internalFormat required for the texture. bool compressed_image = isCompressedInternalFormat((GLenum)image->getPixelFormat()); @@ -2136,7 +2130,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); unsigned int rowLength = image->getRowLength(); - bool useClientStorage = extensions->isClientStorageSupported() && getClientStorageHint(); + bool useClientStorage = extensions->isClientStorageSupported && getClientStorageHint(); if (useClientStorage) { glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE,GL_TRUE); @@ -2200,7 +2194,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima bool useHardwareMipMapGeneration = mipmappingRequired && (!image->isMipmap() && isHardwareMipmapGenerationEnabled(state)); bool useGluBuildMipMaps = mipmappingRequired && (!useHardwareMipMapGeneration && !image->isMipmap()); - GLBufferObject* pbo = image->getOrCreateGLBufferObject(contextID); + GLBufferObject* pbo = image->getOrCreateGLBufferObject(state.getContextID()); if (pbo && !needImageRescale && !useGluBuildMipMaps) { state.bindPixelBufferObject(pbo); @@ -2261,7 +2255,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima int width = inwidth; int height = inheight; - bool useTexStorrage = extensions->isTexStorageEnabled(); + bool useTexStorrage = extensions->isTextureStorageEnabled; GLenum sizedInternalFormat = 0; if(useTexStorrage) @@ -2491,7 +2485,7 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image* // get the contextID (user defined ID of 0 upwards) for the // current OpenGL context. const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); // select the internalFormat required for the texture. bool compressed_image = isCompressedInternalFormat((GLenum)image->getPixelFormat()); @@ -2678,9 +2672,9 @@ bool Texture::isHardwareMipmapGenerationEnabled(const State& state) const if (_useHardwareMipMapGeneration) { unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); - if (extensions->isGenerateMipMapSupported()) + if (extensions->isGenerateMipMapSupported) { return true; } @@ -2705,11 +2699,12 @@ Texture::GenerateMipmapMode Texture::mipmapBeforeTexImage(const State& state, bo #else FBOExtensions* fbo_ext = FBOExtensions::instance(state.getContextID(),true); + const GL2Extensions* tex_ext = state.get(); bool useGenerateMipMap = fbo_ext->isSupported() && fbo_ext->glGenerateMipmap; if (useGenerateMipMap) { - if (Texture::getExtensions(state.getContextID(),true)->getPreferGenerateMipmapSGISForPowerOfTwo()) + if (tex_ext->preferGenerateMipmapSGISForPowerOfTwo) { int width = getTextureWidth(); int height = getTextureHeight(); @@ -2823,6 +2818,7 @@ void Texture::releaseGLObjects(State* state) const } } +#if 0 Texture::Extensions* Texture::getExtensions(unsigned int contextID,bool createIfNotInitalized) { if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); @@ -2960,6 +2956,6 @@ Texture::Extensions::Extensions(unsigned int contextID) OSG_DEBUG<<"Texture::Extensions::Extensionts() _isTextureStorageEnabled = "<<_isTextureStorageEnabled<data()) return; - // get the contextID (user defined ID of 0 upwards) for the - // current OpenGL context. - const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); - + // get extension object + const GL2Extensions* extensions = state.get(); // compute the internal texture format, this set the _internalFormat to an appropriate value. computeInternalFormat(); @@ -290,10 +287,10 @@ void Texture1D::applyTexImage1D(GLenum target, Image* image, State& state, GLsiz bool compressed = isCompressedInternalFormat(_internalFormat); //Rescale if resize hint is set or NPOT not supported or dimension exceeds max size - if( _resizeNonPowerOfTwoHint || !extensions->isNonPowerOfTwoTextureSupported(_min_filter) || inwidth > extensions->maxTextureSize() ) + if( _resizeNonPowerOfTwoHint || !extensions->isNonPowerOfTwoTextureSupported(_min_filter) || inwidth > extensions->maxTextureSize ) { // this is not thread safe... should really create local image data and rescale to that as per Texture2D. - image->ensureValidSizeForTexturing(extensions->maxTextureSize()); + image->ensureValidSizeForTexturing(extensions->maxTextureSize); } glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 20597738e..30a5fea6c 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -225,10 +225,10 @@ void Texture2DArray::apply(State& state) const ElapsedTime elapsedTime(&(tom->getApplyTime())); tom->getNumberApplied()++; - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); // if not supported, then return - if (!extensions->isTexture2DArraySupported() || !extensions->isTexture3DSupported()) + if (!extensions->isTexture2DArraySupported || !extensions->isTexture3DSupported) { OSG_WARN<<"Warning: Texture2DArray::apply(..) failed, 2D texture arrays are not support by OpenGL driver."<(); // source images have no mipmamps but we could generate them... if( _min_filter != LINEAR && _min_filter != NEAREST && !_images[0]->isMipmap() && - _useHardwareMipMapGeneration && texExtensions->isGenerateMipMapSupported() ) + _useHardwareMipMapGeneration && extensions->isGenerateMipMapSupported ) { _numMipmapLevels = Image::computeNumberOfMipmapLevels( _textureWidth, _textureHeight ); generateMipmap( state ); @@ -434,9 +434,7 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL // get the contextID (user defined ID of 0 upwards) for the // current OpenGL context. - const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); - const Texture::Extensions* texExtensions = Texture::getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); GLenum target = GL_TEXTURE_2D_ARRAY_EXT; // compute the internal texture format, this set the _internalFormat to an appropriate value. @@ -447,7 +445,7 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL bool compressed_image = isCompressedInternalFormat((GLenum)image->getPixelFormat()); // if the required layer is exceeds the maximum allowed layer sizes - if (indepth > extensions->maxLayerCount()) + if (indepth > extensions->maxLayerCount) { // we give a warning and do nothing OSG_WARN<<"Warning: Texture2DArray::applyTexImage2DArray_subload(..) the given layer number exceeds the maximum number of supported layers."<isNonPowerOfTwoTextureSupported(_min_filter) - || inwidth > extensions->max2DSize() - || inheight > extensions->max2DSize()) - image->ensureValidSizeForTexturing(extensions->max2DSize()); + if( _resizeNonPowerOfTwoHint || !extensions->isNonPowerOfTwoTextureSupported(_min_filter) + || inwidth > extensions->max2DSize + || inheight > extensions->max2DSize) + image->ensureValidSizeForTexturing(extensions->max2DSize); // image size or format has changed, this is not allowed, hence return if (image->s()!=inwidth || @@ -475,7 +473,7 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL #endif bool useHardwareMipmapGeneration = - !image->isMipmap() && _useHardwareMipMapGeneration && texExtensions->isGenerateMipMapSupported(); + !image->isMipmap() && _useHardwareMipMapGeneration && extensions->isGenerateMipMapSupported; // if no special mipmapping is required, then if( _min_filter == LINEAR || _min_filter == NEAREST || useHardwareMipmapGeneration ) @@ -584,7 +582,7 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL void Texture2DArray::copyTexSubImage2DArray(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height ) { const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID); @@ -616,7 +614,7 @@ void Texture2DArray::allocateMipmap(State& state) const if (textureObject && _textureWidth != 0 && _textureHeight != 0 && _textureDepth != 0) { - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); int safeSourceFormat = _sourceFormat ? _sourceFormat : _internalFormat; @@ -674,133 +672,3 @@ void Texture2DArray::allocateMipmap(State& state) const state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); } } - -typedef buffered_value< ref_ptr > BufferedExtensions; -static BufferedExtensions s_extensions; - -Texture2DArray::Extensions* Texture2DArray::getExtensions(unsigned int contextID,bool createIfNotInitalized) -{ - if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID); - return s_extensions[contextID].get(); -} - -void Texture2DArray::setExtensions(unsigned int contextID,Extensions* extensions) -{ - s_extensions[contextID] = extensions; -} - -Texture2DArray::Extensions::Extensions(unsigned int contextID) -{ - setupGLExtensions(contextID); -} - -Texture2DArray::Extensions::Extensions(const Extensions& rhs): - Referenced() -{ - _isTexture3DSupported = rhs._isTexture3DSupported; - _isTexture2DArraySupported = rhs._isTexture2DArraySupported; - - _max2DSize = rhs._max2DSize; - _maxLayerCount = rhs._maxLayerCount; - - _glTexImage3D = rhs._glTexImage3D; - _glTexSubImage3D = rhs._glTexSubImage3D; - _glCopyTexSubImage3D = rhs._glCopyTexSubImage3D; - _glCompressedTexImage3D = rhs._glCompressedTexImage3D; - _glCompressedTexSubImage3D = rhs._glCompressedTexSubImage3D;; -} - -void Texture2DArray::Extensions::lowestCommonDenominator(const Extensions& rhs) -{ - if (!rhs._isTexture3DSupported) _isTexture3DSupported = false; - if (!rhs._isTexture2DArraySupported) _isTexture2DArraySupported = false; - if (rhs._max2DSize<_max2DSize) _max2DSize = rhs._max2DSize; - if (rhs._maxLayerCount<_maxLayerCount) _maxLayerCount = rhs._maxLayerCount; - - if (!rhs._glTexImage3D) _glTexImage3D = 0; - if (!rhs._glTexSubImage3D) _glTexSubImage3D = 0; - if (!rhs._glCompressedTexImage3D) _glTexImage3D = 0; - if (!rhs._glCompressedTexSubImage3D) _glTexSubImage3D = 0; - if (!rhs._glCopyTexSubImage3D) _glCopyTexSubImage3D = 0; -} - -void Texture2DArray::Extensions::setupGLExtensions(unsigned int contextID) -{ - _isTexture3DSupported = OSG_GL3_FEATURES || - isGLExtensionSupported(contextID,"GL_EXT_texture3D") || - strncmp((const char*)glGetString(GL_VERSION),"1.2",3)>=0; - - _isTexture2DArraySupported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_EXT_texture_array"); - - _max2DSize = 0; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_max2DSize); - _maxLayerCount = 0; - glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS_EXT, &_maxLayerCount); - - setGLExtensionFuncPtr(_glTexImage3D, "glTexImage3D","glTexImage3DEXT"); - setGLExtensionFuncPtr(_glTexSubImage3D, "glTexSubImage3D","glTexSubImage3DEXT"); - setGLExtensionFuncPtr(_glCompressedTexImage3D, "glCompressedTexImage3D","glCompressedTexImage3DARB"); - setGLExtensionFuncPtr(_glCompressedTexSubImage3D, "glCompressedTexSubImage3D","glCompressedTexSubImage3DARB"); - setGLExtensionFuncPtr(_glCopyTexSubImage3D, "glCopyTexSubImage3D","glCopyTexSubImage3DEXT"); -} - -void Texture2DArray::Extensions::glTexImage3D( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels) const -{ - if (_glTexImage3D) - { - _glTexImage3D( target, level, internalFormat, width, height, depth, border, format, type, pixels); - } - else - { - OSG_WARN<<"Error: glTexImage3D not supported by OpenGL driver"<isTextureMultisampledSupported()) + const GL2Extensions* extensions = state.get(); + if (!extensions->isTextureMultisampledSupported) { OSG_INFO<<"Texture2DMultisample not supoorted."<(); int width,height,depth; - if( !_resizeNonPowerOfTwoHint && texExtensions->isNonPowerOfTwoTextureSupported(_min_filter) ) + if( !_resizeNonPowerOfTwoHint && extensions->isNonPowerOfTwoTextureSupported(_min_filter) ) { width = image.s(); height = image.t(); @@ -161,15 +159,15 @@ void Texture3D::computeRequiredTextureDimensions(State& state, const osg::Image& } // cap the size to what the graphics hardware can handle. - if (width>extensions->maxTexture3DSize()) width = extensions->maxTexture3DSize(); - if (height>extensions->maxTexture3DSize()) height = extensions->maxTexture3DSize(); - if (depth>extensions->maxTexture3DSize()) depth = extensions->maxTexture3DSize(); + if (width>extensions->maxTexture3DSize) width = extensions->maxTexture3DSize; + if (height>extensions->maxTexture3DSize) height = extensions->maxTexture3DSize; + if (depth>extensions->maxTexture3DSize) depth = extensions->maxTexture3DSize; inwidth = width; inheight = height; indepth = depth; - bool useHardwareMipMapGeneration = !image.isMipmap() && _useHardwareMipMapGeneration && texExtensions->isGenerateMipMapSupported(); + bool useHardwareMipMapGeneration = !image.isMipmap() && _useHardwareMipMapGeneration && extensions->isGenerateMipMapSupported; if( _min_filter == LINEAR || _min_filter == NEAREST || useHardwareMipMapGeneration ) { @@ -210,9 +208,9 @@ void Texture3D::apply(State& state) const ElapsedTime elapsedTime(&(tom->getApplyTime())); tom->getNumberApplied()++; - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); - if (!extensions->isTexture3DSupported()) + if (!extensions->isTexture3DSupported) { OSG_WARN<<"Warning: Texture3D::apply(..) failed, 3D texturing is not support by OpenGL driver."<isNonPowerOfTwoTextureSupported(_min_filter) - || inwidth > extensions->maxTexture3DSize() - || inheight > extensions->maxTexture3DSize() - || indepth > extensions->maxTexture3DSize() ) - image->ensureValidSizeForTexturing(extensions->maxTexture3DSize()); + if( _resizeNonPowerOfTwoHint || !extensions->isNonPowerOfTwoTextureSupported(_min_filter) + || inwidth > extensions->maxTexture3DSize + || inheight > extensions->maxTexture3DSize + || indepth > extensions->maxTexture3DSize ) + image->ensureValidSizeForTexturing(extensions->maxTexture3DSize); glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) glPixelStorei(GL_UNPACK_ROW_LENGTH,image->getRowLength()); #endif - bool useHardwareMipMapGeneration = !image->isMipmap() && _useHardwareMipMapGeneration && texExtensions->isGenerateMipMapSupported(); + bool useHardwareMipMapGeneration = !image->isMipmap() && _useHardwareMipMapGeneration && extensions->isGenerateMipMapSupported; if( _min_filter == LINEAR || _min_filter == NEAREST || useHardwareMipMapGeneration ) { @@ -489,7 +486,7 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz void Texture3D::copyTexSubImage3D(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height ) { const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID); @@ -523,7 +520,7 @@ void Texture3D::allocateMipmap(State& state) const if (textureObject && _textureWidth != 0 && _textureHeight != 0 && _textureDepth != 0) { - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); // bind texture textureObject->bind(); @@ -563,6 +560,7 @@ void Texture3D::allocateMipmap(State& state) const } } +#if 0 typedef buffered_value< ref_ptr > BufferedExtensions; static BufferedExtensions s_extensions; @@ -630,3 +628,4 @@ void Texture3D::Extensions::setupGLExtensions(unsigned int contextID) setGLExtensionFuncPtr(glCopyTexSubImage3D,"glCopyTexSubImage3D","glCopyTexSubImage3DEXT"); } +#endif diff --git a/src/osg/TextureBuffer.cpp b/src/osg/TextureBuffer.cpp index 7977c6b1b..f9061a4c7 100644 --- a/src/osg/TextureBuffer.cpp +++ b/src/osg/TextureBuffer.cpp @@ -106,7 +106,7 @@ void TextureBuffer::apply(State& state) const TextureObject* textureObject = getTextureObject(contextID); TextureBufferObject* textureBufferObject = _textureBufferObjects[contextID].get(); - + if (textureObject) { @@ -118,11 +118,11 @@ void TextureBuffer::apply(State& state) const textureBufferObject->unbindBuffer(GL_TEXTURE_BUFFER_ARB); _modifiedCount[contextID] = _image->getModifiedCount(); } - textureObject->bind(); - + textureObject->bind(); + if( getTextureParameterDirty(contextID) ) { - const Extensions* extensions = Texture::getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); if (extensions->isBindImageTextureSupported() && _imageAttachment.access!=0) { extensions->glBindImageTexture( @@ -138,11 +138,11 @@ void TextureBuffer::apply(State& state) const textureObject = generateTextureObject(this, contextID,GL_TEXTURE_BUFFER_ARB); _textureObjectBuffer[contextID] = textureObject; textureObject->bind(); - + textureBufferObject = new TextureBufferObject(contextID,_usageHint); _textureBufferObjects[contextID] = textureBufferObject; - - const Extensions* extensions = Texture::getExtensions(contextID,true); + + const GL2Extensions* extensions = state.get(); if (extensions->isBindImageTextureSupported() && _imageAttachment.access!=0) { extensions->glBindImageTexture( @@ -151,17 +151,17 @@ void TextureBuffer::apply(State& state) const _imageAttachment.format!=0 ? _imageAttachment.format : _internalFormat); } getTextureParameterDirty(state.getContextID()) = false; - + computeInternalFormat(); _textureWidth = _image->s(); textureBufferObject->bindBuffer(GL_TEXTURE_BUFFER_ARB); textureBufferObject->bufferData( _image.get() ); textureObject->setAllocated(true); textureBufferObject->unbindBuffer(GL_TEXTURE_BUFFER_ARB); - + textureObject->bind(); textureBufferObject->texBuffer(_internalFormat); - + _modifiedCount[contextID] = _image->getModifiedCount(); } else @@ -176,14 +176,14 @@ void TextureBuffer::apply(State& state) const void TextureBuffer::bindBufferAs( unsigned int contextID, GLuint target ) { - TextureBufferObject* textureBufferObject = _textureBufferObjects[contextID].get(); + TextureBufferObject* textureBufferObject = _textureBufferObjects[contextID].get(); textureBufferObject->bindBuffer(target); - + } void TextureBuffer::unbindBufferAs( unsigned int contextID, GLuint target ) { - TextureBufferObject* textureBufferObject = _textureBufferObjects[contextID].get(); + TextureBufferObject* textureBufferObject = _textureBufferObjects[contextID].get(); textureBufferObject->unbindBuffer(target); } diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index 799fb60b4..f2f57f091 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -308,7 +308,7 @@ void TextureRectangle::applyTexImage_load(GLenum target, Image* image, State& st // get the contextID (user defined ID of 0 upwards) for the // current OpenGL context. const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); // update the modified count to show that it is upto date. getModifiedCount(contextID) = image->getModifiedCount(); @@ -321,7 +321,7 @@ void TextureRectangle::applyTexImage_load(GLenum target, Image* image, State& st glPixelStorei(GL_UNPACK_ROW_LENGTH,image->getRowLength()); #endif - bool useClientStorage = extensions->isClientStorageSupported() && getClientStorageHint(); + bool useClientStorage = extensions->isClientStorageSupported && getClientStorageHint(); if (useClientStorage) { glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE,GL_TRUE); @@ -390,7 +390,7 @@ void TextureRectangle::applyTexImage_subload(GLenum target, Image* image, State& // get the contextID (user defined ID of 0 upwards) for the // current OpenGL context. const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); + const GL2Extensions* extensions = state.get(); // update the modified count to show that it is upto date. diff --git a/src/osgText/Glyph.cpp b/src/osgText/Glyph.cpp index 7faa4d25f..ed80fe62e 100644 --- a/src/osgText/Glyph.cpp +++ b/src/osgText/Glyph.cpp @@ -147,8 +147,8 @@ void GlyphTexture::apply(osg::State& state) const } - const Extensions* extensions = getExtensions(contextID,true); - bool generateMipMapSupported = extensions->isGenerateMipMapSupported(); + const osg::GL2Extensions* extensions = state.get(); + bool generateMipMapSupported = extensions->isGenerateMipMapSupported; // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID);