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