Panda3D
 All Classes Functions Variables Enumerations
cullTraverser.h
00001 // Filename: cullTraverser.h
00002 // Created by:  drose (23eb02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef CULLTRAVERSER_H
00016 #define CULLTRAVERSER_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "geom.h"
00021 #include "sceneSetup.h"
00022 #include "renderState.h"
00023 #include "transformState.h"
00024 #include "geometricBoundingVolume.h"
00025 #include "pointerTo.h"
00026 #include "camera.h"
00027 #include "drawMask.h"
00028 #include "typedReferenceCount.h"
00029 #include "pStatCollector.h"
00030 
00031 class GraphicsStateGuardian;
00032 class PandaNode;
00033 class CullHandler;
00034 class CullableObject;
00035 class CullTraverserData;
00036 class PortalClipper;
00037 class NodePath;
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //       Class : CullTraverser
00041 // Description : This object performs a depth-first traversal of the
00042 //               scene graph, with optional view-frustum culling,
00043 //               collecting CullState and searching for GeomNodes.
00044 //               Each renderable Geom encountered is passed along with
00045 //               its associated RenderState to the CullHandler object.
00046 ////////////////////////////////////////////////////////////////////
00047 class EXPCL_PANDA_PGRAPH CullTraverser : public TypedReferenceCount {
00048 PUBLISHED:
00049   CullTraverser();
00050   CullTraverser(const CullTraverser &copy);
00051 
00052   INLINE GraphicsStateGuardianBase *get_gsg() const;
00053   INLINE Thread *get_current_thread() const;
00054 
00055   virtual void set_scene(SceneSetup *scene_setup,
00056                          GraphicsStateGuardianBase *gsg,
00057                          bool dr_incomplete_render);
00058   INLINE SceneSetup *get_scene() const;
00059   INLINE bool has_tag_state_key() const;
00060   INLINE const string &get_tag_state_key() const;
00061 
00062   INLINE void set_camera_mask(const DrawMask &camera_mask);
00063   INLINE const DrawMask &get_camera_mask() const;
00064 
00065   INLINE const TransformState *get_camera_transform() const;
00066   INLINE const TransformState *get_world_transform() const;
00067 
00068   INLINE const RenderState *get_initial_state() const;
00069   INLINE bool get_depth_offset_decals() const;
00070 
00071   INLINE void set_view_frustum(GeometricBoundingVolume *view_frustum);
00072   INLINE GeometricBoundingVolume *get_view_frustum() const;
00073 
00074   INLINE void set_cull_handler(CullHandler *cull_handler);
00075   INLINE CullHandler *get_cull_handler() const;
00076 
00077   INLINE void set_portal_clipper(PortalClipper *portal_clipper);
00078   INLINE PortalClipper *get_portal_clipper() const;
00079 
00080   INLINE bool get_effective_incomplete_render() const;
00081 
00082   void traverse(const NodePath &root);
00083   void traverse(CullTraverserData &data);
00084   virtual void traverse_below(CullTraverserData &data);
00085 
00086   virtual void end_traverse();
00087 
00088   INLINE static void flush_level();
00089 
00090   void draw_bounding_volume(const BoundingVolume *vol, 
00091                             const TransformState *net_transform,
00092                             const TransformState *modelview_transform) const;
00093 
00094 protected:
00095   virtual bool is_in_view(CullTraverserData &data);
00096 
00097 public:
00098   // Statistics
00099   static PStatCollector _nodes_pcollector;
00100   static PStatCollector _geom_nodes_pcollector;
00101   static PStatCollector _geoms_pcollector;
00102   static PStatCollector _geoms_occluded_pcollector;
00103 
00104 private:
00105   void show_bounds(CullTraverserData &data, bool tight);
00106   static PT(Geom) make_bounds_viz(const BoundingVolume *vol);
00107   PT(Geom) make_tight_bounds_viz(PandaNode *node) const;
00108   static LVertex compute_point(const BoundingSphere *sphere, 
00109                                PN_stdfloat latitude, PN_stdfloat longitude);
00110   static CPT(RenderState) get_bounds_outer_viz_state();
00111   static CPT(RenderState) get_bounds_inner_viz_state();
00112   static CPT(RenderState) get_depth_offset_state();
00113   void start_decal(const CullTraverserData &data);
00114   CullableObject *r_get_decals(CullTraverserData &data,
00115                                CullableObject *decals);
00116 
00117   GraphicsStateGuardianBase *_gsg;
00118   Thread *_current_thread;
00119   PT(SceneSetup) _scene_setup;
00120   DrawMask _camera_mask;
00121   bool _has_tag_state_key;
00122   string _tag_state_key;
00123   CPT(RenderState) _initial_state;
00124   bool _depth_offset_decals;
00125   PT(GeometricBoundingVolume) _view_frustum;
00126   CullHandler *_cull_handler;
00127   PortalClipper *_portal_clipper;
00128   bool _effective_incomplete_render;
00129   
00130 public:
00131   static TypeHandle get_class_type() {
00132     return _type_handle;
00133   }
00134   static void init_type() {
00135     TypedReferenceCount::init_type();
00136     register_type(_type_handle, "CullTraverser",
00137                   TypedReferenceCount::get_class_type());
00138   }
00139   virtual TypeHandle get_type() const {
00140     return get_class_type();
00141   }
00142   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00143 
00144 private:
00145   static TypeHandle _type_handle;
00146 };
00147 
00148 #include "cullTraverser.I"
00149 
00150 #endif
00151 
00152 
00153   
 All Classes Functions Variables Enumerations