15 #include "accumulatedAttribs.h" 16 #include "sceneGraphReducer.h" 17 #include "pandaNode.h" 18 #include "colorAttrib.h" 19 #include "colorScaleAttrib.h" 20 #include "texMatrixAttrib.h" 21 #include "textureAttrib.h" 22 #include "clipPlaneAttrib.h" 23 #include "cullFaceAttrib.h" 24 #include "config_pgraph.h" 33 AccumulatedAttribs() {
34 _transform = TransformState::make_identity();
36 _color_scale_override = 0;
37 _tex_matrix_override = 0;
38 _texture_override = 0;
39 _clip_plane_override = 0;
40 _cull_face_override = 0;
41 _other = RenderState::make_empty();
51 _transform(copy._transform),
53 _color_override(copy._color_override),
54 _color_scale(copy._color_scale),
55 _color_scale_override(copy._color_scale_override),
56 _tex_matrix(copy._tex_matrix),
57 _tex_matrix_override(copy._tex_matrix_override),
58 _texture(copy._texture),
59 _texture_override(copy._texture_override),
60 _clip_plane(copy._clip_plane),
61 _clip_plane_override(copy._clip_plane_override),
62 _cull_face(copy._cull_face),
63 _cull_face_override(copy._cull_face_override),
73 void AccumulatedAttribs::
75 _transform = copy._transform;
77 _color_override = copy._color_override;
78 _color_scale = copy._color_scale;
79 _color_scale_override = copy._color_scale_override;
80 _tex_matrix = copy._tex_matrix;
81 _tex_matrix_override = copy._tex_matrix_override;
82 _texture = copy._texture;
83 _texture_override = copy._texture_override;
84 _clip_plane = copy._clip_plane;
85 _clip_plane_override = copy._clip_plane_override;
86 _cull_face = copy._cull_face;
87 _cull_face_override = copy._cull_face_override;
96 void AccumulatedAttribs::
97 write(ostream &out,
int attrib_types,
int indent_level)
const {
98 if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
99 _transform->write(out, indent_level);
101 if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
103 indent(out, indent_level) <<
"no color\n";
105 _color->write(out, indent_level);
108 if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
110 indent(out, indent_level) <<
"no color scale\n";
112 _color_scale->write(out, indent_level);
115 if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
117 indent(out, indent_level) <<
"no tex matrix\n";
119 _tex_matrix->write(out, indent_level);
122 if ((attrib_types & SceneGraphReducer::TT_clip_plane) != 0) {
124 indent(out, indent_level) <<
"no clip plane\n";
126 _clip_plane->write(out, indent_level);
129 if ((attrib_types & SceneGraphReducer::TT_cull_face) != 0) {
131 indent(out, indent_level) <<
"no cull face\n";
133 _cull_face->write(out, indent_level);
136 if ((attrib_types & SceneGraphReducer::TT_other) != 0) {
137 _other->write(out, indent_level);
150 if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
152 nassertv(_transform != (TransformState *)NULL);
153 _transform = _transform->compose(node->get_transform());
173 if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
175 new_state->get_attrib(ColorAttrib::get_class_slot());
177 int color_override = new_state->get_override(ColorAttrib::get_class_slot());
178 if (color_override >= _color_override ||
182 _color = node_attrib;
184 _color = _color->compose(node_attrib);
186 _color_override = color_override;
188 new_state = new_state->remove_attrib(ColorAttrib::get_class_slot());
192 if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
194 new_state->get_attrib(ColorScaleAttrib::get_class_slot());
196 int color_scale_override = new_state->get_override(ColorScaleAttrib::get_class_slot());
197 if (color_scale_override >= _color_scale_override ||
200 _color_scale = node_attrib;
202 _color_scale = _color_scale->compose(node_attrib);
204 _color_scale_override = color_scale_override;
206 new_state = new_state->remove_attrib(ColorScaleAttrib::get_class_slot());
210 if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
212 new_state->get_attrib(TexMatrixAttrib::get_class_slot());
214 int tex_matrix_override = new_state->get_override(TexMatrixAttrib::get_class_slot());
215 if (tex_matrix_override >= _tex_matrix_override ||
218 _tex_matrix = node_attrib;
220 _tex_matrix = _tex_matrix->compose(node_attrib);
222 _tex_matrix_override = tex_matrix_override;
224 new_state = new_state->remove_attrib(TexMatrixAttrib::get_class_slot());
230 new_state->get_attrib(TextureAttrib::get_class_slot());
232 int texture_override = new_state->get_override(TextureAttrib::get_class_slot());
233 if (texture_override >= _texture_override ||
236 _texture = tex_attrib;
238 _texture = _texture->compose(tex_attrib);
240 _texture_override = texture_override;
249 if ((attrib_types & SceneGraphReducer::TT_clip_plane) != 0) {
251 new_state->get_attrib(ClipPlaneAttrib::get_class_slot());
253 int clip_plane_override = new_state->get_override(ClipPlaneAttrib::get_class_slot());
254 if (clip_plane_override >= _clip_plane_override ||
257 _clip_plane = node_attrib;
259 _clip_plane = _clip_plane->compose(node_attrib);
261 _clip_plane_override = clip_plane_override;
263 new_state = new_state->remove_attrib(ClipPlaneAttrib::get_class_slot());
267 if ((attrib_types & SceneGraphReducer::TT_cull_face) != 0) {
269 new_state->get_attrib(CullFaceAttrib::get_class_slot());
271 int cull_face_override = new_state->get_override(CullFaceAttrib::get_class_slot());
272 if (cull_face_override >= _cull_face_override ||
275 _cull_face = node_attrib;
277 _cull_face = _cull_face->compose(node_attrib);
279 _cull_face_override = cull_face_override;
281 new_state = new_state->remove_attrib(CullFaceAttrib::get_class_slot());
285 if ((attrib_types & SceneGraphReducer::TT_other) != 0) {
287 nassertr(_other != (
RenderState *)NULL, new_state);
288 _other = _other->compose(new_state);
289 new_state = RenderState::make_empty();
306 if ((attrib_types & SceneGraphReducer::TT_transform) != 0) {
307 node->
set_transform(_transform->compose(node->get_transform())->get_unique());
309 _transform = TransformState::make_identity();
312 if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
315 node->get_attrib(ColorAttrib::get_class_slot());
317 node->
set_attrib(_color->compose(node_attrib)->get_unique());
325 if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
328 node->get_attrib(ColorScaleAttrib::get_class_slot());
330 node->
set_attrib(_color_scale->compose(node_attrib)->get_unique());
338 if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
341 node->get_attrib(TexMatrixAttrib::get_class_slot());
343 node->
set_attrib(_tex_matrix->compose(node_attrib)->get_unique());
351 if ((attrib_types & SceneGraphReducer::TT_clip_plane) != 0) {
354 node->get_attrib(ClipPlaneAttrib::get_class_slot());
356 node->
set_attrib(_clip_plane->compose(node_attrib)->get_unique());
364 if ((attrib_types & SceneGraphReducer::TT_cull_face) != 0) {
367 node->get_attrib(CullFaceAttrib::get_class_slot());
369 node->
set_attrib(_cull_face->compose(node_attrib)->get_unique());
377 if ((attrib_types & SceneGraphReducer::TT_other) != 0) {
378 node->
set_state(_other->compose(node->get_state())->get_unique());
379 _other = RenderState::make_empty();
A basic node of the scene graph or data graph.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
void collect(PandaNode *node, int attrib_types)
Collects the state and transform from the indicated node and adds it to the accumulator, removing it from the node.
void reset_prev_transform(Thread *current_thread=Thread::get_current_thread())
Resets the transform that represents this node's "previous" position to the same as the current trans...
This class is used by the SceneGraphReducer to maintain and accumulate the set of attributes we have ...
void set_state(const RenderState *state, Thread *current_thread=Thread::get_current_thread())
Sets the complete RenderState that will be applied to all nodes at this level and below...
void set_attrib(const RenderAttrib *attrib, int override=0)
Adds the indicated render attribute to the scene graph on this node.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void set_prev_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Sets the transform that represents this node's "previous" position, one frame ago, for the purposes of detecting motion for accurate collision calculations.
void apply_to_node(PandaNode *node, int attrib_types)
Stores the indicated attributes in the node's transform and state information; does not attempt to ap...
void set_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Sets the transform that will be applied to this node and below.