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