Panda3D
Loading...
Searching...
No Matches
cullTraverser.I
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.I
10 * @author drose
11 * @date 2002-02-23
12 */
13
14/**
15 * Returns the GraphicsStateGuardian in effect.
16 */
18get_gsg() const {
19 return _gsg;
20}
21
22/**
23 * Returns the currently-executing thread object, as passed to the
24 * CullTraverser constructor.
25 */
27get_current_thread() const {
28 return _current_thread;
29}
30
31/**
32 * Returns the SceneSetup object.
33 */
35get_scene() const {
36 return _scene_setup;
37}
38
39/**
40 * Returns true if a nonempty tag state key has been specified for the scene's
41 * camera, false otherwise.
42 */
43INLINE bool CullTraverser::
44has_tag_state_key() const {
45 return _has_tag_state_key;
46}
47
48/**
49 * Returns the tag state key that has been specified for the scene's camera,
50 * if any.
51 */
52INLINE const std::string &CullTraverser::
53get_tag_state_key() const {
54 return _tag_state_key;
55}
56
57/**
58 * Returns the position of the camera relative to the starting node.
59 */
62 return _scene_setup->get_camera_transform();
63}
64
65/**
66 * Returns the position of the starting node relative to the camera. This is
67 * the inverse of the camera transform.
68 *
69 * Note that this value is always the position of the starting node, not the
70 * current node, even if it is sampled during a traversal. To get the
71 * transform of the current node use
72 * CullTraverserData::get_modelview_transform().
73 */
75get_world_transform() const {
76 return _scene_setup->get_world_transform();
77}
78
79/**
80 * Returns the initial RenderState at the top of the scene graph we are
81 * traversing, or the empty state if the initial state was never set.
82 */
84get_initial_state() const {
85 return _initial_state;
86}
87
88/**
89 * Returns true, as depth offsets are the only way that we implement decals
90 * nowadays.
91 */
92INLINE bool CullTraverser::
94 return true;
95}
96
97/**
98 * Changes the visibility mask for the camera viewing the scene. This is
99 * normally set automatically at the time setup_scene() is called; you should
100 * change this only if you want to render some set of objects different from
101 * what the camera normally would draw.
102 */
104set_camera_mask(const DrawMask &camera_mask) {
105 _camera_mask = camera_mask;
106}
107
108/**
109 * Returns the visibility mask from the camera viewing the scene.
110 */
112get_camera_mask() const {
113 return _camera_mask;
114}
115
116/**
117 * Specifies the bounding volume that corresponds to the view frustum. Any
118 * primitives that fall entirely outside of this volume are not drawn.
119 */
122 _view_frustum = view_frustum;
123}
124
125/**
126 * Returns the bounding volume that corresponds to the view frustum, or NULL
127 * if the view frustum is not in use or has not been set.
128 *
129 * Note that the view frustum returned here is always in the coordinate space
130 * of the starting node, not the current node, even if it is sampled during a
131 * traversal. To get the view frustum in the current node's coordinate space,
132 * check in the current CullTraverserData.
133 */
135get_view_frustum() const {
136 return _view_frustum;
137}
138
139/**
140 * Specifies the object that will receive the culled Geoms. This must be set
141 * before calling traverse().
142 */
144set_cull_handler(CullHandler *cull_handler) {
145 _cull_handler = cull_handler;
146}
147
148/**
149 * Returns the object that will receive the culled Geoms.
150 */
152get_cull_handler() const {
153 return _cull_handler;
154}
155/**
156 * Specifies _portal_clipper object pointer that subsequent traverse() or
157 * traverse_below may use.
158 */
160set_portal_clipper(PortalClipper *portal_clipper) {
161 _portal_clipper = portal_clipper;
162}
163
164/**
165 * Returns the _portal_clipper pointer
166 */
168get_portal_clipper() const {
169 return _portal_clipper;
170}
171
172/**
173 * Returns true if the cull traversal is effectively in incomplete_render
174 * state, considering both the GSG's incomplete_render and the current
175 * DisplayRegion's incomplete_render flags. This returns the flag during the
176 * cull traversal; see GSG::get_effective_incomplete_render() for this same
177 * flag during the draw traversal.
178 */
181 return _effective_incomplete_render;
182}
183
184/**
185 * Flushes the PStatCollectors used during traversal.
186 */
188flush_level() {
189 _nodes_pcollector.flush_level();
190 _geom_nodes_pcollector.flush_level();
191 _geoms_pcollector.flush_level();
192 _geoms_occluded_pcollector.flush_level();
193}
194
195/**
196 * This is implemented inline to reduce recursion.
197 */
198INLINE void CullTraverser::
199do_traverse(CullTraverserData &data) {
200 if (is_in_view(data)) {
201 if (pgraph_cat.is_spam()) {
202 pgraph_cat.spam()
203 << "\n" << data.get_node_path()
204 << " " << data._draw_mask << "\n";
205 }
206
207 PandaNodePipelineReader *node_reader = data.node_reader();
208 int fancy_bits = node_reader->get_fancy_bits();
209
210 if (fancy_bits == 0 && data._cull_planes->is_empty()) {
211 // Nothing interesting in this node; just move on.
212
213 } else {
214 // Something in this node is worth taking a closer look.
215 const RenderEffects *node_effects = node_reader->get_effects();
216 if (node_effects->has_show_bounds()) {
217 // If we should show the bounding volume for this node, make it up
218 // now.
219 show_bounds(data, node_effects->has_show_tight_bounds());
220 }
221
222 data.apply_transform_and_state(this);
223
224 const FogAttrib *fog = (const FogAttrib *)
225 node_reader->get_state()->get_attrib(FogAttrib::get_class_slot());
226
227 if (fog != nullptr && fog->get_fog() != nullptr) {
228 // If we just introduced a FogAttrib here, call adjust_to_camera()
229 // now. This maybe isn't the perfect time to call it, but it's good
230 // enough; and at this time we have all the information we need for
231 // it.
232 fog->get_fog()->adjust_to_camera(get_camera_transform());
233 }
234
235 if (fancy_bits & PandaNode::FB_cull_callback) {
236 PandaNode *node = data.node();
237 if (!node->cull_callback(this, data)) {
238 return;
239 }
240 }
241 }
242
243 traverse_below(data);
244 }
245}
This defines the abstract interface for an object that receives Geoms identified by the CullTraverser...
Definition cullHandler.h:28
This collects together the pieces of data that are accumulated for each node while walking the scene ...
void set_view_frustum(GeometricBoundingVolume *view_frustum)
Specifies the bounding volume that corresponds to the view frustum.
CullHandler * get_cull_handler() const
Returns the object that will receive the culled Geoms.
PortalClipper * get_portal_clipper() const
Returns the _portal_clipper pointer.
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
const std::string & get_tag_state_key() const
Returns the tag state key that has been specified for the scene's camera, if any.
void set_camera_mask(const DrawMask &camera_mask)
Changes the visibility mask for the camera viewing the scene.
const TransformState * get_world_transform() const
Returns the position of the starting node relative to the camera.
const TransformState * get_camera_transform() const
Returns the position of the camera relative to the starting node.
void set_portal_clipper(PortalClipper *portal_clipper)
Specifies _portal_clipper object pointer that subsequent traverse() or traverse_below may use.
virtual void traverse_below(CullTraverserData &data)
Traverses all the children of the indicated node, with the given data, which has been converted into ...
bool has_tag_state_key() const
Returns true if a nonempty tag state key has been specified for the scene's camera,...
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...
void set_cull_handler(CullHandler *cull_handler)
Specifies the object that will receive the culled Geoms.
bool get_effective_incomplete_render() const
Returns true if the cull traversal is effectively in incomplete_render state, considering both the GS...
SceneSetup * get_scene() const
Returns the SceneSetup object.
static void flush_level()
Flushes the PStatCollectors used during traversal.
const DrawMask & get_camera_mask() const
Returns the visibility mask from the camera viewing the scene.
GeometricBoundingVolume * get_view_frustum() const
Returns the bounding volume that corresponds to the view frustum, or NULL if the view frustum is not ...
GraphicsStateGuardianBase * get_gsg() const
Returns the GraphicsStateGuardian in effect.
bool get_depth_offset_decals() const
Returns true, as depth offsets are the only way that we implement decals nowadays.
Applies a Fog to the geometry at and below this node.
Definition fogAttrib.h:25
get_fog
If the FogAttrib is not an 'off' FogAttrib, returns the fog that is associated.
Definition fogAttrib.h:38
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Encapsulates the data from a PandaNode, pre-fetched for one stage of the pipeline.
Definition pandaNode.h:840
const RenderEffects * get_effects() const
Returns the complete RenderEffects that will be applied to this node.
Definition pandaNode.I:1431
const RenderState * get_state() const
Returns the complete RenderState that will be applied to all nodes at this level and below,...
Definition pandaNode.I:1423
int get_fancy_bits() const
Returns the union of all of the enum FancyBits values corresponding to the various "fancy" attributes...
Definition pandaNode.I:1552
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
This represents a unique collection of RenderEffect objects that correspond to a particular renderabl...
bool has_show_tight_bounds() const
If has_show_bounds() returns true, this will return true if the ShowBoundsEffect in question requests...
bool has_show_bounds() const
This function is provided as an optimization, to speed up the render-time checking for the existance ...
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
This object holds the camera position, etc., and other general setup information for rendering a part...
Definition sceneSetup.h:32
A thread; that is, a lightweight process.
Definition thread.h:46
Indicates a coordinate-system transform on vertices.