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

GlContextData.h

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile: GlContextData.h,v $
00027  * Date modified: $Date: 2003/12/08 14:29:42 $
00028  * Version:       $Revision: 1.35 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #ifndef _VRJ_GL_CONTEXT_DATA_H_
00034 #define _VRJ_GL_CONTEXT_DATA_H_
00035 //#pragma once
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       /* Makes sure that the vector is at least requiredSize large */
00137       void checkSize(unsigned requiredSize)
00138       {
00139          if(requiredSize > mContextDataVector.size())
00140          {
00141             mContextDataVector.reserve(requiredSize);          // Resize smartly
00142             while(mContextDataVector.size() < requiredSize)    // Add any new items needed
00143             {  mContextDataVector.push_back(new DataType()); }
00144          }
00145       }
00146 
00147       std::vector<DataType*> mContextDataVector;   
00148    };
00149 
00150 
00158    ContextDataType* getPtrToCur()
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    }
00168 
00169 private:
00170    vpr::TSObjectProxy<ThreadContextData<ContextDataType> >  mThreadSpecificContextData;
00171 };
00172 
00173 }
00174 
00175 #endif

Generated on Sun May 2 15:10:17 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002