From 717a6dcf147d9244647244a2ac2836610124f117 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 18 Aug 2005 09:36:40 +0000 Subject: [PATCH] Added beginings of GraphicsThread class --- include/osg/GraphicsContext | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index ebe128fc9..a3a1809d5 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -15,8 +15,11 @@ #define OSG_GRAPHICSCONTEXT 1 #include + #include +#include + namespace osg { /** Base class for providing Windowing API agnostic access to creating and managing graphics context.*/ @@ -151,6 +154,8 @@ class OSG_EXPORT GraphicsContext : public Referenced /** Make this graphics context current with specified read context.*/ virtual void makeContextCurrent(GraphicsContext* readContext) = 0; + virtual void releaseContext() = 0; + /** Return true if the current thread has this OpenGL graphics context.*/ inline bool isCurrent() const { return _threadOfLastMakeCurrent == OpenThreads::Thread::CurrentThread(); } @@ -161,6 +166,37 @@ class OSG_EXPORT GraphicsContext : public Referenced /** swap the front and back buffers.*/ virtual void swapBuffers() = 0; + public: + + + struct GraphicsOperation : public Referenced + { + virtual void operator () (GraphicsContext& context) {} + }; + + class GraphicsThread : public Referenced, OpenThreads::Thread + { + public: + GraphicsThread() {} + + typedef std::list< ref_ptr > OperationList; + + void add(GraphicsOperation* operation); + + virtual void run(); + + protected: + virtual ~GraphicsThread() {} + + OpenThreads::Mutex _runListMutex; + OperationList _operations; + + }; + + void setGraphicsThread(GraphicsThread* gt) { _graphicsThread = gt; } + GraphicsThread* getGraphicsThread() { return _graphicsThread.get(); } + const GraphicsThread* getGraphicsThread() const { return _graphicsThread.get(); } + protected: GraphicsContext(); @@ -171,6 +207,8 @@ class OSG_EXPORT GraphicsContext : public Referenced ref_ptr _state; OpenThreads::Thread* _threadOfLastMakeCurrent; + ref_ptr _graphicsThread; + };