Added support for using a custom osg::Geometry that attempts to force the OpenGL driver

to download the texture object to graphics card.

Calling IncrementalCompileOperation::assignForceTextureDownloadGeometry() assigns a geometry
to the job.
This commit is contained in:
Robert Osfield 2010-10-13 15:03:02 +00:00
parent ffa75c9c84
commit b55f75111e
2 changed files with 68 additions and 12 deletions

View File

@ -15,6 +15,7 @@
#define OSGUTIL_INCREMENTALCOMPILEOPERATOR
#include <osgUtil/GLObjectsVisitor>
#include <osg/Geometry>
namespace osgUtil {
@ -167,6 +168,16 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
OpenThreads::Mutex* getCompiledMutex() { return &_compiledMutex; }
CompileSets& getCompiled() { return _compiled; }
/** Assign a geometry and associated StateSet than is applied after each texture compile to atttempt to force the OpenGL
* drive to download the texture object to OpenGL graphics card.*/
void assignForceTextureDownloadGeometry();
/** Set the osg::Geometry to apply after each texture compile to atttempt to force the OpenGL
* drive to download the texture object to OpenGL graphics card.*/
void setForceTextureDownloadGeometry(osg::Geometry* geom) { _forceTextureDownloadGeometry = geom; }
osg::Geometry* getForceTextureDownloadGeometry() { return _forceTextureDownloadGeometry.get(); }
const osg::Geometry* getForceTextureDownloadGeometry() const { return _forceTextureDownloadGeometry.get(); }
protected:
virtual ~IncrementalCompileOperation();
@ -174,23 +185,24 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
// forward declare to keep within class namespace
class CollectStateToCompile;
double _targetFrameRate;
double _minimumTimeAvailableForGLCompileAndDeletePerFrame;
unsigned int _maximumNumOfObjectsToCompilePerFrame;
double _flushTimeRatio;
double _conservativeTimeRatio;
double _targetFrameRate;
double _minimumTimeAvailableForGLCompileAndDeletePerFrame;
unsigned int _maximumNumOfObjectsToCompilePerFrame;
double _flushTimeRatio;
double _conservativeTimeRatio;
OpenThreads::Mutex _toCompileMutex;
CompileSets _toCompile;
osg::ref_ptr<osg::Geometry> _forceTextureDownloadGeometry;
OpenThreads::Mutex _toCompileMutex;
CompileSets _toCompile;
OpenThreads::Mutex _compiledMutex;
CompileSets _compiled;
OpenThreads::Mutex _compiledMutex;
CompileSets _compiled;
ContextSet _contexts;
ContextSet _contexts;
};
}
#endif

View File

@ -16,6 +16,8 @@
#include <osg/Notify>
#include <osg/Timer>
#include <osg/GLObjects>
#include <osg/Depth>
#include <osg/ColorMask>
#include <OpenThreads/ScopedLock>
@ -50,6 +52,33 @@ IncrementalCompileOperation::~IncrementalCompileOperation()
{
}
void IncrementalCompileOperation::assignForceTextureDownloadGeometry()
{
osg::Geometry* geometry = new osg::Geometry;
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(0.0f,0.0f,0.0f));
geometry->setVertexArray(vertices);
osg::Vec2Array* texcoords = new osg::Vec2Array;
texcoords->push_back(osg::Vec2(0.0f,0.0f));
geometry->setTexCoordArray(0, texcoords);
geometry->addPrimitiveSet(new osg::DrawArrays(GL_POINTS,0,1));
osg::StateSet* stateset = geometry->getOrCreateStateSet();
stateset->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);
osg::Depth* depth = new osg::Depth;
depth->setWriteMask(false);
stateset->setAttribute(depth);
osg::ColorMask* colorMask = new osg::ColorMask(false,false,false,false);
stateset->setAttribute(colorMask);
_forceTextureDownloadGeometry = geometry;
}
void IncrementalCompileOperation::assignContexts(Contexts& contexts)
{
for(Contexts::iterator itr = contexts.begin();
@ -365,7 +394,22 @@ void IncrementalCompileOperation::operator () (osg::GraphicsContext* context)
while(!cd._textures.empty() &&
osg::Timer::instance()->delta_s(startTick, osg::Timer::instance()->tick()) < compileTime)
{
cd._textures.back()->apply(*renderInfo.getState());
if (_forceTextureDownloadGeometry.get())
{
if (_forceTextureDownloadGeometry->getStateSet())
{
renderInfo.getState()->apply(_forceTextureDownloadGeometry->getStateSet());
}
renderInfo.getState()->applyTextureAttribute(0, cd._textures.back().get());
_forceTextureDownloadGeometry->draw(renderInfo);
}
else
{
cd._textures.back()->apply(*renderInfo.getState());
}
cd._textures.pop_back();
}