| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSG_GRAPHICSTHREAD |
|---|
| 15 | #define OSG_GRAPHICSTHREAD 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/OperationThread> |
|---|
| 18 | #include <osg/State> |
|---|
| 19 | |
|---|
| 20 | namespace osg { |
|---|
| 21 | |
|---|
| 22 | class GraphicsContext; |
|---|
| 23 | |
|---|
| 24 | /** GraphicsThread is a helper class for running OpenGL GraphicsOperation within a single thread assigned to a specific GraphicsContext.*/ |
|---|
| 25 | class OSG_EXPORT GraphicsThread : public osg::OperationThread |
|---|
| 26 | { |
|---|
| 27 | public: |
|---|
| 28 | |
|---|
| 29 | GraphicsThread(); |
|---|
| 30 | |
|---|
| 31 | /** Run does the graphics thread run loop.*/ |
|---|
| 32 | virtual void run(); |
|---|
| 33 | }; |
|---|
| 34 | |
|---|
| 35 | struct OSG_EXPORT GraphicsOperation : public Operation |
|---|
| 36 | { |
|---|
| 37 | GraphicsOperation(const std::string& name, bool keep): |
|---|
| 38 | Operation(name,keep) {} |
|---|
| 39 | |
|---|
| 40 | /** Override the standard Operation operator and dynamic cast object to a GraphicsContext, |
|---|
| 41 | * on success call operation()(GraphicsContext*).*/ |
|---|
| 42 | virtual void operator () (Object* object); |
|---|
| 43 | |
|---|
| 44 | virtual void operator () (GraphicsContext* context) = 0; |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | /** SwapBufferOperation calls swap buffers on the GraphicsContext.*/ |
|---|
| 49 | struct OSG_EXPORT SwapBuffersOperation : public GraphicsOperation |
|---|
| 50 | { |
|---|
| 51 | SwapBuffersOperation(): |
|---|
| 52 | GraphicsOperation("SwapBuffers",true) {} |
|---|
| 53 | |
|---|
| 54 | virtual void operator () (GraphicsContext* context); |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | /** BarrierOperation allows one to synchronize multiple GraphicsThreads with each other.*/ |
|---|
| 58 | struct OSG_EXPORT BarrierOperation : public Operation, public OpenThreads::Barrier |
|---|
| 59 | { |
|---|
| 60 | enum PreBlockOp |
|---|
| 61 | { |
|---|
| 62 | NO_OPERATION, |
|---|
| 63 | GL_FLUSH, |
|---|
| 64 | GL_FINISH |
|---|
| 65 | }; |
|---|
| 66 | |
|---|
| 67 | BarrierOperation(int numThreads, PreBlockOp op=NO_OPERATION, bool keep=true): |
|---|
| 68 | Operation("Barrier", keep), |
|---|
| 69 | OpenThreads::Barrier(numThreads), |
|---|
| 70 | _preBlockOp(op) {} |
|---|
| 71 | |
|---|
| 72 | virtual void release(); |
|---|
| 73 | |
|---|
| 74 | virtual void operator () (Object* object); |
|---|
| 75 | |
|---|
| 76 | PreBlockOp _preBlockOp; |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | /** ReleaseContext_Block_MakeCurrentOperation releases the context for another thread to acquire, |
|---|
| 80 | * then blocks waiting for context to be released, once the block is release the context is re-acquired.*/ |
|---|
| 81 | struct OSG_EXPORT ReleaseContext_Block_MakeCurrentOperation : public GraphicsOperation, public RefBlock |
|---|
| 82 | { |
|---|
| 83 | ReleaseContext_Block_MakeCurrentOperation(): |
|---|
| 84 | GraphicsOperation("ReleaseContext_Block_MakeCurrent", false) {} |
|---|
| 85 | |
|---|
| 86 | virtual void release(); |
|---|
| 87 | |
|---|
| 88 | virtual void operator () (GraphicsContext* context); |
|---|
| 89 | }; |
|---|
| 90 | |
|---|
| 91 | struct OSG_EXPORT BlockAndFlushOperation : public GraphicsOperation, public OpenThreads::Block |
|---|
| 92 | { |
|---|
| 93 | BlockAndFlushOperation(); |
|---|
| 94 | |
|---|
| 95 | virtual void release(); |
|---|
| 96 | |
|---|
| 97 | virtual void operator () (GraphicsContext*); |
|---|
| 98 | }; |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | struct OSG_EXPORT FlushDeletedGLObjectsOperation : public GraphicsOperation |
|---|
| 102 | { |
|---|
| 103 | FlushDeletedGLObjectsOperation(double availableTime, bool keep=false); |
|---|
| 104 | |
|---|
| 105 | virtual void operator () (GraphicsContext*); |
|---|
| 106 | |
|---|
| 107 | double _availableTime; |
|---|
| 108 | }; |
|---|
| 109 | |
|---|
| 110 | class OSG_EXPORT RunOperations : public osg::GraphicsOperation |
|---|
| 111 | { |
|---|
| 112 | public: |
|---|
| 113 | |
|---|
| 114 | RunOperations(): |
|---|
| 115 | osg::GraphicsOperation("RunOperation",true) {} |
|---|
| 116 | |
|---|
| 117 | virtual void operator () (osg::GraphicsContext* context); |
|---|
| 118 | |
|---|
| 119 | }; |
|---|
| 120 | |
|---|
| 121 | class OSG_EXPORT EndOfDynamicDrawBlock : public OpenThreads::BlockCount, public osg::State::DynamicObjectRenderingCompletedCallback |
|---|
| 122 | { |
|---|
| 123 | public: |
|---|
| 124 | |
|---|
| 125 | EndOfDynamicDrawBlock(unsigned int); |
|---|
| 126 | |
|---|
| 127 | void completed(osg::State* state); |
|---|
| 128 | |
|---|
| 129 | protected: |
|---|
| 130 | |
|---|
| 131 | ~EndOfDynamicDrawBlock() {} |
|---|
| 132 | }; |
|---|
| 133 | |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | #endif |
|---|