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_CONTEXT_DATA_H_
00034 #define _VRJ_GL_CONTEXT_DATA_H_
00035
00036
00037 #include <vrj/vrjConfig.h>
00038 #include <vector>
00039 #include <vrj/Draw/OGL/GlDrawManager.h>
00040 #include <vrj/Util/Debug.h>
00041 #include <vpr/Thread/TSObjectProxy.h>
00042
00043 namespace vrj
00044 {
00045
00052 class GlContextDataBase
00053 {
00054 protected:
00055 int getCurContext()
00056 {
00057 return GlDrawManager::instance()->getCurrentContext();
00058 }
00059 };
00060
00061
00084 template<class ContextDataType = int>
00085 class GlContextData : private GlContextDataBase
00086 {
00087 public:
00088 GlContextData()
00089 {;}
00090
00098 ContextDataType& operator*()
00099 { return (*getPtrToCur()); }
00100
00108 ContextDataType* operator->()
00109 { return getPtrToCur(); }
00110
00120 std::vector<ContextDataType*>* getDataVector()
00121 {
00122 return &(mThreadSpecificContextData->mContextDataVector);
00123 }
00124
00125 protected:
00128 template<class DataType>
00129 struct ThreadContextData
00130 {
00131 public:
00132 ThreadContextData()
00133 : mContextDataVector()
00134 {;}
00135
00136
00137 void checkSize(unsigned requiredSize)
00138 {
00139 if(requiredSize > mContextDataVector.size())
00140 {
00141 mContextDataVector.reserve(requiredSize);
00142 while(mContextDataVector.size() < requiredSize)
00143 { mContextDataVector.push_back(new DataType()); }
00144 }
00145 }
00146
00147 std::vector<DataType*> mContextDataVector;
00148 };
00149
00150
00158 ContextDataType* getPtrToCur()
00159 {
00160
00161 int context_id = getCurContext();
00162 ThreadContextData<ContextDataType>* thread_specific_context_data = &(*mThreadSpecificContextData);
00163
00164 thread_specific_context_data->checkSize(context_id+1);
00165
00166 return thread_specific_context_data->mContextDataVector[context_id];
00167 }
00168
00169 private:
00170 vpr::TSObjectProxy<ThreadContextData<ContextDataType> > mThreadSpecificContextData;
00171 };
00172
00173 }
00174
00175 #endif