From a7839d77cdf3da9644977a96ab6b2c59e0770182 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 10 Feb 2018 17:50:39 +0000 Subject: [PATCH] Added support for PixelBufferObject to Texture2DArray --- src/osg/Texture2DArray.cpp | 51 ++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index b37051167..ff16ba66d 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -17,6 +17,7 @@ #include +//#define DO_TIMING using namespace osg; @@ -454,6 +455,13 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL if (!imagesValid()) return; +#ifdef DO_TIMING + osg::Timer_t start_tick = osg::Timer::instance()->tick(); + OSG_NOTICE<<"Texture2DArray::applyTexImage2DArray_subload() = "<<(void*)image<(); @@ -494,11 +502,29 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL glPixelStorei(GL_UNPACK_ROW_LENGTH,image->getRowLength()); #endif - bool useHardwareMipmapGeneration = - !image->isMipmap() && _useHardwareMipMapGeneration && extensions->isGenerateMipMapSupported; + bool mipmappingRequired = _min_filter != LINEAR && _min_filter != NEAREST; + bool useHardwareMipMapGeneration = mipmappingRequired && !image->isMipmap(); + unsigned char* dataPtr = (unsigned char*)image->data(); + + GLBufferObject* pbo = image->getOrCreateGLBufferObject(contextID); + if (pbo) + { + state.bindPixelBufferObject(pbo); + dataPtr = reinterpret_cast(pbo->getOffset(image->getBufferIndex())); + + } + else + { + pbo = 0; + } + +#ifdef DO_TIMING + OSG_NOTICE<<" Texture2DArray::applyTexImage2DArray_subload() pbo="<tick(); +#endif // if no special mipmapping is required, then - if( _min_filter == LINEAR || _min_filter == NEAREST || useHardwareMipmapGeneration ) + if( _min_filter == LINEAR || _min_filter == NEAREST || useHardwareMipMapGeneration ) { if( _min_filter == LINEAR || _min_filter == NEAREST ) numMipmapLevels = 1; @@ -508,12 +534,15 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL // upload non-compressed image if ( !compressed_image ) { + //OSG_NOTICE<<"Texture2DArray::applyTexImage2DArray_subload()"<glTexSubImage3D( target, 0, 0, 0, layer, inwidth, inheight, indepth, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), - image->data() ); + dataPtr ); +#endif } // if we support compression and image is compressed, then @@ -529,7 +558,7 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL inwidth, inheight, indepth, (GLenum)image->getPixelFormat(), size, - image->data()); + dataPtr); } // we want to use mipmapping, so enable it @@ -565,7 +594,7 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL width, height, indepth, (GLenum)image->getPixelFormat(), (GLenum)image->getDataType(), - image->getMipmapData(k)); + dataPtr + image->getMipmapOffset(k)); width >>= 1; height >>= 1; @@ -589,7 +618,7 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL width, height, indepth, (GLenum)image->getPixelFormat(), size, - image->getMipmapData(k)); + dataPtr + image->getMipmapOffset(k)); // state.checkGLErrors("after extensions->glCompressedTexSubImage3D("); @@ -600,6 +629,14 @@ void Texture2DArray::applyTexImage2DArray_subload(State& state, Image* image, GL } } + + if (pbo) + { + state.unbindPixelBufferObject(); + } +#ifdef DO_TIMING + OSG_NOTICE<<" Texture2DArray::applyTexImage2DArray_subload() pbo="<