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
00034
00035
00036
00037 #ifndef VRS_OPENGL_BATCHTREEGL_H
00038 #define VRS_OPENGL_BATCHTREEGL_H
00039
00040 #include <vrs/polygonset.h>
00041
00042 namespace VRS {
00043
00053
00054 class MappedVertexAttributeShapeGL;
00055 template<typename T> class Iterator;
00056 template<typename T> class FixedSizeIterator;
00057 template<typename K, typename V> class Dictionary;
00058
00059 class VRS_CORE_API BatchTreeGL : public Shape {
00060 public:
00061
00062 BatchTreeGL();
00063
00068 int insertShape(SO<PolygonSet> shape);
00069
00072 SO<Iterator<int> > insertShapes(SO<Iterator<SO<PolygonSet> > > shapes);
00073
00078 bool canBeInserted(SO<PolygonSet> shape) const;
00079
00083 bool removeShape(int index);
00084
00088 bool removeShapes(SO<Iterator<int> > indices);
00089
00090
00097 SO<PolygonSet> extractShape(int index) const;
00098
00100 virtual Bounds boundingBox() const;
00101
00102
00108 unsigned int getMaximumBatchSize() const;
00109 void setMaximumBatchSize(unsigned int size = 5000);
00110
00111
00114 void transformTextureCoords(const Matrix& matrix);
00115
00116
00118 struct Node : public SharedObj {
00119 SO<Node> m_children[2];
00120 SO<Node> m_parent;
00121 Bounds m_bounds;
00122 SO<MappedVertexAttributeShapeGL> m_geometry;
00123 SO<Iterator<int> > m_vertexRanges;
00124 SO<Iterator<int> > m_indexRanges;
00125 SO<Iterator<int> > m_shapeIDs;
00126
00127
00128
00129
00130 int m_numVertices;
00131
00132 VRS_TYPEINFO(Node, SharedObj);
00133 VRS_SERIALIZABLE(Node);
00134 };
00135
00136 VRS_TYPEINFO(BatchTreeGL, Shape);
00137 VRS_SERIALIZABLE(BatchTreeGL);
00138
00139 private:
00140
00141 friend class BatchTreeSimplifierGL;
00142 friend class BatchTreeRayIntersectorGL;
00143
00144
00145
00146
00147
00148
00149
00150 struct VRS_CORE_API ShapeInfo {
00151 SO<Node> m_node;
00152 int m_rangeNumber;
00153 VRS_SERIALIZABLE_NO_SO_CLASS(ShapeInfo);
00154 };
00155
00156
00157 SO<Node> findNode(const Bounds& bounds);
00158
00159
00160
00161 void insertShapes(
00162 SO<Node> node,
00163 SO<Iterator<SO<PolygonSet> > > shapes,
00164 SO<Iterator<Bounds> > boundingBoxes,
00165 SO<Iterator<int> > shapeNums,
00166 SO<FixedSizeIterator<int> > newIDs
00167 );
00168
00169 void buildSubNode(
00170 SO<Node> node,
00171 SO<MappedVertexAttributeShapeGL> oldShapes,
00172 SO<Iterator<SO<PolygonSet> > > newShapes,
00173 SO<FixedSizeIterator<int> > newShapeIDs,
00174 SO<Iterator<int> > oldShapeNums,
00175 SO<Iterator<int> > newShapeNums,
00176 SO<Iterator<int> > oldVertexRanges,
00177 SO<Iterator<int> > oldIndexRanges,
00178 SO<Iterator<int> > oldShapeIDs
00179 );
00180 void updateBoundsAndNumVertices(SO<Node> leaf);
00181 void collapseNode(SO<Node> node);
00182 int generateNewID();
00183
00184
00185 int m_nextShapeID;
00186 unsigned int m_maxBatchSize;
00187 SO<Node> m_root;
00188 bool m_normalsStored;
00189 bool m_texCoordsStored;
00190 bool m_colorsStored;
00191 SO<Dictionary<int, ShapeInfo> > m_index2Shape;
00192
00193 PolygonSet::PrimitiveType m_primitiveType;
00194 };
00195
00196 }
00197
00198 #endif // VRS_OPENGL_BATCHTREEGL_H