Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGRenderAction.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
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 //  Includes
00047 //---------------------------------------------------------------------------
00048 
00049 #include <vector>
00050 #include <stack>
00051 #include <map>
00052 
00053 #include <OSGSystemDef.h>
00054 #include <OSGBaseTypes.h>
00055 #include <OSGRenderActionBase.h>
00056 #include <OSGMatrix.h>
00057 #include <OSGMaterial.h>
00058 #include <OSGStatElemTypes.h>
00059 
00060 OSG_BEGIN_NAMESPACE
00061 
00062 //---------------------------------------------------------------------------
00063 //  Forward References
00064 //---------------------------------------------------------------------------
00065 
00066 class Material;
00067 class DrawTreeNode;
00068 class Geometry;
00069 class State;
00070 class Light;
00071 class LightEnv;
00072 class LightChunk;
00073 
00074 class DrawTreeNodeFactory;
00075 
00076 //---------------------------------------------------------------------------
00077 //   Types
00078 //---------------------------------------------------------------------------
00079 
00080 //---------------------------------------------------------------------------
00081 //  Class
00082 //---------------------------------------------------------------------------
00083 
00087 class OSG_SYSTEMLIB_DLLMAPPING RenderAction : public RenderActionBase
00088 {
00089   public:
00090 
00091     typedef struct
00092     {
00093         UInt32 first;
00094         Matrix second;
00095         Matrix acc;
00096     }
00097     MatrixStore;
00098     
00099     typedef std::map <Material   *,      DrawTreeNode *         > MaterialMap;
00100     typedef std::pair<LightChunk *,      Matrix                 > LightStore;
00101     typedef std::map <Light      *,      UInt32                 > LightsMap;
00102 
00103     typedef std::stack<Light     *                              > LightsStack;
00104     typedef std::stack<LightEnv  *                              > LightEnvsStack;
00105     typedef std::map  <LightEnv  *,      UInt32                 > LightEnvsMap;
00106   
00107     //-----------------------------------------------------------------------
00108     //   constants                                                               
00109     //-----------------------------------------------------------------------
00110 
00111     static StatElemDesc<StatTimeElem   > statDrawTime;
00112     static StatElemDesc<StatIntElem    > statNMaterials;
00113     static StatElemDesc<StatIntElem    > statNMatrices;
00114     static StatElemDesc<StatIntElem    > statNGeometries;
00115     static StatElemDesc<StatIntElem    > statNTransGeometries;
00116     static StatElemDesc<StatIntOnceElem> statNTextures;
00117     static StatElemDesc<StatIntOnceElem> statNTexBytes;
00118 
00119     //-----------------------------------------------------------------------
00120     //   enums                                                               
00121     //-----------------------------------------------------------------------
00122 
00123     //-----------------------------------------------------------------------
00124     //   types                                                               
00125     //-----------------------------------------------------------------------
00126   
00127     //-----------------------------------------------------------------------
00128     //   class functions                                                     
00129     //-----------------------------------------------------------------------
00130 
00131     static RenderAction *create      (void                    );
00132     
00133     static void          setPrototype(RenderAction *pPrototype);
00134     static RenderAction *getPrototype(void                    );
00135 
00136 
00137     static void registerEnterDefault (const FieldContainerType &type, 
00138                                       const Action::Functor    &func);
00139     
00140     static void registerLeaveDefault (const FieldContainerType &type, 
00141                                       const Action::Functor    &func);
00142 
00143     //-----------------------------------------------------------------------
00144     //   instance functions                                                  
00145     //-----------------------------------------------------------------------
00146 
00147     virtual ~RenderAction(void); 
00148 
00149     /*------------------------- your_category -------------------------------*/
00150     
00151     virtual Action::ResultE start(void       );
00152     virtual Action::ResultE stop (ResultE res); 
00153 
00154     /*------------------------- your_operators ------------------------------*/
00155 
00156            void          push_matrix(const Matrix &matrix);
00157            void          pop_matrix (      void          );
00158 
00159     inline const Matrix &top_matrix (      void          );
00160 
00161     /*------------------------- assignment ----------------------------------*/
00162 
00163     void dropGeometry(Geometry  *pGeo);
00164     void dropFunctor (Material::DrawFunctor &func, Material *mat);
00165 
00166     void dropLight     (Light     *pLight);
00167     void undropLight   (Light     *pLight);
00168 
00169     void dropLightEnv  (LightEnv  *pLightEnv);
00170     void undropLightEnv(LightEnv  *pLightEnv);
00171     
00172     
00173 
00174     void setStateSorting(bool s);
00175     bool getStateSorting(void);
00176 
00177     std::vector<Light *> getActiveLights(void);
00178     UInt32 getActiveLightsMask(void);
00179 
00180     /*------------------------- comparison ----------------------------------*/
00181 
00182     void setSortTrans(bool bVal);
00183     bool getSortTrans(void);
00184     void setZWriteTrans(bool bVal);
00185     bool getZWriteTrans(void);
00186     void setLocalLights(bool bVal);
00187     bool getLocalLights(void);
00188     void setCorrectTwoSidedLighting(bool bVal);
00189     bool getCorrectTwoSidedLighting(void);
00190 
00191     /*------------------------- comparison ----------------------------------*/
00192 
00193     // test a single node
00194     bool            isVisible( Node* node );
00195     
00196     // visibility levels
00197     bool  pushVisibility(void);
00198     void  popVisibility(void);
00199     
00200   protected:
00201 
00202     //-----------------------------------------------------------------------
00203     //   enums                                                               
00204     //-----------------------------------------------------------------------
00205 
00206     //-----------------------------------------------------------------------
00207     //   types                                                               
00208     //-----------------------------------------------------------------------
00209 
00210     typedef RenderActionBase Inherited;
00211 
00212     //-----------------------------------------------------------------------
00213     //   class variables                                                     
00214     //-----------------------------------------------------------------------
00215 
00216     static RenderAction    *_pPrototype;
00217 
00218     static std::vector<Functor> *_vDefaultEnterFunctors;
00219     static std::vector<Functor> *_vDefaultLeaveFunctors;
00220 
00221     //-----------------------------------------------------------------------
00222     //   class functions                                                     
00223     //-----------------------------------------------------------------------
00224 
00225     //-----------------------------------------------------------------------
00226     //   instance variables                                                  
00227     //-----------------------------------------------------------------------
00228 
00229     DrawTreeNodeFactory      *_pNodeFactory;
00230 
00231     UInt32                    _uiMatrixId;
00232 
00233     MatrixStore               _currMatrix;
00234     Matrix                    _camInverse;
00235 
00236     std::vector<MatrixStore>  _vMatrixStack;
00237 
00238     MaterialMap               _mMatMap;
00239     
00240     //DrawTreeNode             *_pRoot;
00241     typedef std::map<Int32, DrawTreeNode *> SortKeyMap;
00242     SortKeyMap                  _pMatRoots;
00243     SortKeyMap                  _pTransMatRoots;
00244     DrawTreeNode               *_pNoStateSortRoot;
00245     DrawTreeNode               *_pNoStateSortTransRoot;
00246 
00247     UInt32                    _uiActiveMatrix;
00248     State                    *_pActiveState;
00249 
00250     UInt32                    _uiNumMaterialChanges;
00251     UInt32                    _uiNumMatrixChanges;
00252     UInt32                    _uiNumGeometries;
00253     UInt32                    _uiNumTransGeometries;
00254  
00255     bool                      _bSortTrans;
00256     bool                      _bZWriteTrans;
00257     bool                      _bLocalLights;
00258     bool                      _bCorrectTwoSidedLighting;
00259 
00260     std::vector<LightStore>   _vLights;
00261     LightsMap                 _lightsMap;
00262     UInt64                    _lightsState;
00263     UInt64                    _activeLightsState;
00264     UInt32                    _activeLightsCount;
00265     UInt32                    _activeLightsMask;
00266 
00267     LightsStack               _lightsStack;
00268     LightEnvsStack            _lightEnvsStack;
00269     LightEnvsMap              _lightEnvsMap;
00270 
00271     bool                      _stateSorting;
00272 
00273     std::vector<FrustumVolume::PlaneSet>  _visibilityStack;
00274 
00275 //    Time                 _tMatSlot
00276 
00277     //-----------------------------------------------------------------------
00278     //   instance functions                                                  
00279     //-----------------------------------------------------------------------
00280 
00281     // prohibit default functions (move to 'public' if you need one)
00282 
00283     RenderAction(void);
00284     RenderAction(const RenderAction &source);
00285 
00286     void operator =(const RenderAction &source);
00287 
00288     // access default functors
00289 
00290     virtual std::vector<Functor> *getDefaultEnterFunctors(void);
00291     virtual std::vector<Functor> *getDefaultLeaveFunctors(void);
00292 
00293             void dump(DrawTreeNode *pRoot, UInt32 uiIndent);
00294     virtual void draw(DrawTreeNode *pRoot);
00295 
00296     inline  void updateTopMatrix(void);
00297             void activateLocalLights(DrawTreeNode *pRoot);
00298 
00299   private:
00300 
00301     //-----------------------------------------------------------------------
00302     //   enums                                                               
00303     //-----------------------------------------------------------------------
00304 
00305     //-----------------------------------------------------------------------
00306     //   types                                                               
00307     //-----------------------------------------------------------------------
00308 
00309     //-----------------------------------------------------------------------
00310     //   friend classes                                                      
00311     //-----------------------------------------------------------------------
00312 
00313     //-----------------------------------------------------------------------
00314     //   friend functions                                                    
00315     //-----------------------------------------------------------------------
00316 
00317     //-----------------------------------------------------------------------
00318     //   class variables                                                     
00319     //-----------------------------------------------------------------------
00320 
00321     static char cvsid[];
00322     
00323     //-----------------------------------------------------------------------
00324     //   class functions                                                     
00325     //-----------------------------------------------------------------------
00326 
00327     //-----------------------------------------------------------------------
00328     //   instance variables                                                  
00329     //-----------------------------------------------------------------------
00330     
00331     //-----------------------------------------------------------------------
00332     //   instance functions                                                  
00333     //-----------------------------------------------------------------------
00334 };
00335 
00336 //---------------------------------------------------------------------------
00337 //   Exported Types
00338 //---------------------------------------------------------------------------
00339 
00340 OSG_END_NAMESPACE
00341 
00342 #include "OSGRenderAction.inl"
00343 
00344 #endif /* _OSGRENDERACTION_H_ */
00345 
00346 

Generated on Thu Aug 25 04:09:07 2005 for OpenSG by  doxygen 1.4.3