vrj::GlPipe Class Reference

Handles the rendering on multiple GLWindows in a single process. More...

#include <vrj/Draw/OGL/GlPipe.h>

Collaboration diagram for vrj::GlPipe:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GlPipe (size_t num, GlDrawManager *glMgr, vpr::Mutex *drawMgrWinLock)
 Constructor.
 ~GlPipe ()
int start ()
 Starts the pipe running.
void controlLoop (void *nullParam)
 The main loop routine.
void stop ()
 Stops the pipe.
void triggerRender ()
 Triggers rendering of the pipe to start.
void completeRender ()
 Blocks until rendering of the windows is completed.
void triggerSwap ()
 Triggers swapping of all pipe's windows.
void completeSwap ()
 Blocks until swapping of the windows is completed.
void addWindow (GlWindow *win)
 Adds a GLWindow to the window list.
void removeWindow (GlWindow *win)
 Removes a GLWindow from the window list.
int hasWindows ()
 Returns true if pipe has any windows.
const std::vector< GlWindow * > & getOpenWindows ()
 Return a list of open windows.

Detailed Description

Handles the rendering on multiple GLWindows in a single process.

This class can be used to group glWindows to render efficiently on one pipe (SGI terminology).

Date:
1-12-98

Definition at line 57 of file GlPipe.h.


Constructor & Destructor Documentation

vrj::GlPipe::GlPipe ( size_t  num,
GlDrawManager glMgr,
vpr::Mutex *  drawMgrWinLock 
) [inline]

Constructor.

Parameters:
num The ID number of the pipe.
glMgr The OpenGL Draw Manager instance associated with this pipe.
drawMgrWinLock Cross-pipe lock associated with the OpenGL Draw Manager to prevent windows from opening simultaneously on different pipes.
Note:
All contained windows SHOULD have the same pipe number.

Definition at line 72 of file GlPipe.h.

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    }

vrj::GlPipe::~GlPipe (  ) 

Definition at line 58 of file GlPipe.cpp.

00059 {
00060    if ( NULL != mActiveThread )
00061    {
00062       delete mActiveThread;
00063       mActiveThread = NULL;
00064    }
00065 
00066    if ( NULL != mControlFunctor )
00067    {
00068       delete mControlFunctor;
00069       mControlFunctor = NULL;
00070    }
00071 }


Member Function Documentation

int vrj::GlPipe::start (  ) 

Starts the pipe running.

Precondition:
The pipe should not have a thread of control yet.
Postcondition:
The pipe has it's own thread of control and is ready to operate The Thread of control is running controlLoop.
Note:
The pipe does NOT have to have any windows in order to run that way we can add windows to pipes at run-time.

Definition at line 77 of file GlPipe.cpp.

References controlLoop(), and vrjDBG_DRAW_MGR().

Referenced by vrj::GlDrawManager::addDisplay().

00078 {
00079     vprASSERT(mThreadRunning == false);        // We should not be running yet
00080 
00081     // Create a new thread to call the control loop
00082     mControlFunctor =
00083       new vpr::ThreadMemberFunctor<GlPipe>(this, &GlPipe::controlLoop, NULL);
00084 
00085     mActiveThread = new vpr::Thread(mControlFunctor);
00086 
00087     vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_CONFIG_LVL)
00088        << "[vrj::GlPipe::start()] Started control loop. " << mActiveThread
00089        << std::endl << vprDEBUG_FLUSH;
00090     return 1;        // XXX: Is this always true?
00091 }

void vrj::GlPipe::controlLoop ( void *  nullParam  ) 

The main loop routine.

-Checks for new windows
-renders all windows when triggered

Definition at line 174 of file GlPipe.cpp.

References vrj::GlDrawManager::getApp(), and vrj::GlApp::pipePreDraw().

Referenced by start().

00175 {
00176    boost::ignore_unused_variable_warning(nullParam);
00177    mThreadRunning = true;     // We are running so set flag
00178    // Loop until flag set
00179    while (!mControlExit)
00180    {
00181       // --- handle EVENTS for the windows --- //
00182       // XXX: This may have to be here because of need to get open window event (Win32)
00183       // otherwise I would like to move it to being after the swap to get better performance
00184       {
00185          for (unsigned int winId=0;winId<mOpenWins.size();winId++)
00186          {
00187             mOpenWins[winId]->checkEvents();
00188          }
00189       }
00190 
00191       // --- RENDER the windows ---- //
00192       {
00193          mRenderTriggerSema.acquire();
00194 
00195          GlApp* the_app = mGlDrawManager->getApp();
00196 
00197          // --- pipe PRE-draw function ---- //
00198          the_app->pipePreDraw();      // Can't get a context since I may not be guaranteed a window
00199 
00200          // Render the windows
00201          for (unsigned int winId = 0 ; winId < mOpenWins.size() ; winId++)
00202          {
00203             renderWindow(mOpenWins[winId]);
00204          }
00205          mRenderCompleteSema.release();
00206       }
00207 
00208       // ----- SWAP the windows ------ //
00209       {
00210          mSwapTriggerSema.acquire();
00211 
00212          // Swap all the windows
00213          for (unsigned int winId = 0 ; winId < mOpenWins.size() ; winId++)
00214          {
00215             swapWindowBuffers(mOpenWins[winId]);
00216          }
00217 
00218          mSwapCompleteSema.release();
00219       }
00220       checkForWindowsToClose();  // Checks for closing windows
00221       checkForNewWindows();      // Checks for new windows to open
00222    }
00223 
00224    mThreadRunning = false;     // We are not running
00225 }

void vrj::GlPipe::stop (  ) 

Stops the pipe.

Postcondition:
Flag is set to tell pipe to stop rendering.

Definition at line 227 of file GlPipe.cpp.

References getOpenWindows(), removeWindow(), triggerRender(), and triggerSwap().

00228 {
00229    // Close all open windows/contexts.
00230    std::vector<GlWindow*> windows = getOpenWindows();
00231    for ( std::vector<GlWindow*>::iterator itr = windows.begin();
00232          itr != windows.end();
00233          ++itr )
00234    {
00235       removeWindow(*itr);
00236    }
00237 
00238    mControlExit = 1;     // Set the control loop exit flag
00239    
00240    // We don't actually need to call completeRender() or completeSwap()
00241    // since we don't care about when they complete. We only care about
00242    // joining the thread
00243    triggerRender();
00244    //completeRender();
00245    triggerSwap();
00246    //completeSwap();
00247 
00248    mActiveThread->join();
00249 }

void vrj::GlPipe::triggerRender (  ) 

Triggers rendering of the pipe to start.

Precondition:
The pipe must have a thread of control.
Postcondition:
The pipe has be told to start rendering.

Definition at line 97 of file GlPipe.cpp.

References vrjDBG_DRAW_MGR().

Referenced by stop().

00098 {
00099    //vprASSERT(mThreadRunning == true);      // We must be running
00100    while (!mThreadRunning)
00101    {
00102       vprDEBUG(vrjDBG_DRAW_MGR,vprDBG_HVERB_LVL) << "Waiting in for thread to start triggerRender.\n" << vprDEBUG_FLUSH;
00103       vpr::Thread::yield();
00104    }
00105 
00106    mRenderTriggerSema.release();
00107 }

void vrj::GlPipe::completeRender (  ) 

Blocks until rendering of the windows is completed.

Precondition:
The pipe must have a thread of control.
Postcondition:
The pipe has completed its rendering.

Definition at line 113 of file GlPipe.cpp.

00114 {
00115    vprASSERT(mThreadRunning == true);      // We must be running
00116 
00117    mRenderCompleteSema.acquire();
00118 }

void vrj::GlPipe::triggerSwap (  ) 

Triggers swapping of all pipe's windows.

Precondition:
The pipe must have a thread of control.
Postcondition:
The pipe has be told to swap.

Definition at line 121 of file GlPipe.cpp.

Referenced by stop().

00122 {
00123    vprASSERT(mThreadRunning == true);
00124    mSwapTriggerSema.release();
00125 }

void vrj::GlPipe::completeSwap (  ) 

Blocks until swapping of the windows is completed.

Precondition:
The pipe must have a thread of control.
Postcondition:
The pipe has completed its rendering.

Definition at line 128 of file GlPipe.cpp.

00129 {
00130    vprASSERT(mThreadRunning == true);
00131    mSwapCompleteSema.acquire();
00132 }

void vrj::GlPipe::addWindow ( GlWindow win  ) 

Adds a GLWindow to the window list.

Control loop must now open the window on the next frame.

Definition at line 139 of file GlPipe.cpp.

References vrjDBG_DRAW_MGR().

Referenced by vrj::GlDrawManager::addDisplay().

00140 {
00141    vpr::Guard<vpr::Mutex> guardNew(mNewWinLock);       // Protect the data
00142    vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00143       << "[vrj::GlPipe::addWindow()] Pipe: " << mPipeNum
00144       << " adding window (to new wins):\n" << win
00145       << std::endl << vprDEBUG_FLUSH;
00146    mNewWins.push_back(win);
00147 }

void vrj::GlPipe::removeWindow ( GlWindow win  ) 

Removes a GLWindow from the window list.

Note:
The window is not actually removed until the next draw trigger.

Definition at line 153 of file GlPipe.cpp.

References vrjDBG_DRAW_MGR().

Referenced by vrj::GlDrawManager::removeDisplay(), and stop().

00154 {
00155    vpr::Guard<vpr::Mutex> guardClosing(mClosingWinLock);
00156    vprDEBUG(vrjDBG_DRAW_MGR, vprDBG_STATE_LVL)
00157       << "[vrj::GlPipe::removeWindow()] Pipe: " << mPipeNum
00158       << " window added to closingWins.\n" << win
00159       << std::endl << vprDEBUG_FLUSH;
00160    mClosingWins.push_back(win);
00161 }

int vrj::GlPipe::hasWindows (  )  [inline]

Returns true if pipe has any windows.

Definition at line 157 of file GlPipe.h.

00158    {
00159       return ( (mNewWins.size() > 0) || (mOpenWins.size() > 0));
00160    }

const std::vector<GlWindow*>& vrj::GlPipe::getOpenWindows (  )  [inline]

Return a list of open windows.

Definition at line 163 of file GlPipe.h.

Referenced by stop().

00164    {
00165       return mOpenWins;
00166    }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:58:18 2007 for VR Juggler by  doxygen 1.5.1