Introduce GraphicsOperation subclass from osg::Operation, and osgUtil::GLObjectOperation

for compiling subgraphs.
This commit is contained in:
Robert Osfield
2007-07-13 17:25:35 +00:00
parent 65156475f6
commit a28588a84c
9 changed files with 99 additions and 57 deletions

View File

@@ -18,6 +18,9 @@
namespace osg {
class GraphicsContext;
/** GraphicsThread is a helper class for running OpenGL GraphicsOperation within a single thread assigned to a specific GraphicsContext.*/
class OSG_EXPORT GraphicsThread : public osg::OperationThread
{
public:
@@ -28,17 +31,30 @@ class OSG_EXPORT GraphicsThread : public osg::OperationThread
virtual void run();
};
struct OSG_EXPORT GraphicsOperation : public Operation
{
GraphicsOperation(const std::string& name, bool keep):
Operation(name,keep) {}
/** Override the standard Operation opertator and dynamic cast object to a GraphicsContext,
* on success call operation()(GraphicsContext*).*/
virtual void operator () (Object* object);
virtual void operator () (GraphicsContext* context) = 0;
};
/** SwapBufferOperation calls swap buffers on the GraphicsContext.*/
struct OSG_EXPORT SwapBuffersOperation : public Operation
struct OSG_EXPORT SwapBuffersOperation : public GraphicsOperation
{
SwapBuffersOperation():
Operation("SwapBuffers",true) {}
GraphicsOperation("SwapBuffers",true) {}
virtual void operator () (Object* context);
virtual void operator () (GraphicsContext* context);
};
/** BarrierOperation allows one to syncronize multiple GraphicsThreads with each other.*/
struct OSG_EXPORT BarrierOperation : public Operation, public OpenThreads::Barrier
struct OSG_EXPORT BarrierOperation : public GraphicsOperation, public OpenThreads::Barrier
{
enum PreBlockOp
{
@@ -48,36 +64,36 @@ struct OSG_EXPORT BarrierOperation : public Operation, public OpenThreads::Barri
};
BarrierOperation(int numThreads, PreBlockOp op=NO_OPERATION):
Operation("Barrier", true),
GraphicsOperation("Barrier", true),
OpenThreads::Barrier(numThreads),
_preBlockOp(op) {}
virtual void release();
virtual void operator () (Object* context);
virtual void operator () (GraphicsContext* context);
PreBlockOp _preBlockOp;
};
/** ReleaseContext_Block_MakeCurrentOperation releases the context for another thread to aquire,
* then blocks waiting for context to be released, once the block is release the context is re-aqquired.*/
struct OSG_EXPORT ReleaseContext_Block_MakeCurrentOperation : public Operation, public RefBlock
struct OSG_EXPORT ReleaseContext_Block_MakeCurrentOperation : public GraphicsOperation, public RefBlock
{
ReleaseContext_Block_MakeCurrentOperation():
Operation("ReleaseContext_Block_MakeCurrent", false) {}
GraphicsOperation("ReleaseContext_Block_MakeCurrent", false) {}
virtual void release();
virtual void operator () (Object* context);
virtual void operator () (GraphicsContext* context);
};
struct OSG_EXPORT BlockAndFlushOperation : public Operation, public OpenThreads::Block
struct OSG_EXPORT BlockAndFlushOperation : public GraphicsOperation, public OpenThreads::Block
{
BlockAndFlushOperation();
virtual void release();
virtual void operator () (Object*);
virtual void operator () (GraphicsContext*);
};
}

View File

@@ -130,7 +130,7 @@ class OSG_EXPORT OperationQueue : public Referenced
OperationThreads _operationThreads;
};
/** GraphicsThread is a helper class for running OpenGL GraphicsOperation within a single thread assigned to a specific GraphicsContext.*/
/** OperationThread is a helper class for running Operation within a single thread.*/
class OSG_EXPORT OperationThread : public Referenced, public OpenThreads::Thread
{
public:

View File

@@ -373,11 +373,11 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
double _minimumTimeAvailableForGLCompileAndDeletePerFrame;
unsigned int _maximumNumOfObjectsToCompilePerFrame;
struct CompileOperation : public osg::Operation
struct CompileOperation : public osg::GraphicsOperation
{
CompileOperation(DatabasePager* databasePager);
virtual void operator () (osg::Object* object);
virtual void operator () (osg::GraphicsContext* context);
osg::observer_ptr<DatabasePager> _databasePager;
};

View File

@@ -113,6 +113,20 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
};
class GLObjectsOperation : public osg::GraphicsOperation
{
public:
GLObjectsOperation(osg::Node* subgraph, GLObjectsVisitor::Mode mode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|GLObjectsVisitor::CHECK_BLACK_LISTED_MODES);
virtual void operator () (osg::GraphicsContext* context);
protected:
osg::ref_ptr<osg::Node> _subgraph;
GLObjectsVisitor::Mode _mode;
};
}
#endif