Updates to the flush rendering objects function calls to allow for

managment of amount of time available to do gl delete's.  This control is
required for constant frame rate applications.
This commit is contained in:
Robert Osfield
2003-07-15 21:19:03 +00:00
parent 0c4a66c85e
commit 82008d5ecd
13 changed files with 57 additions and 35 deletions

View File

@@ -304,7 +304,7 @@ class SG_EXPORT Drawable : public Object
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
static void flushDeletedDisplayLists(unsigned int contextID);
static void flushDeletedDisplayLists(unsigned int contextID,double currentTime, double& availableTime);
/** use deleteVertexBufferObject instead of glDeleteList to allow
* OpenGL buffer objects to cached until they can be deleted
@@ -314,7 +314,7 @@ class SG_EXPORT Drawable : public Object
/** flush all the cached vertex buffer objects which need to be deleted
* in the OpenGL context related to contextID.*/
static void flushDeletedVertexBufferObjects(unsigned int contextID);
static void flushDeletedVertexBufferObjects(unsigned int contextID,double currentTime, double& availableTime);
typedef unsigned int AttributeType;

View File

@@ -523,8 +523,12 @@ class SG_EXPORT Texture : public osg::StateAttribute
virtual void addTextureObjectsFrom(Texture& texture);
virtual void deleteTextureObjects(unsigned int contextID,double currentTime);
virtual void flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime);
void setExpiryDelay(double expiryDelay) { _expiryDelay = expiryDelay; }
double getExpiryDelay() const { return _expiryDelay; }
// how long to keep unsed texture objects around for before deleting.
double _expiryDelay;
@@ -536,6 +540,7 @@ class SG_EXPORT Texture : public osg::StateAttribute
static void setTextureObjectManager(TextureObjectManager* tom);
static TextureObjectManager* getTextureObjectManager();
static void flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime);

View File

@@ -54,6 +54,9 @@ class SG_EXPORT Timer {
Timer();
~Timer() {}
static const Timer* instance();
#if defined __DARWIN_OSX__ || defined macintosh
// PJA MAC OSX - inline Tick() pollutes namespace so badly
// we cant compile, due to Carbon.h ...

View File

@@ -188,7 +188,7 @@ class SG_EXPORT VertexProgram : public StateAttribute
/** flush all the cached vertex programs which need to be deleted
* in the OpenGL context related to contextID.*/
static void flushDeletedVertexProgramObjects(unsigned int contextID);
static void flushDeletedVertexProgramObjects(unsigned int contextID,double currentTime, double& availableTime);
virtual void apply(State& state) const;

View File

@@ -80,15 +80,9 @@ class OSGPRODUCER_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseReques
/** Get whether the compilation of rendering objects for specfied graphics context on (true) or off(false).*/
bool getCompileRenderingObjectsForContexID(unsigned int contextID);
/* Set the maximum amount of time available for compile rendering objects. */
void setMaximumTimeForCompilingRenderingObjects(double time) { _maximumTimeForCompiling = time; }
/* Get the maximum amount of time available for compile rendering objects. */
double getMaximumTimeForCompilingRenderingObjects() const { return _maximumTimeForCompiling; }
/** Compile the rendering objects (display lists,texture objects, VBO's) on loaded subgraph.
* note, should only be called from the draw thread.*/
void compileRenderingObjects(osg::State& state);
void compileRenderingObjects(osg::State& state,double& availableTime);
public:
@@ -141,7 +135,6 @@ class OSGPRODUCER_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseReques
double _expiryDelay;
double _maximumTimeForCompiling;
ActiveGraphicsContexts _activeGraphicsContexts;
};

View File

@@ -45,7 +45,7 @@ void Drawable::deleteDisplayList(unsigned int contextID,GLuint globj)
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
void Drawable::flushDeletedDisplayLists(unsigned int contextID)
void Drawable::flushDeletedDisplayLists(unsigned int contextID,double currentTime, double& availableTime)
{
DeletedDisplayListCache::iterator citr = s_deletedDisplayListCache.find(contextID);
if (citr!=s_deletedDisplayListCache.end())
@@ -77,7 +77,7 @@ void Drawable::deleteVertexBufferObject(unsigned int contextID,GLuint globj)
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID)
void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID,double currentTime, double& availableTime)
{
DeletedDisplayListCache::iterator citr = s_deletedVertexBufferObjectCache.find(contextID);
if (citr!=s_deletedVertexBufferObjectCache.end())

View File

@@ -95,7 +95,7 @@ void Texture::TextureObjectManager::addTextureObjectsFrom(Texture& texture)
texture.takeTextureObjects(_textureObjectListMap);
}
void Texture::TextureObjectManager::deleteTextureObjects(unsigned int contextID,double currentTime)
void Texture::TextureObjectManager::flushTextureObjects(unsigned int contextID,double currentTime, double& availbleTime)
{
TextureObjectList& tol = _textureObjectListMap[contextID];
@@ -145,6 +145,10 @@ Texture::TextureObjectManager* Texture::getTextureObjectManager()
return s_textureObjectManager.get();
}
void Texture::flushTextureObjects(unsigned int contextID,double currentTime, double& availbleTime)
{
getTextureObjectManager()->flushTextureObjects(contextID, currentTime, availbleTime);
}
Texture::Texture():
_wrap_s(CLAMP),
@@ -836,7 +840,7 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
size = ((width+3)/4)*((height+3)/4)*blockSize;
state.checkGLErrors("before extensions->glCompressedTexSubImage2D(");
//state.checkGLErrors("before extensions->glCompressedTexSubImage2D(");
extensions->glCompressedTexSubImage2D(target, k,
0, 0,
@@ -845,7 +849,7 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
size,
image->getMipmapData(k));
state.checkGLErrors("after extensions->glCompressedTexSubImage2D(");
//state.checkGLErrors("after extensions->glCompressedTexSubImage2D(");
width >>= 1;
height >>= 1;

View File

@@ -98,7 +98,7 @@ void Texture2D::setImage(Image* image)
void Texture2D::apply(State& state) const
{
state.setReportGLErrors(true);
//state.setReportGLErrors(true);
// get the contextID (user defined ID of 0 upwards) for the
// current OpenGL context.

View File

@@ -24,6 +24,13 @@ using namespace osg;
//
// all the rest of the timer methods are implemented within the header.
const Timer* Timer::instance()
{
static Timer s_timer;
return &s_timer;
}
#ifdef WIN32
#include <sys/types.h>

View File

@@ -34,7 +34,7 @@ void VertexProgram::deleteVertexProgramObject(unsigned int contextID,GLuint hand
}
void VertexProgram::flushDeletedVertexProgramObjects(unsigned int contextID)
void VertexProgram::flushDeletedVertexProgramObjects(unsigned int contextID,double currentTime, double& availableTime)
{
const Extensions* extensions = getExtensions(contextID,true);

View File

@@ -19,8 +19,6 @@ DatabasePager::DatabasePager()
_deleteRemovedSubgraphsInDatabaseThread = true;
_expiryDelay = 1.0;
_maximumTimeForCompiling = 0.005; // 5ms.
}
void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* group)
@@ -464,10 +462,10 @@ bool DatabasePager::getCompileRenderingObjectsForContexID(unsigned int contextID
}
void DatabasePager::compileRenderingObjects(osg::State& state)
void DatabasePager::compileRenderingObjects(osg::State& state, double& availableTime)
{
osg::Timer timer;
const osg::Timer& timer = *osg::Timer::instance();
osg::Timer_t start_tick = timer.tick();
double elapsedTime = 0.0;
@@ -480,18 +478,18 @@ void DatabasePager::compileRenderingObjects(osg::State& state)
// while there are valid databaseRequest's in the to compile list and there is
// sufficient time left compile each databaseRequest's stateset and drawables.
while (databaseRequest.valid() && elapsedTime<_maximumTimeForCompiling)
while (databaseRequest.valid() && elapsedTime<availableTime)
{
DataToCompileMap& dcm = databaseRequest->_dataToCompileMap;
DataToCompile& dtc = dcm[state.getContextID()];
if (!dtc.first.empty() && elapsedTime<_maximumTimeForCompiling)
if (!dtc.first.empty() && elapsedTime<availableTime)
{
// we have StateSet's to compile
StateSetList& sslist = dtc.first;
//std::cout<<"Compiling statesets"<<std::endl;
StateSetList::iterator itr=sslist.begin();
for(;
itr!=sslist.end() && elapsedTime<_maximumTimeForCompiling;
itr!=sslist.end() && elapsedTime<availableTime;
++itr)
{
//std::cout<<" Compiling stateset "<<(*itr).get()<<std::endl;
@@ -501,14 +499,14 @@ void DatabasePager::compileRenderingObjects(osg::State& state)
// remove the compiled stateset from the list.
sslist.erase(sslist.begin(),itr);
}
if (!dtc.second.empty() && elapsedTime<_maximumTimeForCompiling)
if (!dtc.second.empty() && elapsedTime<availableTime)
{
// we have Drawable's to compile
//std::cout<<"Compiling drawables"<<std::endl;
DrawableList& dwlist = dtc.second;
DrawableList::iterator itr=dwlist.begin();
for(;
itr!=dwlist.end() && elapsedTime<_maximumTimeForCompiling;
itr!=dwlist.end() && elapsedTime<availableTime;
++itr)
{
//std::cout<<" Compiling drawable "<<(*itr).get()<<std::endl;
@@ -560,5 +558,7 @@ void DatabasePager::compileRenderingObjects(osg::State& state)
elapsedTime = timer.delta_s(start_tick,timer.tick());
}
availableTime -= elapsedTime;
}

View File

@@ -309,7 +309,9 @@ public:
sh.drawImplementation(camera);
_databasePager->compileRenderingObjects(*(sh.getSceneView()->getState()));
double availableTime = 0.005; // 5 ms
_databasePager->compileRenderingObjects(*(sh.getSceneView()->getState()),availableTime);
}
osg::ref_ptr<DatabasePager> _databasePager;

View File

@@ -14,6 +14,7 @@
#include <osgUtil/UpdateVisitor>
#include <osgUtil/DisplayListVisitor>
#include <osg/Timer>
#include <osg/Notify>
#include <osg/Texture>
#include <osg/VertexProgram>
@@ -536,13 +537,20 @@ void SceneView::draw()
// and texture objects is deferred until the OpenGL context is the correct
// context for when the object were originally created. Here we know what
// context we are in so can flush the appropriate caches.
osg::Drawable::flushDeletedDisplayLists(_state->getContextID());
osg::Drawable::flushDeletedVertexBufferObjects(_state->getContextID());
osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID());
//static osg::Timer timer;
//osg::Timer_t tstart = timer.tick();
double currentTime = _state->getFrameStamp()?_state->getFrameStamp()->getReferenceTime():0.0;
osg::Texture::getTextureObjectManager()->deleteTextureObjects(_state->getContextID(),currentTime);
double availableTime = 0.005; // 5 ms.
osg::Drawable::flushDeletedDisplayLists(_state->getContextID(),currentTime,availableTime);
osg::Drawable::flushDeletedVertexBufferObjects(_state->getContextID(),currentTime,availableTime);
osg::VertexProgram::flushDeletedVertexProgramObjects(_state->getContextID(),currentTime,availableTime);
osg::Texture::flushTextureObjects(_state->getContextID(),currentTime,availableTime);
//osg::Timer_t tend = timer.tick();
//std::cout<<"time to flush rendering objects"<<timer.delta_m(tstart,tend)<<std::endl;
RenderLeaf* previous = NULL;
if (_displaySettings.valid() && _displaySettings->getStereo())