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
00038
00039 #ifndef _OSGRENDERACTION_H_
00040 #define _OSGRENDERACTION_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045
00046
00047
00048
00049 #include <vector>
00050 #include <stack>
00051 #include <map>
00052 #include <set>
00053
00054 #include <OSGSystemDef.h>
00055 #include <OSGBaseTypes.h>
00056 #include <OSGRenderActionBase.h>
00057 #include <OSGMatrix.h>
00058 #include <OSGMaterial.h>
00059 #include <OSGStatElemTypes.h>
00060
00061 OSG_BEGIN_NAMESPACE
00062
00063
00064
00065
00066
00067 class Material;
00068 class DrawTreeNode;
00069 class Geometry;
00070 class State;
00071 class Light;
00072 class LightEnv;
00073 class LightChunk;
00074 class ClipPlane;
00075 class SClipPlaneChunk;
00076
00077 class DrawTreeNodeFactory;
00078
00079
00080
00081
00082
00083
00084
00085
00086
00090 class OSG_SYSTEMLIB_DLLMAPPING RenderAction : public RenderActionBase
00091 {
00092 public:
00093
00094 typedef struct
00095 {
00096 UInt32 first;
00097 Matrix second;
00098 Matrix acc;
00099 }
00100 MatrixStore;
00101
00102 typedef std::map <Material *, DrawTreeNode * > MaterialMap;
00103 typedef std::pair<LightChunk *, Matrix > LightStore;
00104 typedef std::pair<SClipPlaneChunk *, Matrix > ClipPlaneStore;
00105
00106
00107
00108
00109
00110 static StatElemDesc<StatTimeElem > statDrawTime;
00111 static StatElemDesc<StatIntElem > statNMaterials;
00112 static StatElemDesc<StatIntElem > statNMatrices;
00113 static StatElemDesc<StatIntElem > statNLights;
00114 static StatElemDesc<StatIntElem > statNGeometries;
00115 static StatElemDesc<StatIntElem > statNTransGeometries;
00116 static StatElemDesc<StatIntOnceElem> statNTextures;
00117 static StatElemDesc<StatIntOnceElem> statNTexBytes;
00118 static StatElemDesc<StatStringElem > statNOcclusionMode;
00119 static StatElemDesc<StatIntElem > statNOcclusionTests;
00120 static StatElemDesc<StatIntElem > statNOcclusionCulled;
00121
00122 static const Int32 OcclusionStopAndWait;
00123 static const Int32 OcclusionMultiFrame;
00124 static const Int32 OcclusionHierarchicalMultiFrame;
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 static RenderAction *create (void );
00139
00140 static void setPrototype(RenderAction *pPrototype);
00141 static RenderAction *getPrototype(void );
00142
00143
00144 static void registerEnterDefault (const FieldContainerType &type,
00145 const Action::Functor &func);
00146
00147 static void registerLeaveDefault (const FieldContainerType &type,
00148 const Action::Functor &func);
00149
00150
00151
00152
00153
00154 virtual ~RenderAction(void);
00155
00156
00157
00158 virtual Action::ResultE start(void );
00159 virtual Action::ResultE stop (ResultE res);
00160
00161
00162
00163 void push_matrix(const Matrix &matrix);
00164 void pop_matrix ( void );
00165
00166 inline const Matrix &top_matrix ( void );
00167
00168
00169
00170 void dropGeometry(Geometry *pGeo);
00171 void dropFunctor (Material::DrawFunctor &func, Material *mat);
00172
00173 void dropLight (Light *pLight);
00174 void undropLight (Light *pLight);
00175
00176 void dropLightEnv (LightEnv *pLightEnv);
00177 void undropLightEnv(LightEnv *pLightEnv);
00178
00179 void dropClipPlane (ClipPlane *pClipPlane);
00180 void undropClipPlane(ClipPlane *pClipPlane);
00181
00182 void setStateSorting(bool s);
00183 bool getStateSorting(void);
00184
00185 std::vector<Light *> getActiveLights(void);
00186 UInt32 getActiveLightsMask(void);
00187 UInt32 getActiveLightsCount(void);
00188
00189 const std::vector<UInt32> &getLightEnvsLightsState(void);
00190
00191 inline State *getCurrentState(void);
00192
00193
00194
00195 void setSortTrans(bool bVal);
00196 bool getSortTrans(void) const;
00197
00198 void setZWriteTrans(bool bVal);
00199 bool getZWriteTrans(void) const;
00200
00201 void setLocalLights(bool bVal);
00202 bool getLocalLights(void) const;
00203
00204 void setCorrectTwoSidedLighting(bool bVal);
00205 bool getCorrectTwoSidedLighting(void) const;
00206
00207 void setOcclusionCulling(bool bVal);
00208 bool getOcclusionCulling(void) const;
00209
00210 void setOcclusionCullingMode(Int32 mode);
00211 Int32 getOcclusionCullingMode(void) const;
00212 void setOcclusionCullingPixels(UInt32 pixels);
00213 UInt32 getOcclusionCullingPixels(void) const;
00214 void setOcclusionCullingThreshold(UInt32 threshold);
00215 UInt32 getOcclusionCullingThreshold(void) const;
00216
00217 void setSmallFeatureCulling(bool bVal);
00218 bool getSmallFeatureCulling(void) const;
00219 void setSmallFeaturePixels(Real32 pixels);
00220 Real32 getSmallFeaturePixels(void) const;
00221 void setSmallFeatureThreshold(UInt32 threshold);
00222 UInt32 getSmallFeatureThreshold(void) const;
00223
00224 void setUseGLFinish(bool s);
00225 bool getUseGLFinish(void) const;
00226
00227
00228
00229 bool isSmallFeature(const NodePtr &node);
00230 bool isOccluded(DrawTreeNode *pRoot);
00231 void deleteOcclusionQueriesPool(void);
00232 GLuint getOcclusionQuery(void);
00233 GLuint getOcclusionQuery(NodePtr node);
00234 void setOcclusionQuery(NodePtr node, GLuint occlusionQuery);
00235 void resetOcclusionQueryIndex(void);
00236 void setOcclusionMask(NodePtr node, UInt8 mask);
00237 bool hasGeometryChild(NodePtr node);
00238
00239 void drawOcclusionBB(const Pnt3f &bbmin, const Pnt3f &bbmax);
00240 void drawMultiFrameOcclusionBB(DrawTreeNode *pRoot);
00241 void drawHierarchicalMultiFrameOcclusionBB(const Matrix &view, NodePtr node);
00242
00243
00244 bool isVisible( Node* node );
00245
00246
00247 bool pushVisibility(void);
00248 void popVisibility(void);
00249
00250 void (OSG_APIENTRY* _glGenQueriesARB)(GLsizei, GLuint*);
00251 void (OSG_APIENTRY* _glDeleteQueriesARB)(GLsizei, GLuint*);
00252 void (OSG_APIENTRY* _glBeginQueryARB)(GLenum, GLuint);
00253 void (OSG_APIENTRY* _glEndQueryARB)(GLenum);
00254 void (OSG_APIENTRY* _glGetQueryObjectuivARB)(GLuint, GLenum, GLuint*);
00255
00256 protected:
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 typedef RenderActionBase Inherited;
00267
00268
00269
00270
00271
00272 static RenderAction *_pPrototype;
00273
00274 static std::vector<Functor> *_vDefaultEnterFunctors;
00275 static std::vector<Functor> *_vDefaultLeaveFunctors;
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 DrawTreeNodeFactory *_pNodeFactory;
00286
00287 UInt32 _uiMatrixId;
00288
00289 MatrixStore _currMatrix;
00290 Matrix _camInverse;
00291
00292 std::vector<MatrixStore> _vMatrixStack;
00293
00294 MaterialMap _mMatMap;
00295
00296
00297 typedef std::map<Int32, DrawTreeNode *> SortKeyMap;
00298 SortKeyMap _pMatRoots;
00299
00300 typedef std::map<Real32, DrawTreeNode *> TransSortMap;
00301 typedef std::map<Int32, TransSortMap> TransSortKeyMap;
00302 TransSortKeyMap _pTransMatRoots;
00303
00304 DrawTreeNode *_pNoStateSortRoot;
00305 DrawTreeNode *_pNoStateSortTransRoot;
00306
00307 typedef std::map<Real32, DrawTreeNode *> OCMap;
00308 OCMap _ocRoot;
00309
00310 UInt32 _uiActiveMatrix;
00311 State *_pActiveState;
00312
00313 UInt32 _uiNumMaterialChanges;
00314 UInt32 _uiNumMatrixChanges;
00315 UInt32 _uiNumLightChanges;
00316 UInt32 _uiNumGeometries;
00317 UInt32 _uiNumTransGeometries;
00318 UInt32 _uiNumOcclusionTests;
00319 UInt32 _uiNumOcclusionCulled;
00320
00321 bool _bSortTrans;
00322 bool _bZWriteTrans;
00323 bool _bLocalLights;
00324 bool _bCorrectTwoSidedLighting;
00325 bool _bOcclusionCulling;
00326 Int32 _occlusionCullingMode;
00327 UInt32 _occlusionCullingPixels;
00328 UInt32 _occlusionCullingThreshold;
00329 UInt32 _currentOcclusionQueryIndex;
00330 std::vector<NodePtr> _occluded_nodes;
00331 std::set<UInt32> _hier_occlusions;
00332 UInt32 _occ_bb_dl;
00333
00334 bool _bSmallFeatureCulling;
00335 Real32 _smallFeaturesPixels;
00336 UInt32 _smallFeaturesThreshold;
00337 Matrix _worldToScreenMatrix;
00338 bool _useGLFinish;
00339
00340 std::vector<LightStore> _vLights;
00341 std::vector<Light *> _lightsMap;
00342 UInt32 _lightsState;
00343 UInt32 _activeLightsState;
00344 UInt32 _activeLightsCount;
00345 UInt32 _activeLightsMask;
00346
00347 std::vector<std::vector<UInt32> > _lightsTable;
00348 std::vector<UInt32> _lightsPath;
00349 std::vector<UInt32> _lightEnvsLightsState;
00350
00351
00352 std::vector<ClipPlaneStore> _vClipPlanes;
00353 std::vector<ClipPlane *> _clipPlanesMap;
00354 UInt32 _clipPlanesState;
00355 UInt32 _activeClipPlanesState;
00356 UInt32 _activeClipPlanesCount;
00357 UInt32 _activeClipPlanesMask;
00358
00359 std::vector<std::vector<UInt32> > _clipPlanesTable;
00360 std::vector<UInt32> _clipPlanesPath;
00361
00362 bool _stateSorting;
00363
00364 std::vector<FrustumVolume::PlaneSet> _visibilityStack;
00365
00366 GLuint _occlusionQuery;
00367 std::vector<GLuint> _occlusionQueriesPool;
00368 std::map<UInt32, GLuint> _occlusionQueries;
00369
00370 Int32 _cgChunkId;
00371 Int32 _cgfxChunkId;
00372 Int32 _shlChunkId;
00373
00374 static UInt32 _arbOcclusionQuery;
00375 static UInt32 _funcGenQueriesARB;
00376 static UInt32 _funcDeleteQueriesARB;
00377 static UInt32 _funcBeginQueryARB;
00378 static UInt32 _funcEndQueryARB;
00379 static UInt32 _funcGetQueryObjectuivARB;
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 RenderAction(void);
00390 RenderAction(const RenderAction &source);
00391
00392 void operator =(const RenderAction &source);
00393
00394
00395
00396 virtual std::vector<Functor> *getDefaultEnterFunctors(void);
00397 virtual std::vector<Functor> *getDefaultLeaveFunctors(void);
00398
00399 void dump(DrawTreeNode *pRoot, UInt32 uiIndent);
00400
00401 void updateShader(State *state);
00402 virtual void draw(DrawTreeNode *pRoot);
00403
00404 inline void updateTopMatrix(void);
00405 void activateLocalLights(DrawTreeNode *pRoot);
00406 void activateLocalClipPlanes(DrawTreeNode *pRoot);
00407
00408 void getMaterialStates(Material *mat, std::vector<State *> &states);
00409
00410 private:
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 friend class ShadowViewport;
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 static char cvsid[];
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 };
00448
00449
00450
00451
00452
00453 OSG_END_NAMESPACE
00454
00455 #include "OSGRenderAction.inl"
00456
00457 #endif
00458
00459