Panda3D
cullTraverser.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file cullTraverser.h
10  * @author drose
11  * @date 2002-02-23
12  */
13 
14 #ifndef CULLTRAVERSER_H
15 #define CULLTRAVERSER_H
16 
17 #include "pandabase.h"
18 
19 #include "geom.h"
20 #include "sceneSetup.h"
21 #include "renderState.h"
22 #include "transformState.h"
24 #include "pointerTo.h"
25 #include "camera.h"
26 #include "drawMask.h"
27 #include "typedReferenceCount.h"
28 #include "pStatCollector.h"
29 #include "fogAttrib.h"
30 
32 class PandaNode;
33 class CullHandler;
34 class CullableObject;
35 class CullTraverserData;
36 class PortalClipper;
37 class NodePath;
38 
39 /**
40  * This object performs a depth-first traversal of the scene graph, with
41  * optional view-frustum culling, collecting CullState and searching for
42  * GeomNodes. Each renderable Geom encountered is passed along with its
43  * associated RenderState to the CullHandler object.
44  */
45 class EXPCL_PANDA_PGRAPH CullTraverser : public TypedReferenceCount {
46 PUBLISHED:
47  CullTraverser();
48  CullTraverser(const CullTraverser &copy);
49 
50  INLINE GraphicsStateGuardianBase *get_gsg() const;
51  INLINE Thread *get_current_thread() const;
52 
53  virtual void set_scene(SceneSetup *scene_setup,
55  bool dr_incomplete_render);
56  INLINE SceneSetup *get_scene() const;
57  INLINE bool has_tag_state_key() const;
58  INLINE const std::string &get_tag_state_key() const;
59 
60  INLINE void set_camera_mask(const DrawMask &camera_mask);
61  INLINE const DrawMask &get_camera_mask() const;
62 
63  INLINE const TransformState *get_camera_transform() const;
64  INLINE const TransformState *get_world_transform() const;
65 
66  INLINE const RenderState *get_initial_state() const;
67  INLINE bool get_depth_offset_decals() const;
68 
69  INLINE void set_view_frustum(GeometricBoundingVolume *view_frustum);
70  INLINE GeometricBoundingVolume *get_view_frustum() const;
71 
72  INLINE void set_cull_handler(CullHandler *cull_handler);
73  INLINE CullHandler *get_cull_handler() const;
74 
75  INLINE void set_portal_clipper(PortalClipper *portal_clipper);
76  INLINE PortalClipper *get_portal_clipper() const;
77 
78  INLINE bool get_effective_incomplete_render() const;
79 
80  void traverse(const NodePath &root);
81  void traverse(CullTraverserData &data);
82  virtual void traverse_below(CullTraverserData &data);
83 
84  virtual void end_traverse();
85 
86  INLINE static void flush_level();
87 
88  void draw_bounding_volume(const BoundingVolume *vol,
89  const TransformState *internal_transform) const;
90 
91 protected:
92  INLINE void do_traverse(CullTraverserData &data);
93 
94  virtual bool is_in_view(CullTraverserData &data);
95 
96 public:
97  // Statistics
98  static PStatCollector _nodes_pcollector;
99  static PStatCollector _geom_nodes_pcollector;
100  static PStatCollector _geoms_pcollector;
101  static PStatCollector _geoms_occluded_pcollector;
102 
103 private:
104  void show_bounds(CullTraverserData &data, bool tight);
105  static PT(Geom) make_bounds_viz(const BoundingVolume *vol);
106  PT(Geom) make_tight_bounds_viz(PandaNode *node) const;
107  static LVertex compute_point(const BoundingSphere *sphere,
108  PN_stdfloat latitude, PN_stdfloat longitude);
109  static CPT(RenderState) get_bounds_outer_viz_state();
110  static CPT(RenderState) get_bounds_inner_viz_state();
111  static CPT(RenderState) get_depth_offset_state();
112 
114  Thread *_current_thread;
115  PT(SceneSetup) _scene_setup;
116  DrawMask _camera_mask;
117  bool _has_tag_state_key;
118  std::string _tag_state_key;
119  CPT(RenderState) _initial_state;
120  PT(GeometricBoundingVolume) _view_frustum;
121  CullHandler *_cull_handler;
122  PortalClipper *_portal_clipper;
123  bool _effective_incomplete_render;
124 
125 public:
126  static TypeHandle get_class_type() {
127  return _type_handle;
128  }
129  static void init_type() {
130  TypedReferenceCount::init_type();
131  register_type(_type_handle, "CullTraverser",
132  TypedReferenceCount::get_class_type());
133  }
134  virtual TypeHandle get_type() const {
135  return get_class_type();
136  }
137  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
138 
139 private:
140  static TypeHandle _type_handle;
141 };
142 
143 #include "cullTraverserData.h"
144 
145 #include "cullTraverser.I"
146 
147 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Indicates a coordinate-system transform on vertices.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines a bounding sphere, consisting of a center and a radius.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A lightweight class that represents a single element that may be timed and/or counted via stats.
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
Definition: cullHandler.h:28
The smallest atom of cull.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: portalClipper.h:49
A container for geometry primitives.
Definition: geom.h:54
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:47
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encapsulates all the communication with a particular instance of a given rendering backend.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:32
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45