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 #ifndef VRS_OPENGL_TEXTUREDBATCHTREEGL_H
00029 #define VRS_OPENGL_TEXTUREDBATCHTREEGL_H
00030
00031 #include <vrs/shape.h>
00032 #include <vrs/opengl/imagetexture2dgl.h>
00033 #include <vrs/opengl/batchtreegl.h>
00034
00035 namespace VRS {
00036
00041 class BatchTreeGL;
00042 class PolygonSet;
00043 class ImageTexture2DGL;
00044 template<typename T> class HashTable;
00045 template<typename T> class Iterator;
00046 template<typename T> class Array;
00047 template<typename T> class StaticArray;
00048 template<typename K, typename V> class Dictionary;
00049
00050 class VRS_CORE_API TexturedBatchTreeGL : public Shape {
00051 public:
00052
00053 TexturedBatchTreeGL();
00054
00061 enum TextureHint { TH_DISABLE_ATLAS, TH_ENABLE_ATLAS, TH_UNKNOWN };
00062
00069 int insertShape(SO<PolygonSet> shape, SO<ImageTexture2DGL> texture = NULL, TextureHint hint = TH_UNKNOWN, int stateSetID = -1);
00070
00074 SO<Iterator<int> > insertShapes(
00075 SO<Iterator<SO<PolygonSet> > > shapes,
00076 SO<ImageTexture2DGL> texture = NULL,
00077 TextureHint hint = TH_UNKNOWN,
00078 int stateSetID = -1
00079 );
00087 SO<Iterator<int> > insertShapes(
00088 SO<Iterator<SO<PolygonSet> > > shapes,
00089 SO<Iterator<SO<ImageTexture2DGL> > > textures,
00090 SO<Iterator<TextureHint> > hints,
00091 SO<Iterator<int> > stateSetIDs
00092 );
00093
00098 bool removeShape(int id);
00099
00103 bool removeShapes(SO<Iterator<int> > ids);
00104
00105
00112 SO<PolygonSet> extractShape(int index) const;
00113
00115 SO<Iterator<int> > shapeIDs() const;
00116
00118 SO<ImageTexture2DGL> getTexture(int index) const;
00119
00121 virtual Bounds boundingBox() const;
00122
00126 void setShapeVisibility(int index, bool visible);
00127 bool getShapeVisibility(int index) const;
00128
00130 void optimize(int maxAtlasSize = 1024);
00131
00133 unsigned int getMaximumBatchSize() const;
00134 void setMaximumBatchSize(unsigned int size = 0xffff);
00135
00139 typedef Iterator<SO<RenderObj> > StateSet;
00140
00141
00157 int registerStateSet(SO<StateSet> stateSet, bool doNotUnify = false);
00158
00162 SO<StateSet> getStateSet(int stateSetID) const;
00163 bool unregisterStateSet(int stateSetID);
00164
00167 void cleanUpStateSets();
00168
00171 int getShapeStateSet(int shapeID) const;
00172
00174 SO<Iterator<int> > getStateSetIDs() const;
00175
00181 void changeStateSet(int shapeID, int newStateSetID, SO<ImageTexture2DGL> tex);
00182 void changeStateSets(
00183 SO<Iterator<int> > shapeIDs,
00184 SO<Iterator<int> > newStateSetIDs,
00185 SO<Iterator<SO<ImageTexture2DGL> > > textures = NULL
00186 );
00187
00192 bool replaceStateSet(int stateSetIndex, SO<StateSet> stateSet);
00193
00194
00195 VRS_TYPEINFO(TexturedBatchTreeGL, Shape);
00196 VRS_SERIALIZABLE(TexturedBatchTreeGL);
00197
00198 private:
00199
00200 friend class TexturedBatchTreeSimplifierGL;
00201 friend class TexturedBatchTreeRayIntersectorGL;
00202
00203
00204 SO<Dictionary<SO<ImageTexture2DGL>, SO<Array<SO<BatchTreeGL> > > > > m_renderingData;
00205
00206
00207 struct VRS_CORE_API ShapeInfo {
00208 SO<BatchTreeGL> m_tree;
00209 int m_internalShapeID;
00210 SO<PolygonSet> m_hiddenGeometry;
00211
00212
00213 VRS_SERIALIZABLE_NO_SO_CLASS(ShapeInfo);
00214 };
00215
00216 struct AtlasImage : public SharedObj {
00217 SO<ImageTexture2DGL> m_atlas;
00218 SO<Array<SO<ImageTexture2DGL> > > m_replacedOriginalTextures;
00219 SO<Array<Matrix> > m_texCoordTransforms;
00220 int m_texturesUsedForCreation;
00221
00222
00223 VRS_TYPEINFO(AtlasImage, SharedObj);
00224 VRS_SERIALIZABLE(AtlasImage);
00225 };
00226
00227
00228 SO<Dictionary<int, ShapeInfo> > m_index2Shape;
00229 SO<HashTable<SO<ImageTexture2DGL> > > m_atlasEnabled;
00230 SO<Dictionary<SO<ImageTexture2DGL>, SO<AtlasImage> > > m_tex2Atlas;
00231
00232
00233 SO<Dictionary<SO<ImageTexture2DGL>, SO<Array<SO<BatchTreeGL> > > > > m_tex2Geometry;
00234
00235
00236
00237
00238 SO<Dictionary<SO<BatchTreeGL>, SO<Array<int> > > > m_tree2HiddenShapes;
00239
00240 SO<Dictionary<std::pair<SO<BatchTreeGL>, int>, int> > m_internalID2ExternalID;
00241
00242
00243 SO<Dictionary<SO<BatchTreeGL>, int> > m_tree2StateSet;
00244
00245 SO<Dictionary<int, SO<StateSet> > > m_id2StateSet;
00246
00247 SO<HashTable<int> > m_lockedStateSets;
00248
00249
00250 int m_nextShapeID;
00251 int m_nextStateSetID;
00252
00253 Bounds m_bounds;
00254 bool m_boundsValid;
00255 int m_maxBatchSize;
00256
00257 int createNewShapeID();
00258
00259 void registerShapes(
00260 SO<Iterator<SO<PolygonSet> > > allNewShapes,
00261 SO<Iterator<int> > allNewShapeIDs,
00262 SO<Iterator<int> > shapeNums,
00263 SO<BatchTreeGL> target,
00264 SO<ImageTexture2DGL> texture
00265 );
00266 void resolveTextureAtlas(SO<AtlasImage> atlas);
00267
00268 SO<Iterator<int> > insertShapesImpl(
00269 SO<Iterator<SO<PolygonSet> > > shapes,
00270 SO<StaticArray<int> > newShapeIDs,
00271 SO<ImageTexture2DGL> texture = NULL,
00272 TextureHint hint = TH_UNKNOWN,
00273 int stateSetID = -1
00274 );
00275 SO<Iterator<int> > insertShapesImpl(
00276 SO<Iterator<SO<PolygonSet> > > shapes,
00277 SO<StaticArray<int> > newShapeIDs,
00278 SO<Iterator<SO<ImageTexture2DGL> > > textures,
00279 SO<Iterator<TextureHint> > hints,
00280 SO<Iterator<int> > stateSetIDs
00281 );
00282
00283 };
00284
00285 }
00286
00287 #endif // VRS_OPENGL_TEXTUREDBATCHTREEGL_H