00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _VRJ_GL_PIPE_H_
00034 #define _VRJ_GL_PIPE_H_
00035
00036 #include <vrj/Draw/OGL/Config.h>
00037 #include <vector>
00038
00039 #include <vrj/Draw/OGL/GlWindow.h>
00040 #include <vrj/Draw/OGL/GlDrawManager.h>
00041 #include <vpr/Sync/CondVar.h>
00042 #include <vpr/Sync/Semaphore.h>
00043
00044 namespace vrj
00045 {
00046 class GlDrawManager;
00047
00057 class VJ_OGL_CLASS_API GlPipe
00058 {
00059 public:
00072 GlPipe(size_t num, GlDrawManager* glMgr, vpr::Mutex* drawMgrWinLock)
00073 : mControlFunctor(NULL)
00074 , mActiveThread(NULL)
00075 , mPipeNum(num)
00076 , mControlExit(0)
00077 , mGlDrawManager(glMgr)
00078 , mDrawMgrWinLock(drawMgrWinLock)
00079 , mRenderTriggerSema(0)
00080 , mRenderCompleteSema(0)
00081 , mSwapTriggerSema(0)
00082 , mSwapCompleteSema(0)
00083 {
00084 mThreadRunning = false;
00085 }
00086
00087 ~GlPipe();
00088
00098 int start();
00099
00105 void controlLoop(void* nullParam);
00106
00111 void stop();
00112
00113 public:
00119 void triggerRender();
00120
00126 void completeRender();
00127
00133 void triggerSwap();
00134
00140 void completeSwap();
00141
00142 public:
00143
00148 void addWindow(GlWindow* win);
00149
00154 void removeWindow(GlWindow* win);
00155
00157 int hasWindows()
00158 {
00159 return ( (mNewWins.size() > 0) || (mOpenWins.size() > 0));
00160 }
00161
00163 const std::vector<GlWindow*>& getOpenWindows()
00164 {
00165 return mOpenWins;
00166 }
00167
00168 private:
00174 void checkForNewWindows();
00175
00181 void checkForWindowsToClose();
00182
00187 void renderWindow(GlWindow* win);
00188
00190 void swapWindowBuffers(GlWindow* win);
00191
00196 void finishWindowSetup(GlWindow* win);
00197
00198 GlPipe(const GlPipe&) {;}
00199 void operator=(const GlPipe&) {;}
00200
00201 private:
00202 vpr::ThreadMemberFunctor<GlPipe>* mControlFunctor;
00203 vpr::Thread* mActiveThread;
00204 bool mThreadRunning;
00206 size_t mPipeNum;
00208 std::vector<GlWindow*> mNewWins;
00209 vpr::Mutex mNewWinLock;
00211 std::vector<GlWindow*> mOpenWins;
00212 vpr::Mutex mOpenWinLock;
00214 std::vector<GlWindow*> mClosingWins;
00215 vpr::Mutex mClosingWinLock;
00217 int mControlExit;
00219 GlDrawManager* mGlDrawManager;
00221 vpr::Mutex* mDrawMgrWinLock;
00224 vpr::Semaphore mRenderTriggerSema;
00225 vpr::Semaphore mRenderCompleteSema;
00226 vpr::Semaphore mSwapTriggerSema;
00227 vpr::Semaphore mSwapCompleteSema;
00228 };
00229
00230 }
00231
00232 #endif