Renamed include/osg/OperationsThread to OperationThread.

Created a new GraphicsThread subclass from OperationThread which allows the
GraphicsContext specific calls to be moved out of the base OperationThread class.

Updated the rest of the OSG to respect these changes.
This commit is contained in:
Robert Osfield
2007-07-12 15:54:45 +00:00
parent 4d7e8b12ae
commit ecf0b58a19
24 changed files with 212 additions and 145 deletions

View File

@@ -91,7 +91,7 @@ SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/Notify
${HEADER_PATH}/Object
${HEADER_PATH}/OccluderNode
${HEADER_PATH}/OperationsThread
${HEADER_PATH}/OperationThread
${HEADER_PATH}/PagedLOD
${HEADER_PATH}/Plane
${HEADER_PATH}/Point
@@ -246,7 +246,7 @@ ADD_LIBRARY(${LIB_NAME}
Notify.cpp
Object.cpp
OccluderNode.cpp
OperationsThread.cpp
OperationThread.cpp
PagedLOD.cpp
Point.cpp
PointSprite.cpp

View File

@@ -313,11 +313,11 @@ void Camera::createCameraThread()
{
if (!_cameraThread)
{
setCameraThread(new OperationsThread);
setCameraThread(new OperationThread);
}
}
void Camera::setCameraThread(OperationsThread* gt)
void Camera::setCameraThread(OperationThread* gt)
{
if (_cameraThread==gt) return;

View File

@@ -472,11 +472,11 @@ void GraphicsContext::createGraphicsThread()
{
if (!_graphicsThread)
{
setGraphicsThread(new OperationsThread);
setGraphicsThread(new GraphicsThread);
}
}
void GraphicsContext::setGraphicsThread(OperationsThread* gt)
void GraphicsContext::setGraphicsThread(GraphicsThread* gt)
{
if (_graphicsThread==gt) return;

View File

@@ -19,6 +19,28 @@
using namespace osg;
using namespace OpenThreads;
GraphicsThread::GraphicsThread()
{
}
void GraphicsThread::run()
{
// make the graphics context current.
GraphicsContext* graphicsContext = dynamic_cast<GraphicsContext*>(_parent.get());
if (graphicsContext)
{
graphicsContext->makeCurrent();
}
OperationThread::run();
if (graphicsContext)
{
graphicsContext->releaseContext();
}
}
struct BlockOperation : public Operation, public Block
{
BlockOperation():

View File

@@ -12,7 +12,7 @@
*/
#include <osg/OperationsThread>
#include <osg/OperationThread>
#include <osg/GraphicsContext>
#include <osg/Notify>
@@ -347,13 +347,6 @@ void OperationThread::removeAllOperations()
void OperationThread::run()
{
// make the graphics context current.
GraphicsContext* graphicsContext = dynamic_cast<GraphicsContext*>(_parent.get());
if (graphicsContext)
{
graphicsContext->makeCurrent();
}
osg::notify(osg::INFO)<<"Doing run "<<this<<" isRunning()="<<isRunning()<<std::endl;
bool firstTime = true;
@@ -403,11 +396,6 @@ void OperationThread::run()
} while (!testCancel() && !_done);
if (graphicsContext)
{
graphicsContext->releaseContext();
}
osg::notify(osg::INFO)<<"exit loop "<<this<<" isRunning()="<<isRunning()<<std::endl;
}

View File

@@ -602,7 +602,7 @@ void DatabasePager::run()
osg::GraphicsContext* gc = osg::GraphicsContext::getCompileContext(*itr);
if (gc)
{
osg::OperationsThread* gt = gc->getGraphicsThread();
osg::GraphicsThread* gt = gc->getGraphicsThread();
if (gt)
{
gt->add(new DatabasePager::CompileOperation(this));

View File

@@ -99,36 +99,6 @@ void TerrainNode::setColorFilter(unsigned int i, Filter filter)
_colorLayers[i].filter = filter;
}
void TerrainNode::addCompileGraphicsContext(osg::GraphicsContext* gc)
{
for(CompileGraphicsContexts::iterator itr = _compileGraphicsContexts.begin();
itr != _compileGraphicsContexts.end();
++itr)
{
if (*itr == gc)
{
return;
}
}
_compileGraphicsContexts.push_back(gc);
}
void TerrainNode::removeCompileGraphicsContext(osg::GraphicsContext* gc)
{
for(CompileGraphicsContexts::iterator itr = _compileGraphicsContexts.begin();
itr != _compileGraphicsContexts.end();
++itr)
{
if (*itr == gc)
{
_compileGraphicsContexts.erase(itr);
return;
}
}
}
osg::BoundingSphere TerrainNode::computeBound() const
{
osg::BoundingSphere bs;

View File

@@ -842,7 +842,7 @@ void RenderStage::draw(osg::RenderInfo& renderInfo,RenderLeaf*& previous)
osg::State* useState = &state;
osg::GraphicsContext* callingContext = state.getGraphicsContext();
osg::GraphicsContext* useContext = callingContext;
osg::OperationsThread* useThread = 0;
osg::OperationThread* useThread = 0;
osg::RenderInfo useRenderInfo(renderInfo);
RenderLeaf* saved_previous = previous;

View File

@@ -1469,11 +1469,11 @@ void Viewer::getCameras(Cameras& cameras, bool onlyActive)
void Viewer::getAllThreads(Threads& threads, bool onlyActive)
{
OperationsThreads operationsThreads;
getOperationsThreads(operationsThreads);
OperationThreads operationThreads;
getOperationThreads(operationThreads);
for(OperationsThreads::iterator itr = operationsThreads.begin();
itr != operationsThreads.end();
for(OperationThreads::iterator itr = operationThreads.begin();
itr != operationThreads.end();
++itr)
{
threads.push_back(*itr);
@@ -1488,7 +1488,7 @@ void Viewer::getAllThreads(Threads& threads, bool onlyActive)
}
void Viewer::getOperationsThreads(OperationsThreads& threads, bool onlyActive)
void Viewer::getOperationThreads(OperationThreads& threads, bool onlyActive)
{
threads.clear();

View File

@@ -22,7 +22,7 @@
#include <osg/Matrixf>
#include <osg/NodeVisitor>
#include <osg/Object>
#include <osg/OperationsThread>
#include <osg/OperationThread>
#include <osg/State>
#include <osg/Stats>
#include <osg/Texture>
@@ -446,19 +446,19 @@ BEGIN_OBJECT_REFLECTOR(osg::Camera)
__void__createCameraThread,
"Create a operation thread for this camera. ",
"");
I_Method1(void, setCameraThread, IN, osg::OperationsThread *, gt,
I_Method1(void, setCameraThread, IN, osg::OperationThread *, gt,
Properties::NON_VIRTUAL,
__void__setCameraThread__OperationsThread_P1,
__void__setCameraThread__OperationThread_P1,
"Assign a operation thread to the camera. ",
"");
I_Method0(osg::OperationsThread *, getCameraThread,
I_Method0(osg::OperationThread *, getCameraThread,
Properties::NON_VIRTUAL,
__OperationsThread_P1__getCameraThread,
__OperationThread_P1__getCameraThread,
"Get the operation thread assigned to this camera. ",
"");
I_Method0(const osg::OperationsThread *, getCameraThread,
I_Method0(const osg::OperationThread *, getCameraThread,
Properties::NON_VIRTUAL,
__C5_OperationsThread_P1__getCameraThread,
__C5_OperationThread_P1__getCameraThread,
"Get the const operation thread assigned to this camera. ",
"");
I_Method1(void, setGraphicsContext, IN, osg::GraphicsContext *, context,
@@ -552,9 +552,9 @@ BEGIN_OBJECT_REFLECTOR(osg::Camera)
I_SimpleProperty(osg::Camera::BufferAttachmentMap &, BufferAttachmentMap,
__BufferAttachmentMap_R1__getBufferAttachmentMap,
0);
I_SimpleProperty(osg::OperationsThread *, CameraThread,
__OperationsThread_P1__getCameraThread,
__void__setCameraThread__OperationsThread_P1);
I_SimpleProperty(osg::OperationThread *, CameraThread,
__OperationThread_P1__getCameraThread,
__void__setCameraThread__OperationThread_P1);
I_SimpleProperty(const osg::Vec4 &, ClearColor,
__C5_Vec4_R1__getClearColor,
__void__setClearColor__C5_Vec4_R1);

View File

@@ -12,8 +12,9 @@
#include <OpenThreads/Mutex>
#include <osg/GraphicsContext>
#include <osg/GraphicsThread>
#include <osg/Object>
#include <osg/OperationsThread>
#include <osg/OperationThread>
#include <osg/State>
#include <osg/Vec4>
@@ -181,19 +182,19 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext)
__void__createGraphicsThread,
"Create a graphics thread to the graphics context, so that the thread handles all OpenGL operations. ",
"");
I_Method1(void, setGraphicsThread, IN, osg::OperationsThread *, gt,
I_Method1(void, setGraphicsThread, IN, osg::GraphicsThread *, gt,
Properties::NON_VIRTUAL,
__void__setGraphicsThread__OperationsThread_P1,
__void__setGraphicsThread__GraphicsThread_P1,
"Assign a graphics thread to the graphics context, so that the thread handles all OpenGL operations. ",
"");
I_Method0(osg::OperationsThread *, getGraphicsThread,
I_Method0(osg::GraphicsThread *, getGraphicsThread,
Properties::NON_VIRTUAL,
__OperationsThread_P1__getGraphicsThread,
__GraphicsThread_P1__getGraphicsThread,
"Get the graphics thread assigned the graphics context. ",
"");
I_Method0(const osg::OperationsThread *, getGraphicsThread,
I_Method0(const osg::GraphicsThread *, getGraphicsThread,
Properties::NON_VIRTUAL,
__C5_OperationsThread_P1__getGraphicsThread,
__C5_GraphicsThread_P1__getGraphicsThread,
"Get the const graphics thread assigned the graphics context. ",
"");
I_Method0(bool, realizeImplementation,
@@ -377,9 +378,9 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::GraphicsContext)
I_SimpleProperty(osg::Operation *, CurrentOperation,
__Operation_P1__getCurrentOperation,
0);
I_SimpleProperty(osg::OperationsThread *, GraphicsThread,
__OperationsThread_P1__getGraphicsThread,
__void__setGraphicsThread__OperationsThread_P1);
I_SimpleProperty(osg::GraphicsThread *, GraphicsThread,
__GraphicsThread_P1__getGraphicsThread,
__void__setGraphicsThread__GraphicsThread_P1);
I_SimpleProperty(osg::RefBlock *, OperationsBlock,
__osg_RefBlock_P1__getOperationsBlock,
0);

View File

@@ -58,6 +58,19 @@ BEGIN_OBJECT_REFLECTOR(osg::BlockAndFlushOperation)
"");
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osg::GraphicsThread)
I_DeclaringFile("osg/GraphicsThread");
I_BaseType(osg::OperationThread);
I_Constructor0(____GraphicsThread,
"",
"");
I_Method0(void, run,
Properties::VIRTUAL,
__void__run,
"Run does the graphics thread run loop. ",
"");
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osg::ReleaseContext_Block_MakeCurrentOperation)
I_DeclaringFile("osg/GraphicsThread");
I_BaseType(osg::Operation);

View File

@@ -11,7 +11,7 @@
#include <osgIntrospection/Attributes>
#include <osg/Object>
#include <osg/OperationsThread>
#include <osg/OperationThread>
// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
@@ -22,7 +22,7 @@
#endif
BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Operation)
I_DeclaringFile("osg/OperationsThread");
I_DeclaringFile("osg/OperationThread");
I_VirtualBaseType(osg::Referenced);
I_Constructor2(IN, const std::string &, name, IN, bool, keep,
____Operation__C5_std_string_R1__bool,
@@ -61,8 +61,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Operation)
__void__setName__C5_std_string_R1);
END_REFLECTOR
TYPE_NAME_ALIAS(std::set< osg::OperationThread * >, osg::OperationQueue::OperationThreads)
BEGIN_OBJECT_REFLECTOR(osg::OperationQueue)
I_DeclaringFile("osg/OperationsThread");
I_DeclaringFile("osg/OperationThread");
I_BaseType(osg::Referenced);
I_Constructor0(____OperationQueue,
"",
@@ -107,13 +109,33 @@ BEGIN_OBJECT_REFLECTOR(osg::OperationQueue)
__void__releaseOperationsBlock,
"Release operations block that is used to block threads that are waiting on an empty operations queue. ",
"");
I_Method0(const osg::OperationQueue::OperationThreads &, getOperationThreads,
Properties::NON_VIRTUAL,
__C5_OperationThreads_R1__getOperationThreads,
"Get the set of OperationThreads that are sharing this OperationQueue. ",
"");
I_ProtectedMethod1(void, addOperationThread, IN, osg::OperationThread *, thread,
Properties::NON_VIRTUAL,
Properties::NON_CONST,
__void__addOperationThread__OperationThread_P1,
"",
"");
I_ProtectedMethod1(void, removeOperationThread, IN, osg::OperationThread *, thread,
Properties::NON_VIRTUAL,
Properties::NON_CONST,
__void__removeOperationThread__OperationThread_P1,
"",
"");
I_SimpleProperty(const osg::OperationQueue::OperationThreads &, OperationThreads,
__C5_OperationThreads_R1__getOperationThreads,
0);
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osg::OperationsThread)
I_DeclaringFile("osg/OperationsThread");
BEGIN_OBJECT_REFLECTOR(osg::OperationThread)
I_DeclaringFile("osg/OperationThread");
I_BaseType(osg::Referenced);
I_BaseType(OpenThreads::Thread);
I_Constructor0(____OperationsThread,
I_Constructor0(____OperationThread,
"",
"");
I_Method1(void, setParent, IN, osg::Object *, parent,
@@ -174,7 +196,7 @@ BEGIN_OBJECT_REFLECTOR(osg::OperationsThread)
I_Method0(void, run,
Properties::VIRTUAL,
__void__run,
"Run does the graphics thread run loop. ",
"Run does the opertion thread run loop. ",
"");
I_Method1(void, setDone, IN, bool, done,
Properties::NON_VIRTUAL,
@@ -206,7 +228,7 @@ BEGIN_OBJECT_REFLECTOR(osg::OperationsThread)
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osg::RefBlock)
I_DeclaringFile("osg/OperationsThread");
I_DeclaringFile("osg/OperationThread");
I_VirtualBaseType(osg::Referenced);
I_BaseType(OpenThreads::Block);
I_Constructor0(____RefBlock,
@@ -214,3 +236,5 @@ BEGIN_OBJECT_REFLECTOR(osg::RefBlock)
"");
END_REFLECTOR
STD_SET_REFLECTOR(std::set< osg::OperationThread * >)

View File

@@ -14,7 +14,7 @@
#include <osg/GraphicsContext>
#include <osg/Group>
#include <osg/Node>
#include <osg/OperationsThread>
#include <osg/OperationThread>
#include <osg/PagedLOD>
#include <osg/State>
#include <osgDB/DatabasePager>

View File

@@ -12,10 +12,9 @@
#include <osg/BoundingSphere>
#include <osg/CopyOp>
#include <osg/GraphicsContext>
#include <osg/NodeVisitor>
#include <osg/Object>
#include <osg/OperationsThread>
#include <osg/OperationThread>
#include <osg/TransferFunction>
#include <osgTerrain/Layer>
#include <osgTerrain/Locator>
@@ -196,30 +195,20 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::TerrainNode)
__bool__getTreatBoundariesToValidDataAsDefaultValue,
"Get whether the TeatBoundariesToValidDataAsDefaultValue hint. ",
"");
I_Method1(void, setOperationsThread, IN, osg::OperationsThread *, operationsThread,
I_Method1(void, setOperationQueue, IN, osg::OperationQueue *, operations,
Properties::NON_VIRTUAL,
__void__setOperationsThread__osg_OperationsThread_P1,
"Set an OperationsThread to do an data initialization and update work. ",
__void__setOperationQueue__osg_OperationQueue_P1,
"Set an OperationQueue to do an data initialization and update work. ",
"");
I_Method0(osg::OperationsThread *, getOperationsThread,
I_Method0(osg::OperationQueue *, getOperationQueue,
Properties::NON_VIRTUAL,
__osg_OperationsThread_P1__getOperationsThread,
"Get the OperationsThread if one is attached, return NULL otherwise. ",
__osg_OperationQueue_P1__getOperationQueue,
"Get the OperationsQueue if one is attached, return NULL otherwise. ",
"");
I_Method0(const osg::OperationsThread *, getOperationsThread,
I_Method0(const osg::OperationQueue *, getOperationsQueue,
Properties::NON_VIRTUAL,
__C5_osg_OperationsThread_P1__getOperationsThread,
"Get the const OperationsThread if one is attached, return NULL otherwise. ",
"");
I_Method1(void, addCompileGraphicsContext, IN, osg::GraphicsContext *, gc,
Properties::NON_VIRTUAL,
__void__addCompileGraphicsContext__osg_GraphicsContext_P1,
"Add a graphics context that should be used to compile/delete OpenGL objects. ",
"");
I_Method1(void, removeCompileGraphicsContext, IN, osg::GraphicsContext *, gc,
Properties::NON_VIRTUAL,
__void__removeCompileGraphicsContext__osg_GraphicsContext_P1,
"Removed a graphics context that should be used to compile/delete OpenGL objects. ",
__C5_osg_OperationQueue_P1__getOperationsQueue,
"Get the const OperationsQueue if one is attached, return NULL otherwise. ",
"");
I_Method0(osg::BoundingSphere, computeBound,
Properties::VIRTUAL,
@@ -247,9 +236,12 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::TerrainNode)
I_SimpleProperty(osgTerrain::Locator *, Locator,
__Locator_P1__getLocator,
__void__setLocator__Locator_P1);
I_SimpleProperty(osg::OperationsThread *, OperationsThread,
__osg_OperationsThread_P1__getOperationsThread,
__void__setOperationsThread__osg_OperationsThread_P1);
I_SimpleProperty(osg::OperationQueue *, OperationQueue,
__osg_OperationQueue_P1__getOperationQueue,
__void__setOperationQueue__osg_OperationQueue_P1);
I_SimpleProperty(const osg::OperationQueue *, OperationsQueue,
__C5_osg_OperationQueue_P1__getOperationsQueue,
0);
I_SimpleProperty(bool, RequiresNormals,
__bool__getRequiresNormals,
__void__setRequiresNormals__bool);

View File

@@ -13,7 +13,7 @@
#include <osg/ArgumentParser>
#include <osg/Camera>
#include <osg/FrameStamp>
#include <osg/OperationsThread>
#include <osg/OperationThread>
#include <osg/Timer>
#include <osgGA/EventQueue>
#include <osgViewer/CompositeViewer>

View File

@@ -15,7 +15,7 @@
#include <osg/Camera>
#include <osg/FrameStamp>
#include <osg/Node>
#include <osg/OperationsThread>
#include <osg/OperationThread>
#include <osg/Timer>
#include <osgViewer/GraphicsWindow>
#include <osgViewer/Viewer>
@@ -36,7 +36,7 @@ TYPE_NAME_ALIAS(std::vector< osg::Camera * >, osgViewer::Viewer::Cameras)
TYPE_NAME_ALIAS(std::vector< OpenThreads::Thread * >, osgViewer::Viewer::Threads)
TYPE_NAME_ALIAS(std::vector< osg::OperationsThread * >, osgViewer::Viewer::OperationsThreads)
TYPE_NAME_ALIAS(std::vector< osg::OperationThread * >, osgViewer::Viewer::OperationThreads)
BEGIN_ENUM_REFLECTOR(osgViewer::Viewer::ThreadingModel)
I_DeclaringFile("osgViewer/Viewer");
@@ -239,9 +239,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Viewer)
__void__getAllThreads__Threads_R1__bool,
"",
"");
I_MethodWithDefaults2(void, getOperationsThreads, IN, osgViewer::Viewer::OperationsThreads &, threads, , IN, bool, onlyActive, true,
I_MethodWithDefaults2(void, getOperationThreads, IN, osgViewer::Viewer::OperationThreads &, threads, , IN, bool, onlyActive, true,
Properties::NON_VIRTUAL,
__void__getOperationsThreads__OperationsThreads_R1__bool,
__void__getOperationThreads__OperationThreads_R1__bool,
"",
"");
I_Method1(void, setRealizeOperation, IN, osg::Operation *, op,
@@ -350,5 +350,5 @@ STD_VECTOR_REFLECTOR(std::vector< OpenThreads::Thread * >)
STD_VECTOR_REFLECTOR(std::vector< osg::Camera * >)
STD_VECTOR_REFLECTOR(std::vector< osg::OperationsThread * >)
STD_VECTOR_REFLECTOR(std::vector< osg::OperationThread * >)