Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

vrj::GlContextData Class Template Reference

OpenGL helper class that has templatized user context data. More...

#include <GlContextData.h>

Inheritance diagram for vrj::GlContextData:

Inheritance graph
[legend]
Collaboration diagram for vrj::GlContextData:

Collaboration graph
[legend]
List of all members.

Public Methods

 GlContextData ()
ContextDataType & operator * ()
 Returns reference to user data for the current context. More...

ContextDataType * operator-> ()
 Returns reference to user data for the current context. More...

std::vector< ContextDataType * > * getDataVector ()
 This function gives exclusive access to ALL copies of the context-specific data. More...


Protected Methods

ContextDataType * getPtrToCur ()
 Returns a pointer to the correct data element in the current context. More...


Detailed Description

template<class ContextDataType = int>
class vrj::GlContextData< ContextDataType >

OpenGL helper class that has templatized user context data.

This class allows the user to specify a data type that contains data that needs to have a context specific copy. This means that there is a unique copy of the data structure for each openGL context in the current environment. Juggler will take care of the data copies transparently for the user so the user never has to know about the current configuration.

An example use would be a struct full of display list id's. The user passes their user-defined data structure as the template parameter. The resulting object will be a "smart" pointer to the context specific data to use.

Ex:
GlContextData<myStruct> myData;
myData->dlSphere = 0;

Note:
Requires that the type of the context data provide a default constructor used to initialize all of the copies of the data.

Definition at line 85 of file GlContextData.h.


Constructor & Destructor Documentation

template<class ContextDataType = int>
vrj::GlContextData< ContextDataType >::GlContextData   [inline]
 

Definition at line 88 of file GlContextData.h.

00089    {;}


Member Function Documentation

template<class ContextDataType = int>
ContextDataType& vrj::GlContextData< ContextDataType >::operator *   [inline]
 

Returns reference to user data for the current context.

Precondition:
We are in a draw process.
Note:
Should only be called from the draw function. Results are un-defined for other functions.

Definition at line 98 of file GlContextData.h.

00099    { return (*getPtrToCur()); }

template<class ContextDataType = int>
ContextDataType* vrj::GlContextData< ContextDataType >::operator->   [inline]
 

Returns reference to user data for the current context.

Precondition:
We are in a draw process.
Note:
Should only be called from the draw function. Results are un-defined for other functions.

Definition at line 108 of file GlContextData.h.

00109    { return getPtrToCur(); }

template<class ContextDataType = int>
std::vector<ContextDataType*>* vrj::GlContextData< ContextDataType >::getDataVector   [inline]
 

This function gives exclusive access to ALL copies of the context-specific data.

Note:
THIS CAN NOT BE USED IN A DRAW PROCESS OR VERY BAD THINGS WILL HAPPEN. Only for EXPERT use. Needed for casses where something must be done to each copy of the data during pre-draw.

Definition at line 120 of file GlContextData.h.

00121    {
00122       return &(mThreadSpecificContextData->mContextDataVector);
00123    }

template<class ContextDataType = int>
ContextDataType* vrj::GlContextData< ContextDataType >::getPtrToCur   [inline, protected]
 

Returns a pointer to the correct data element in the current context.

Precondition:
We are in the draw function.
Postcondition:
Synchronized.
Note:
ASSERT: Same context is rendered by same thread each time.

Definition at line 158 of file GlContextData.h.

Referenced by vrj::GlContextData< context_data >::operator *, and vrj::GlContextData< context_data >::operator->.

00159    {
00160       // Get current context
00161       int context_id = getCurContext();
00162       ThreadContextData<ContextDataType>* thread_specific_context_data = &(*mThreadSpecificContextData);    // Cache ref for better performance
00163 
00164       thread_specific_context_data->checkSize(context_id+1);     // Make sure we are large enough (+1 since we have index)
00165 
00166       return thread_specific_context_data->mContextDataVector[context_id];
00167    }


The documentation for this class was generated from the following file:
Generated on Sun May 2 15:11:09 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002