Classes | Enumerator | Functions | Variables

Wavepacket OpenGL Threading
[Wavepacket Glut Library Wrapper]


Threading in OpenGL is non-trivial! Just do some internet searches for "OpenGL multithreading context" and you'll see what I mean. More...

Collaboration diagram for Wavepacket OpenGL Threading:

Classes

class  glut::Task
 Create one of these (you'll have to inherit) if you have openGL work you need to submit to requestTask(). More...

Functions

void glut::fcolor_t::clear (void) throw ()
bool glut::fcolor_t::isValid (void) const throw ()
 glut::fcolor_t::operator float * (void) throw ()
 glut::fcolor_t::operator const float * (void) const throw ()
virtual glut::Host::~Host (void) throw ()
virtual void glut::Host::init (void)
 Called once, at initialization (just before main glut loop).
virtual eBehavior glut::Host::tick (void)
 Called on every glut idle event.
virtual void glut::Host::display (int w, int h)
 Called for every display frame.
virtual eBehavior glut::Host::mouseMove (int x, int y)
 Called on mouse motion (see glutPassiveMotionFunc()).
virtual eBehavior glut::Host::mouseButton (int button, int state, int x, int y)
 Called on mouse button events (see glutMouseFunc()).
virtual eBehavior glut::Host::keyboard (int key, int mods)
 Called on keyboard events.
virtual eBehavior glut::Host::specialKey (int key, int mods)
 Called when a special key is pressed (see glutSpecialFunc()).
virtual int glut::Host::shutdown (void)
 Called only once, at glut shutdown.
virtual void glut::Task::doTask (void)=0
 here is where the implementer can do any OpenGL-specific work
void glut::requestTask (Task *task)
 Here a thread can request that a task be handled by the open GL thread.
void glut::drawRectLines (const rect3d_t &r,const glut_color_t &c) throw ()
 draw the outline of a 3D rectangle
void glut::getModelViewMatrix (matrix4_t &T) throw ()
 get a 4x4 matrix from the given OpenGL matrix

Variables

float glut::fcolor_t::red
float glut::fcolor_t::green
float glut::fcolor_t::blue
float glut::fcolor_t::alpha

Detailed Description


Threading in OpenGL is non-trivial! Just do some internet searches for "OpenGL multithreading context" and you'll see what I mean.


In general, OpenGL isn't easy to use in a multithreaded way. It can be done, but for most purposes, diving into OpenGL contexts is probably overkill. However, by default OpenGL isn't thread-friendly, so some sort of synchronization is required.


This library uses multithreading in OpenGL in a very basic way: a single thread is doing all of the rendering, but background threads occasionally kick in and need to load and set up textures, etc.

When a thread needs to do some open-GL specific work (that is, any time it needs to call OpenGL or glut APIs!) it should request that as a task. If the calling thread is not the OpenGL thread, the call (requestTask()) will block until the OpenGL thread gets to it. If the thread is the OpenGL thread, then the task executes right away.


Function Documentation

void glut::fcolor_t::clear ( void   )  throw () [inline, inherited]

Definition at line 77 of file glut.h.

bool glut::fcolor_t::isValid ( void   )  const throw () [inline, inherited]

Definition at line 81 of file glut.h.

glut::fcolor_t::operator float * ( void   )  throw () [inline, inherited]

Definition at line 87 of file glut.h.

glut::fcolor_t::operator const float * ( void   )  const throw () [inline, inherited]

Definition at line 90 of file glut.h.

glut::Host::~Host ( void   )  throw () [virtual, inherited]

Definition at line 46 of file glut.cpp.

virtual void glut::Host::init ( void   )  [inline, virtual, inherited]

Called once, at initialization (just before main glut loop).

Definition at line 122 of file glut.h.

virtual eBehavior glut::Host::tick ( void   )  [inline, virtual, inherited]

Called on every glut idle event.

Definition at line 125 of file glut.h.

virtual void glut::Host::display ( int  w,
int  h 
) [inline, virtual, inherited]

Called for every display frame.

Definition at line 128 of file glut.h.

virtual eBehavior glut::Host::mouseMove ( int  x,
int  y 
) [inline, virtual, inherited]

Called on mouse motion (see glutPassiveMotionFunc()).

Definition at line 131 of file glut.h.

virtual eBehavior glut::Host::mouseButton ( int  button,
int  state,
int  x,
int  y 
) [inline, virtual, inherited]

Called on mouse button events (see glutMouseFunc()).

Definition at line 134 of file glut.h.

virtual eBehavior glut::Host::keyboard ( int  key,
int  mods 
) [inline, virtual, inherited]

Called on keyboard events.

Definition at line 139 of file glut.h.

virtual eBehavior glut::Host::specialKey ( int  key,
int  mods 
) [inline, virtual, inherited]

Called when a special key is pressed (see glutSpecialFunc()).

Definition at line 143 of file glut.h.

virtual int glut::Host::shutdown ( void   )  [inline, virtual, inherited]

Called only once, at glut shutdown.

Host can provide program return value (typically zero if no errors).

Definition at line 148 of file glut.h.

virtual void glut::Task::doTask ( void   )  [pure virtual, inherited]

here is where the implementer can do any OpenGL-specific work

void glut::requestTask ( Task *  task  ) 

Here a thread can request that a task be handled by the open GL thread.

Blocks until task is completed! If task throws an exception, the exception will also be thrown back to the caller.

void glut::drawRectLines ( const rect3d_t r,
const glut_color_t c 
) throw ()

draw the outline of a 3D rectangle

void glut::getModelViewMatrix ( matrix4_t T  )  throw ()

get a 4x4 matrix from the given OpenGL matrix


Variable Documentation

float glut::fcolor_t::red [inherited]

Definition at line 95 of file glut.h.

float glut::fcolor_t::green [inherited]

Definition at line 96 of file glut.h.

float glut::fcolor_t::blue [inherited]

Definition at line 97 of file glut.h.

float glut::fcolor_t::alpha [inherited]

Definition at line 98 of file glut.h.