Panda3D

Loading...
Searching...
No Matches
sceneGraphReducer.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 sceneGraphReducer.I
10 * @author drose
11 * @date 2002-03-14
12 */
13
14/**
15 *
16 */
17INLINE SceneGraphReducer::
18SceneGraphReducer(GraphicsStateGuardianBase *gsg) :
19 _combine_radius(0.0f)
20{
21 set_gsg(gsg);
22}
23
24/**
25 *
26 */
27INLINE SceneGraphReducer::
28~SceneGraphReducer() {
29}
30
31/**
32 * Returns the particular GraphicsStateGuardian that this object will attempt
33 * to optimize to. See set_gsg().
34 */
35INLINE GraphicsStateGuardianBase *SceneGraphReducer::
36 get_gsg() const {
37 return _gsg;
38}
39
40
41/**
42 * Specifies the radius that is used in conjunction with CS_within_radius to
43 * decide whether a subgraph's siblings should be combined into a single node
44 * or not.
45 *
46 * If the CS_within_radius bit is included in the combine_siblings_bits
47 * parameter passed to flatten, than any nodes whose bounding volume is
48 * smaller than the indicated radius will be combined together (as if CS_other
49 * were set).
50 */
51INLINE void SceneGraphReducer::
52 set_combine_radius(PN_stdfloat combine_radius) {
53 _combine_radius = combine_radius;
54}
55
56/**
57 * Returns the radius that is used in conjunction with CS_within_radius. See
58 * set_combine_radius().
59 */
60INLINE PN_stdfloat SceneGraphReducer::
61 get_combine_radius() const {
62 return _combine_radius;
63}
64
65
66/**
67 * Walks the scene graph, accumulating attribs of the indicated types,
68 * applying them to the vertices, and removing them from the scene graph.
69 * This has a performance optimization benefit in itself, but is especially
70 * useful to pave the way for a call to flatten() and greatly improve the
71 * effectiveness of the flattening operation.
72 *
73 * Multiply instanced geometry is duplicated before the attribs are applied.
74 *
75 * Of course, this operation does make certain dynamic operations impossible.
76 */
77INLINE void SceneGraphReducer::
78 apply_attribs(PandaNode *node, int attrib_types) {
79 nassertv(check_live_flatten(node));
80 nassertv(node != nullptr);
81 PStatTimer timer(_apply_collector);
82 AccumulatedAttribs attribs;
83 r_apply_attribs(node, attribs, attrib_types, _transformer);
84 _transformer.finish_apply();
85}
86
87/**
88 * This flavor of apply_attribs() can be called recursively from within
89 * another flatten process (e.g. from
90 * PandaNode::apply_attribs_to_vertices()). The parameters were presumably
91 * received from a parent SceneGraphReducer object.
92 */
93INLINE void SceneGraphReducer::
94 apply_attribs(PandaNode *node, const AccumulatedAttribs &attribs,
95 int attrib_types, GeomTransformer &transformer) {
96 nassertv(node != nullptr);
97 r_apply_attribs(node, attribs, attrib_types, transformer);
98}
99
100/**
101 * Walks through the tree at this node and below and unifies the
102 * GeomVertexFormat for any GeomVertexData objects that are found, so that all
103 * eligible vdatas (according to collect_bits; see collect_vertex_data) will
104 * share the same vertex format.
105 *
106 * This will add unused columns where necessary to match formats. It can
107 * result in suboptimal performance if used needlessly.
108 *
109 * There is usually no reason to call this explicitly, since
110 * collect_vertex_data() will do this anyway if it has not been done already.
111 * However, calling it ahead of time can make that future call to
112 * collect_vertex_data() run a little bit faster.
113 *
114 * The return value is the number of vertex datas modified.
115 */
116INLINE int SceneGraphReducer::
117 make_compatible_format(PandaNode *root, int collect_bits) {
118 nassertr(root != nullptr, 0);
119 nassertr(check_live_flatten(root), 0);
120 PStatTimer timer(_collect_collector);
121 int count = 0;
122 count += r_collect_vertex_data(root, collect_bits, _transformer, true);
123 count += _transformer.finish_collect(true);
124 return count;
125}
126
127/**
128 * Collects all different GeomVertexData blocks that have compatible formats
129 * at this node and below into a single, unified block (or at least multiple
130 * larger blocks). This is intended to reduce rendering overhead incurred by
131 * switching vertex buffers. It can also make a subsequent call to unify()
132 * much more effective than it would have been otherwise.
133 *
134 * The set of bits passed in collect_bits indicates which properties are used
135 * to differentiate GeomVertexData blocks. If it is 0, then more blocks will
136 * be combined together than if it is nonzero.
137 */
138INLINE int SceneGraphReducer::
139 collect_vertex_data(PandaNode *root, int collect_bits) {
140 nassertr(root != nullptr, 0);
141 nassertr(check_live_flatten(root), 0);
142 PStatTimer timer(_collect_collector);
143 int count = 0;
144 count += r_collect_vertex_data(root, collect_bits, _transformer, false);
145 count += _transformer.finish_collect(false);
146 return count;
147}
148
149/**
150 * Converts indexed geometry to nonindexed geometry at the indicated node and
151 * below, by duplicating vertices where necessary. The parameter
152 * nonindexed_bits is a union of bits defined in
153 * SceneGraphReducer::MakeNonindexed, which specifes which types of geometry
154 * to avoid making nonindexed.
155 */
156INLINE int SceneGraphReducer::
157 make_nonindexed(PandaNode *root, int nonindexed_bits) {
158 nassertr(root != nullptr, 0);
159 nassertr(check_live_flatten(root), 0);
160 PStatTimer timer(_make_nonindexed_collector);
161 return r_make_nonindexed(root, nonindexed_bits);
162}
163
164/**
165 * Walks the scene graph rooted at this node and below, and uses the indicated
166 * GSG to premunge every Geom found to optimize it for eventual rendering on
167 * the indicated GSG. If there is no GSG indicated for the SceneGraphReducer,
168 * this is a no-op.
169 *
170 * This operation will also apply to stashed children.
171 */
172INLINE void SceneGraphReducer::
173 premunge(PandaNode *root, const RenderState *initial_state) {
174 nassertv(root != nullptr);
175 nassertv(check_live_flatten(root));
176 if (_gsg != nullptr) {
177 PStatTimer timer(_premunge_collector);
178 r_premunge(root, initial_state);
179 }
180}
AccumulatedAttribs
This class is used by the SceneGraphReducer to maintain and accumulate the set of attributes we have ...
Definition accumulatedAttribs.h:30
GeomTransformer
An object specifically designed to transform the vertices of a Geom without disturbing indexing or af...
Definition geomTransformer.h:42
GraphicsStateGuardianBase
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
Definition graphicsStateGuardianBase.h:110
PStatTimer
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
Definition pStatTimer.h:30
PandaNode
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
RenderState
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
SceneGraphReducer::collect_vertex_data
int collect_vertex_data(PandaNode *root, int collect_bits=~0)
Collects all different GeomVertexData blocks that have compatible formats at this node and below into...
Definition sceneGraphReducer.I:139
SceneGraphReducer::make_compatible_format
int make_compatible_format(PandaNode *root, int collect_bits=~0)
Walks through the tree at this node and below and unifies the GeomVertexFormat for any GeomVertexData...
Definition sceneGraphReducer.I:117
SceneGraphReducer::make_nonindexed
int make_nonindexed(PandaNode *root, int nonindexed_bits=~0)
Converts indexed geometry to nonindexed geometry at the indicated node and below, by duplicating vert...
Definition sceneGraphReducer.I:157
SceneGraphReducer::set_combine_radius
void set_combine_radius(PN_stdfloat combine_radius)
Specifies the radius that is used in conjunction with CS_within_radius to decide whether a subgraph's...
Definition sceneGraphReducer.I:52
SceneGraphReducer::get_combine_radius
PN_stdfloat get_combine_radius() const
Returns the radius that is used in conjunction with CS_within_radius.
Definition sceneGraphReducer.I:61
SceneGraphReducer::get_gsg
GraphicsStateGuardianBase * get_gsg() const
Returns the particular GraphicsStateGuardian that this object will attempt to optimize to.
Definition sceneGraphReducer.I:36
SceneGraphReducer::premunge
void premunge(PandaNode *root, const RenderState *initial_state)
Walks the scene graph rooted at this node and below, and uses the indicated GSG to premunge every Geo...
Definition sceneGraphReducer.I:173
SceneGraphReducer::check_live_flatten
bool check_live_flatten(PandaNode *node)
In a non-release build, returns false if the node is correctly not in a live scene graph.
Definition sceneGraphReducer.cxx:215
SceneGraphReducer::apply_attribs
void apply_attribs(PandaNode *node, int attrib_types=~(TT_clip_plane|TT_cull_face|TT_apply_texture_color))
Walks the scene graph, accumulating attribs of the indicated types, applying them to the vertices,...
Definition sceneGraphReducer.I:78