Implementated experimental reuse of PBO's after download

This commit is contained in:
Robert Osfield
2011-02-07 14:19:58 +00:00
parent e0924886bd
commit 4b4754c3cf
5 changed files with 49 additions and 7 deletions

View File

@@ -528,6 +528,14 @@ class OSG_EXPORT BufferObject : public Object
BufferObjectProfile& getProfile() { return _profile; }
const BufferObjectProfile& getProfile() const { return _profile; }
/** Set whether the BufferObject should use a GLBufferObject just for copying the BufferData and release it immmediately so that it may be reused.*/
void setCopyDataAndReleaseGLBufferObject(bool copyAndRelease) { _copyDataAndReleaseGLBufferObject = copyAndRelease; }
/** Get whether the BufferObject should use a GLBufferObject just for copying the BufferData and release it immmediately.*/
bool getCopyDataAndReleaseGLBufferObject() const { return _copyDataAndReleaseGLBufferObject; }
void dirty();
/** Resize any per context GLObject buffers to specified size. */
@@ -572,6 +580,8 @@ class OSG_EXPORT BufferObject : public Object
BufferObjectProfile _profile;
bool _copyDataAndReleaseGLBufferObject;
BufferDataList _bufferDataList;
mutable GLBufferObjects _glBufferObjects;

View File

@@ -39,6 +39,7 @@ class OSGUTIL_EXPORT StateToCompile : public osg::NodeVisitor
TextureSet _textures;
ProgramSet _programs;
bool _assignPBOToImages;
osg::ref_ptr<osg::PixelBufferObject> _pbo;
bool empty() const { return _textures.empty() && _programs.empty() && _drawables.empty(); }
@@ -48,6 +49,7 @@ class OSGUTIL_EXPORT StateToCompile : public osg::NodeVisitor
virtual void apply(osg::Drawable& drawable);
virtual void apply(osg::StateSet& stateset);
virtual void apply(osg::Texture& texture);
};
class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation

View File

@@ -741,7 +741,7 @@ GLBufferObject* GLBufferObjectSet::takeFromOrphans(BufferObject* bufferObject)
// place at back of active list
addToBack(glbo.get());
OSG_INFO<<"Reusing orphaned GLBufferObject, _numOfGLBufferObjects="<<_numOfGLBufferObjects<<std::endl;
//OSG_NOTICE<<"Reusing orphaned GLBufferObject, _numOfGLBufferObjects="<<_numOfGLBufferObjects<<" target="<<std::hex<<_profile._target<<std::dec<<std::endl;
return glbo.release();
}
@@ -1231,12 +1231,14 @@ void GLBufferObject::releaseGLBufferObject(unsigned int contextID, GLBufferObjec
//
// BufferObject
//
BufferObject::BufferObject()
BufferObject::BufferObject():
_copyDataAndReleaseGLBufferObject(false)
{
}
BufferObject::BufferObject(const BufferObject& bo,const CopyOp& copyop):
Object(bo,copyop)
Object(bo,copyop),
_copyDataAndReleaseGLBufferObject(bo._copyDataAndReleaseGLBufferObject)
{
}

View File

@@ -1958,6 +1958,13 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
if (pbo)
{
state.unbindPixelBufferObject();
BufferObject* bo = image->getBufferObject();
if (bo->getCopyDataAndReleaseGLBufferObject())
{
//OSG_NOTICE<<"Release PBO"<<std::endl;
bo->releaseGLObjects(&state);
}
}
#ifdef DO_TIMING

View File

@@ -23,8 +23,9 @@
#include <OpenThreads/ScopedLock>
#include <algorithm>
#include <stdlib.h>
#include <iterator>
#include <stdlib.h>
#include <string.h>
namespace osgUtil
{
@@ -46,6 +47,7 @@ namespace osgUtil
static osg::ApplicationUsageProxy ICO_e1(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MINIMUM_COMPILE_TIME_PER_FRAME <float>","minimum compile time alloted to compiling OpenGL objects per frame in database pager.");
static osg::ApplicationUsageProxy UCO_e2(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAXIMUM_OBJECTS_TO_COMPILE_PER_FRAME <int>","maximum number of OpenGL objects to compile per frame in database pager.");
static osg::ApplicationUsageProxy UCO_e3(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_FORCE_TEXTURE_DOWNLOAD <ON/OFF>","should the texture compiles be forced to download using a dummy Geometry.");
/////////////////////////////////////////////////////////////////
//
@@ -183,7 +185,11 @@ void StateToCompile::apply(osg::Texture& texture)
if (numRequringPBO>0)
{
// assign pbo
if (!pbo) pbo = new osg::PixelBufferObject;
if (!pbo)
{
if (!_pbo) _pbo = new osg::PixelBufferObject;
pbo = _pbo;
}
for(unsigned int i=0; i<texture.getNumImages(); ++i)
{
@@ -193,6 +199,8 @@ void StateToCompile::apply(osg::Texture& texture)
if (!image->getPixelBufferObject())
{
//OSG_NOTICE<<"Assigning PBO"<<std::endl;
//pbo->setCopyDataAndReleaseGLBufferObject(true);
pbo->setUsage(GL_DYNAMIC_DRAW_ARB);
image->setPixelBufferObject(pbo.get());
}
}
@@ -443,7 +451,20 @@ IncrementalCompileOperation::IncrementalCompileOperation():
_maximumNumOfObjectsToCompilePerFrame = atoi(ptr);
}
// assignForceTextureDownloadGeometry();
bool useForceTextureDownload = false;
if( (ptr = getenv("OSG_FORCE_TEXTURE_DOWNLOAD")) != 0)
{
useForceTextureDownload = strcmp(ptr,"yes")==0 || strcmp(ptr,"YES")==0 ||
strcmp(ptr,"on")==0 || strcmp(ptr,"ON")==0;
OSG_NOTICE<<"OSG_FORCE_TEXTURE_DOWNLOAD set to "<<useForceTextureDownload<<std::endl;
}
if (useForceTextureDownload)
{
assignForceTextureDownloadGeometry();
}
}
IncrementalCompileOperation::~IncrementalCompileOperation()
@@ -617,7 +638,7 @@ void IncrementalCompileOperation::mergeCompiledSubgraphs()
void IncrementalCompileOperation::operator () (osg::GraphicsContext* context)
{
osg::NotifySeverity level = osg::INFO;
osg::NotifySeverity level = osg::NOTICE;
double targetFrameRate = _targetFrameRate;
double minimumTimeAvailableForGLCompileAndDeletePerFrame = _minimumTimeAvailableForGLCompileAndDeletePerFrame;