vrj::GlContextData< ContextDataType > Class Template Reference

OpenGL helper class that has templated user context-specific data. More...

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

Inheritance diagram for vrj::GlContextData< ContextDataType >:

Inheritance graph
[legend]
Collaboration diagram for vrj::GlContextData< ContextDataType >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GlContextData ()
ContextDataType & operator * ()
 Returns reference to user data for the current context.
ContextDataType * operator-> ()
 Returns reference to user data for the current context.
std::vector< ContextDataType * > * getDataVector ()
 This function gives exclusive access to ALL copies of the context-specific data for contexts controlled by the current thread.

Protected Member Functions

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

Classes

struct  ThreadContextData
 Container for the thread-specific context-specific data. More...

Detailed Description

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

OpenGL helper class that has templated user context-specific 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.

Examples:

Example of using GL context-specific data.

Definition at line 103 of file GlContextData.h.


Constructor & Destructor Documentation

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

Definition at line 106 of file GlContextData.h.

00107    {;}


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 116 of file GlContextData.h.

00117    {
00118       return (*getPtrToCur());
00119    }

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 128 of file GlContextData.h.

00129    {
00130       return getPtrToCur();
00131    }

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 for contexts controlled by the current thread.

Note:
THIS CAN NOT BE USED IN A DRAW PROCESS OR VERY BAD THINGS WILL HAPPEN. Only for EXPERT use.

Definition at line 140 of file GlContextData.h.

00141    {
00142       return &(mThreadSpecificContextData->mContextDataVector);
00143    }

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 178 of file GlContextData.h.

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

00179    {
00180       // Get current context
00181       int context_id = getCurContext();
00182 
00183       // Cache ref for better performance
00184       ThreadContextData<ContextDataType>* thread_specific_context_data =
00185          &(*mThreadSpecificContextData);
00186 
00187       thread_specific_context_data->checkSize(context_id+1);     // Make sure we are large enough (+1 since we have index)
00188 
00189       return thread_specific_context_data->mContextDataVector[context_id];
00190    }


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