00001 #ifndef VRS_TRIANGLESET_H
00002 #define VRS_TRIANGLESET_H
00003
00004 #include <vrs/shape.h>
00005 #include <vrs/container/dictionary.h>
00006 #include <vrs/container/dataiterator.h>
00007 #include <vrs/opengl/bufferobjectgl.h>
00008 #include <vrs/vertexattributemap.h>
00009 #include <vrs/opengl/vertexattributebufferobjectgl.h>
00010 #include <vrs/opengl/vertexattributedatagl.h>
00011 #include <vrs/opengl/vertexattributeindexgl.h>
00012
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 namespace VRS {
00051
00052 class VRS_CORE_API TriangleSet : public Shape {
00053 public:
00054 typedef VertexData<4, float> VD;
00057 TriangleSet(
00058 SO<Iterator<VD> > vertices = NULL,
00059 SO<Iterator<UINT> > indices = NULL
00060 );
00061 TriangleSet(
00062 SO<Iterator<Vector> > vertices,
00063 SO<Iterator<UINT> > indices = NULL
00064 );
00065
00066 void clear();
00069
00073 SO<TriangleSet> copy() const;
00077 SO<DataIterator<VD> > vertices() const;
00079 void copyVertices(const Iterator<VD>* );
00080 void copyVertices(const Iterator<Vector>* );
00083 void setVertices(SO<DataIterator<VD> > vertIter);
00087 SO<DataIterator<VD> > normals() const;
00089 void copyNormals(const Iterator<VD>* );
00090 void copyNormals(const Iterator<Vector>* );
00093 void setNormals(SO<DataIterator<VD> > normalIter);
00097 SO<DataIterator<VD> > colors() const;
00099 void copyColors(const Iterator<VD>* sourceColors );
00100 void copyColors(const Iterator<Color>* sourceColors );
00103 void setColors(SO<DataIterator<VD> > colorIter);
00107 SO<DataIterator<VD> > texCoords(const UINT index) const;
00111 void copyTexCoords(const UINT index, const Iterator<VD>* );
00112 void copyTexCoords(const UINT index, const Iterator<Vector>* );
00116 void setTexCoords(UINT index, SO<DataIterator<VD> > texCoordIter);
00120 SO<DataIterator<UINT> > indices() const;
00125 void copyIndices(const Iterator<UINT>* );
00128 void setIndices(SO<DataIterator<UINT> > indexIter);
00132 SO<DataIterator<UINT> > objectIDs() const;
00135 void copyObjectIDs(const Iterator<UINT>* );
00139 void setObjectIDs(SO<DataIterator<UINT> > objectIdIter);
00143 SO<DataIterator<VD> > vertexData(const ID& vertexDataID) const;
00147 void copyVertexData(
00148 const ID& vertexDataID,
00149 const Iterator<VD>* sourceData
00150
00151
00152 );
00153 void copyVertexData(
00154 const ID& vertexDataID,
00155 const Iterator<Vector>* sourceData
00156
00157
00158 );
00159 void copyVertexData(
00160 const ID& vertexDataID,
00161 const Iterator<Color>* sourceData
00162
00163
00164 );
00168 void setVertexData(const ID& vertexDataID, SO<DataIterator<VD> > iter);
00172 enum VertexDataConfigFlags {
00173 VD_ENABLE_VRAM = 0x1,
00174 VD_ENABLE_SOURCE_ELIMINATION = 0x2,
00175 VD_CONFIG_MASK = VD_ENABLE_SOURCE_ELIMINATION | VD_ENABLE_VRAM,
00176
00177 };
00178
00179 void lock(UINT configFlags = VD_ENABLE_VRAM);
00181 void lock(const ID& vertexDataID, UINT configFlags = VD_ENABLE_VRAM);
00183 void lockIndices(UINT configFlags = VD_ENABLE_VRAM);
00186 void unlock();
00188 void unlock(const ID& vertexDataID);
00190 void unlockIndices();
00193 SO<Iterator<ID> > vertexDataIDs() const;
00196 static UINT maxTexCoordSets();
00197
00198 virtual void setBoundingBox(const Bounds& newBBox);
00199 virtual Bounds boundingBox() const;
00200 virtual void modified();
00201
00202 void reportState(const char* triSetName = NULL);
00205
00206
00207 enum VertexDataStateFlags {
00208 VD_LOCK = 0x4,
00209 VD_LOCKED = 0x8,
00210 VD_UPDATE_ALL = 0x10,
00211 VD_UPDATE_RANGE = 0x20,
00212 VD_DELETE = 0x40,
00213 VD_CUSTOM = 0x80,
00214 VD_UPDATE_MASK = VD_UPDATE_ALL | VD_UPDATE_RANGE,
00215 VD_STATE_MASK = VD_CUSTOM | VD_DELETE | VD_UPDATE_MASK | VD_LOCKED | VD_LOCK
00216 };
00217
00218 VRS_TYPEINFO(TriangleSet, Shape);
00219
00220
00221 protected:
00222 const ID& texCoordIdFromIndex(const UINT index) const;
00223
00224 template<class T>
00225 class VertexDataEntry : public SharedObj {
00226 public:
00227 VertexDataEntry()
00228 : m_data(NULL),
00229 m_bufferObject(NULL),
00230
00231
00232 m_flags(0),
00233 m_numElements(0) {
00234 }
00235
00236 VertexDataEntry(SO<DataIterator<T> > data, UINT numElements)
00237 : m_data(data),
00238 m_bufferObject(NULL),
00239
00240
00241 m_numElements(numElements),
00242 m_flags(VD_UPDATE_ALL) {
00243 }
00244
00245 SO<DataIterator<T> > m_data;
00246 SO<BaseVertexAttributeBufferObjectGL> m_bufferObject;
00247 UINT m_flags;
00248 UINT m_numElements;
00249
00250
00251 };
00252
00253
00254
00255 typedef SO<Dictionary<ID, SO<VertexDataEntry<VD> > > > VertexDataDictionary;
00256 VertexDataDictionary m_vertexData;
00257 SO<VertexDataEntry<UINT> > m_indexDataEntry;
00258 SO<DataIterator<UINT> > m_objectIdData;
00259
00260 UINT m_configFlags;
00261
00262
00263
00264
00265
00266
00267
00268 mutable SO<VertexAttributeDataGL> m_bufferObjectData;
00269 mutable SO<VertexAttributeIndexGL> m_bufferObjectIndex;
00270
00271 mutable Bounds m_bbox;
00272 mutable TransactionNo m_bboxValid;
00273
00274 mutable TransactionNo m_bufferObjectUpdate;
00275
00276 friend class TriangleSetSimplifierGL;
00277
00278 private:
00279 void Init();
00280 };
00281
00282 }
00283
00284 #endif