Panda3D
cullTraverser.I
1 // Filename: cullTraverser.I
2 // Created by: drose (23Feb02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: CullTraverser::get_gsg
18 // Access: Published
19 // Description: Returns the GraphicsStateGuardian in effect.
20 ////////////////////////////////////////////////////////////////////
22 get_gsg() const {
23  return _gsg;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: CullTraverser::get_current_thread
28 // Access: Published
29 // Description: Returns the currently-executing thread object, as
30 // passed to the CullTraverser constructor.
31 ////////////////////////////////////////////////////////////////////
32 INLINE Thread *CullTraverser::
34  return _current_thread;
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: CullTraverser::get_scene
39 // Access: Published
40 // Description: Returns the SceneSetup object.
41 ////////////////////////////////////////////////////////////////////
43 get_scene() const {
44  return _scene_setup;
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: CullTraverser::has_tag_state_key
49 // Access: Published
50 // Description: Returns true if a nonempty tag state key has been
51 // specified for the scene's camera, false otherwise.
52 ////////////////////////////////////////////////////////////////////
53 INLINE bool CullTraverser::
55  return _has_tag_state_key;
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: CullTraverser::get_tag_state_key
60 // Access: Published
61 // Description: Returns the tag state key that has been specified for
62 // the scene's camera, if any.
63 ////////////////////////////////////////////////////////////////////
64 INLINE const string &CullTraverser::
66  return _tag_state_key;
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: CullTraverser::get_camera_transform
71 // Access: Published
72 // Description: Returns the position of the camera relative to the
73 // starting node.
74 ////////////////////////////////////////////////////////////////////
75 INLINE const TransformState *CullTraverser::
77  return _scene_setup->get_camera_transform();
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: CullTraverser::get_world_transform
82 // Access: Published
83 // Description: Returns the position of the starting node relative
84 // to the camera. This is the inverse of the camera
85 // transform.
86 //
87 // Note that this value is always the position of the
88 // starting node, not the current node, even if it is
89 // sampled during a traversal. To get the transform of
90 // the current node use
91 // CullTraverserData::get_modelview_transform().
92 ////////////////////////////////////////////////////////////////////
93 INLINE const TransformState *CullTraverser::
95  return _scene_setup->get_world_transform();
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: CullTraverser::get_initial_state
100 // Access: Published
101 // Description: Returns the initial RenderState at the top of the
102 // scene graph we are traversing, or the empty state if
103 // the initial state was never set.
104 ////////////////////////////////////////////////////////////////////
105 INLINE const RenderState *CullTraverser::
107  return _initial_state;
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: CullTraverser::get_depth_offset_decals
112 // Access: Published
113 // Description: Returns true, as depth offsets are the only way
114 // that we implement decals nowadays.
115 ////////////////////////////////////////////////////////////////////
116 INLINE bool CullTraverser::
118  return true;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: CullTraverser::set_camera_mask
123 // Access: Published
124 // Description: Changes the visibility mask for the camera viewing
125 // the scene. This is normally set automatically
126 // at the time setup_scene() is called; you should
127 // change this only if you want to render some set of
128 // objects different from what the camera normally would
129 // draw.
130 ////////////////////////////////////////////////////////////////////
131 INLINE void CullTraverser::
132 set_camera_mask(const DrawMask &camera_mask) {
133  _camera_mask = camera_mask;
134 }
135 
136 ////////////////////////////////////////////////////////////////////
137 // Function: CullTraverser::get_camera_mask
138 // Access: Published
139 // Description: Returns the visibility mask from the camera viewing
140 // the scene.
141 ////////////////////////////////////////////////////////////////////
142 INLINE const DrawMask &CullTraverser::
144  return _camera_mask;
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: CullTraverser::set_view_frustum
149 // Access: Published
150 // Description: Specifies the bounding volume that corresponds to the
151 // view frustum. Any primitives that fall entirely
152 // outside of this volume are not drawn.
153 ////////////////////////////////////////////////////////////////////
154 INLINE void CullTraverser::
156  _view_frustum = view_frustum;
157 }
158 
159 ////////////////////////////////////////////////////////////////////
160 // Function: CullTraverser::get_view_frustum
161 // Access: Published
162 // Description: Returns the bounding volume that corresponds to the
163 // view frustum, or NULL if the view frustum is not in
164 // use or has not been set.
165 //
166 // Note that the view frustum returned here is always in
167 // the coordinate space of the starting node, not the
168 // current node, even if it is sampled during a
169 // traversal. To get the view frustum in the current
170 // node's coordinate space, check in the current
171 // CullTraverserData.
172 ////////////////////////////////////////////////////////////////////
175  return _view_frustum;
176 }
177 
178 ////////////////////////////////////////////////////////////////////
179 // Function: CullTraverser::set_cull_handler
180 // Access: Published
181 // Description: Specifies the object that will receive the culled
182 // Geoms. This must be set before calling traverse().
183 ////////////////////////////////////////////////////////////////////
184 INLINE void CullTraverser::
186  _cull_handler = cull_handler;
187 }
188 
189 ////////////////////////////////////////////////////////////////////
190 // Function: CullTraverser::get_cull_handler
191 // Access: Published
192 // Description: Returns the object that will receive the culled
193 // Geoms.
194 ////////////////////////////////////////////////////////////////////
197  return _cull_handler;
198 }
199 ////////////////////////////////////////////////////////////////////
200 // Function: CullTraverser::set_portal_clipper
201 // Access: Published
202 // Description: Specifies _portal_clipper object pointer that
203 // subsequent traverse() or traverse_below may use.
204 ////////////////////////////////////////////////////////////////////
205 INLINE void CullTraverser::
207  _portal_clipper = portal_clipper;
208 }
209 
210 ////////////////////////////////////////////////////////////////////
211 // Function: CullTraverser::get_portal_clipper
212 // Access: Published
213 // Description: Returns the _portal_clipper pointer
214 ////////////////////////////////////////////////////////////////////
217  return _portal_clipper;
218 }
219 
220 ////////////////////////////////////////////////////////////////////
221 // Function: CullTraverser::get_effective_incomplete_render
222 // Access: Published
223 // Description: Returns true if the cull traversal is effectively in
224 // incomplete_render state, considering both the GSG's
225 // incomplete_render and the current DisplayRegion's
226 // incomplete_render flags. This returns the flag
227 // during the cull traversal; see
228 // GSG::get_effective_incomplete_render() for this same
229 // flag during the draw traversal.
230 ////////////////////////////////////////////////////////////////////
231 INLINE bool CullTraverser::
233  return _effective_incomplete_render;
234 }
235 
236 ////////////////////////////////////////////////////////////////////
237 // Function: CullTraverser::flush_level
238 // Access: Published, Static
239 // Description: Flushes the PStatCollectors used during traversal.
240 ////////////////////////////////////////////////////////////////////
241 INLINE void CullTraverser::
243  _nodes_pcollector.flush_level();
244  _geom_nodes_pcollector.flush_level();
245  _geoms_pcollector.flush_level();
246  _geoms_occluded_pcollector.flush_level();
247 }
248 
249 ////////////////////////////////////////////////////////////////////
250 // Function: CullTraverser::do_traverse
251 // Access: Protected
252 // Description: This is implemented inline to reduce recursion.
253 ////////////////////////////////////////////////////////////////////
254 INLINE void CullTraverser::
255 do_traverse(CullTraverserData &data) {
256  if (is_in_view(data)) {
257  if (pgraph_cat.is_spam()) {
258  pgraph_cat.spam()
259  << "\n" << data._node_path
260  << " " << data._draw_mask << "\n";
261  }
262 
263  PandaNodePipelineReader *node_reader = data.node_reader();
264  int fancy_bits = node_reader->get_fancy_bits();
265 
266  if ((fancy_bits & (PandaNode::FB_transform |
267  PandaNode::FB_state |
268  PandaNode::FB_effects |
269  PandaNode::FB_tag |
270  PandaNode::FB_draw_mask |
271  PandaNode::FB_cull_callback)) == 0 &&
272  data._cull_planes->is_empty()) {
273  // Nothing interesting in this node; just move on.
274 
275  } else {
276  // Something in this node is worth taking a closer look.
277  const RenderEffects *node_effects = node_reader->get_effects();
278  if (node_effects->has_show_bounds()) {
279  // If we should show the bounding volume for this node, make it
280  // up now.
281  show_bounds(data, node_effects->has_show_tight_bounds());
282  }
283 
284  data.apply_transform_and_state(this);
285 
286  const FogAttrib *fog = (const FogAttrib *)
287  node_reader->get_state()->get_attrib(FogAttrib::get_class_slot());
288 
289  if (fog != (const FogAttrib *)NULL && fog->get_fog() != (Fog *)NULL) {
290  // If we just introduced a FogAttrib here, call adjust_to_camera()
291  // now. This maybe isn't the perfect time to call it, but it's
292  // good enough; and at this time we have all the information we
293  // need for it.
295  }
296 
297  if (fancy_bits & PandaNode::FB_cull_callback) {
298  PandaNode *node = data.node();
299  if (!node->cull_callback(this, data)) {
300  return;
301  }
302  }
303  }
304 
305  traverse_below(data);
306  }
307 }
Fog * get_fog() const
If the FogAttrib is not an &#39;off&#39; FogAttrib, returns the fog that is associated.
Definition: fogAttrib.I:45
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
bool has_tag_state_key() const
Returns true if a nonempty tag state key has been specified for the scene&#39;s camera, false otherwise.
Definition: cullTraverser.I:54
void set_camera_mask(const DrawMask &camera_mask)
Changes the visibility mask for the camera viewing the scene.
CullHandler * get_cull_handler() const
Returns the object that will receive the culled Geoms.
const TransformState * get_camera_transform() const
Returns the position of the camera relative to the starting node.
Definition: cullTraverser.I:76
static void flush_level()
Flushes the PStatCollectors used during traversal.
const RenderEffects * get_effects() const
Returns the complete RenderEffects that will be applied to this node.
Definition: pandaNode.I:1742
virtual void traverse_below(CullTraverserData &data)
Traverses all the children of the indicated node, with the given data, which has been converted into ...
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
Definition: cullTraverser.I:33
const RenderState * get_state() const
Returns the complete RenderState that will be applied to all nodes at this level and below...
Definition: pandaNode.I:1731
This collects together the pieces of data that are accumulated for each node while walking the scene ...
void adjust_to_camera(const TransformState *camera_transform)
This function is intended to be called by the cull traverser to compute the appropriate camera-relati...
Definition: fog.cxx:155
PandaNode * node() const
Returns the node traversed to so far.
Applies a Fog to the geometry at and below this node.
Definition: fogAttrib.h:27
PortalClipper * get_portal_clipper() const
Returns the _portal_clipper pointer.
bool get_effective_incomplete_render() const
Returns true if the cull traversal is effectively in incomplete_render state, considering both the GS...
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
void set_portal_clipper(PortalClipper *portal_clipper)
Specifies _portal_clipper object pointer that subsequent traverse() or traverse_below may use...
const string & get_tag_state_key() const
Returns the tag state key that has been specified for the scene&#39;s camera, if any. ...
Definition: cullTraverser.I:65
bool has_show_bounds() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
bool get_depth_offset_decals() const
Returns true, as depth offsets are the only way that we implement decals nowadays.
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
Definition: cullHandler.h:31
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: portalClipper.h:52
Specifies how atmospheric fog effects are applied to geometry.
Definition: fog.h:46
void set_view_frustum(GeometricBoundingVolume *view_frustum)
Specifies the bounding volume that corresponds to the view frustum.
const TransformState * get_world_transform() const
Returns the position of the starting node relative to the camera.
Definition: cullTraverser.I:94
GraphicsStateGuardianBase * get_gsg() const
Returns the GraphicsStateGuardian in effect.
Definition: cullTraverser.I:22
PandaNodePipelineReader * node_reader()
Returns the PipelineReader for the node traversed to so far.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
void apply_transform_and_state(CullTraverser *trav)
Applies the transform and state from the current node onto the current data.
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:51
const RenderState * get_initial_state() const
Returns the initial RenderState at the top of the scene graph we are traversing, or the empty state i...
GeometricBoundingVolume * get_view_frustum() const
Returns the bounding volume that corresponds to the view frustum, or NULL if the view frustum is not ...
Encapsulates the data from a PandaNode, pre-fetched for one stage of the pipeline.
Definition: pandaNode.h:815
SceneSetup * get_scene() const
Returns the SceneSetup object.
Definition: cullTraverser.I:43
const DrawMask & get_camera_mask() const
Returns the visibility mask from the camera viewing the scene.
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition: sceneSetup.h:35
This represents a unique collection of RenderEffect objects that correspond to a particular renderabl...
Definition: renderEffects.h:46
bool has_show_tight_bounds() const
If has_show_bounds() returns true, this will return true if the ShowBoundsEffect in question requests...
void set_cull_handler(CullHandler *cull_handler)
Specifies the object that will receive the culled Geoms.