Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoAutoMap.h
1/*=======================================================================
2** VSG_COPYRIGHT_TAG
3**=======================================================================*/
4/*=======================================================================
5** Author : David Beilloin (Aug 2013)
6**=======================================================================*/
7
8#if !defined(_SO_AUTO_MAP_H_)
9#define _SO_AUTO_MAP_H_
10
11#include <Inventor/devices/SoLocalCpuBufferObject.h>
12
48template<typename T>
50{
51public:
52
55 :m_bufferObject(bufferObject)
56 {
57 m_bufferObject->map(&m_cpuBufferObject,accessMode);
58 m_pointer = static_cast<T*>(m_cpuBufferObject.map(accessMode));
59 m_arraySize = bufferObject->getSize()/sizeof(T);
60 }
61
64 {
65 m_cpuBufferObject.unmap();
66 m_bufferObject->unmap(&m_cpuBufferObject);
67 }
68
70 T& operator[](const size_t i)
71 {
72 assert(i<m_arraySize);
73 return (m_pointer[i]);
74 }
75
77 const T& operator[](const size_t i) const
78 {
79 assert(i<m_arraySize);
80 return (m_pointer[i]);
81 }
82
84 size_t getSize() const
85 { return m_arraySize; }
86
87private:
88 // private default constructor to avoid copy by reference
89 SoAutoMap(){}
90
91 // cpu bufferobject to keep track of the current mapping
92 SoLocalCpuBufferObject m_cpuBufferObject;
93
94 // keep track of the source mapped buffer object
95 SoBufferObject* m_bufferObject;
96
97 // keep track of the pointer target of the mapping
98 T* m_pointer;
99
100 // keep track of the buffer size in number of element
101 size_t m_arraySize;
102};
103
104#endif // _SO_AUTO_MAP_H_
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> buffer object ma...
Definition SoAutoMap.h:50
const T & operator[](const size_t i) const
const accessor to T element at index i
Definition SoAutoMap.h:77
T & operator[](const size_t i)
accessor to T element at index i
Definition SoAutoMap.h:70
size_t getSize() const
return the number of T element in the mapped array
Definition SoAutoMap.h:84
~SoAutoMap()
Destructor.
Definition SoAutoMap.h:63
SoAutoMap(SoBufferObject *bufferObject, SoBufferObject::AccessMode accessMode)
Constructor.
Definition SoAutoMap.h:54
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
AccessMode
This enum provides the possible access modes for a mapped buffer object.
virtual void * map(AccessMode accessMode, size_t offset=0, size_t count=SO_BUFFER_SIZE_ALL)
Map the buffer to a system memory address and allows the mapping of a sub part of the buffer object i...
virtual size_t getSize() const
Returns the size, in bytes, of the buffer object.
virtual void unmap()
Unmaps the buffer from CPU address space.