00001
00002
00003
00004
00005
00006
00007
00008 #if !defined(_SO_AUTO_MAP_H_)
00009 #define _SO_AUTO_MAP_H_
00010
00011 #include <Inventor/devices/SoLocalCpuBufferObject.h>
00012
00048 template<typename T>
00049 class SoAutoMap
00050 {
00051 public:
00052
00054 SoAutoMap(SoBufferObject* bufferObject, SoBufferObject::AccessMode accessMode)
00055 :m_bufferObject(bufferObject)
00056 {
00057 m_bufferObject->map(&m_cpuBufferObject,accessMode);
00058 m_pointer = static_cast<T*>(m_cpuBufferObject.map(accessMode));
00059 m_arraySize = bufferObject->getSize()/sizeof(T);
00060 }
00061
00063 ~SoAutoMap()
00064 {
00065 m_cpuBufferObject.unmap();
00066 m_bufferObject->unmap(&m_cpuBufferObject);
00067 }
00068
00070 T& operator[](const size_t i)
00071 {
00072 assert(i<m_arraySize);
00073 return (m_pointer[i]);
00074 }
00075
00077 const T& operator[](const size_t i) const
00078 {
00079 assert(i<m_arraySize);
00080 return (m_pointer[i]);
00081 }
00082
00084 size_t getSize() const
00085 { return m_arraySize; }
00086
00087 private:
00088
00089 SoAutoMap(){}
00090
00091
00092 SoLocalCpuBufferObject m_cpuBufferObject;
00093
00094
00095 SoBufferObject* m_bufferObject;
00096
00097
00098 T* m_pointer;
00099
00100
00101 size_t m_arraySize;
00102 };
00103
00104 #endif // _SO_AUTO_MAP_H_
00105