From d544bb1badcd830803e07e288106a85fd7391d82 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 15 May 2007 23:20:41 +0000 Subject: [PATCH] fix flatten not to move ClipPlaneAttribs by default --- panda/src/pgraph/accumulatedAttribs.I | 2 + panda/src/pgraph/accumulatedAttribs.cxx | 90 ++++++++++++++++++++++++- panda/src/pgraph/accumulatedAttribs.h | 1 + panda/src/pgraph/sceneGraphReducer.h | 5 +- 4 files changed, 94 insertions(+), 4 deletions(-) diff --git a/panda/src/pgraph/accumulatedAttribs.I b/panda/src/pgraph/accumulatedAttribs.I index bddea8acc2..3e83fa4393 100644 --- a/panda/src/pgraph/accumulatedAttribs.I +++ b/panda/src/pgraph/accumulatedAttribs.I @@ -40,6 +40,7 @@ AccumulatedAttribs(const AccumulatedAttribs ©) : _color_scale(copy._color_scale), _tex_matrix(copy._tex_matrix), _texture(copy._texture), + _clip_plane(copy._clip_plane), _other(copy._other) { } @@ -56,5 +57,6 @@ operator = (const AccumulatedAttribs ©) { _color_scale = copy._color_scale; _tex_matrix = copy._tex_matrix; _texture = copy._texture; + _clip_plane = copy._clip_plane; _other = copy._other; } diff --git a/panda/src/pgraph/accumulatedAttribs.cxx b/panda/src/pgraph/accumulatedAttribs.cxx index a893205072..153368db5e 100644 --- a/panda/src/pgraph/accumulatedAttribs.cxx +++ b/panda/src/pgraph/accumulatedAttribs.cxx @@ -23,6 +23,7 @@ #include "colorScaleAttrib.h" #include "texMatrixAttrib.h" #include "textureAttrib.h" +#include "clipPlaneAttrib.h" #include "config_pgraph.h" @@ -57,6 +58,13 @@ write(ostream &out, int attrib_types, int indent_level) const { _tex_matrix->write(out, indent_level); } } + if ((attrib_types & SceneGraphReducer::TT_clip_plane) != 0) { + if (_clip_plane == (const RenderAttrib *)NULL) { + indent(out, indent_level) << "no clip plane\n"; + } else { + _clip_plane->write(out, indent_level); + } + } if ((attrib_types & SceneGraphReducer::TT_other) != 0) { _other->write(out, indent_level); } @@ -137,11 +145,63 @@ collect(PandaNode *node, int attrib_types) { } } + if ((attrib_types & SceneGraphReducer::TT_clip_plane) != 0) { + const RenderAttrib *node_attrib = + node->get_attrib(ClipPlaneAttrib::get_class_type()); + if (node_attrib != (const RenderAttrib *)NULL) { + // The node has a clip plane attribute; apply it. + if (_clip_plane == (const RenderAttrib *)NULL) { + _clip_plane = node_attrib; + } else { + _clip_plane = _clip_plane->compose(node_attrib); + } + node->clear_attrib(ClipPlaneAttrib::get_class_type()); + } + } + if ((attrib_types & SceneGraphReducer::TT_other) != 0) { // Collect everything else. nassertv(_other != (RenderState *)NULL); - _other = _other->compose(node->get_state()); - node->set_state(RenderState::make_empty()); + CPT(RenderState) collect_state = node->get_state(); + CPT(RenderState) keep_state = RenderState::make_empty(); + + const RenderAttrib *attrib = collect_state->get_attrib(ColorAttrib::get_class_type()); + if (attrib != (const RenderAttrib *)NULL) { + int override = collect_state->get_override(ColorAttrib::get_class_type()); + collect_state = collect_state->remove_attrib(ColorAttrib::get_class_type()); + keep_state = keep_state->add_attrib(attrib, override); + } + + attrib = collect_state->get_attrib(ColorScaleAttrib::get_class_type()); + if (attrib != (const RenderAttrib *)NULL) { + int override = collect_state->get_override(ColorScaleAttrib::get_class_type()); + collect_state = collect_state->remove_attrib(ColorScaleAttrib::get_class_type()); + keep_state = keep_state->add_attrib(attrib, override); + } + + attrib = collect_state->get_attrib(TexMatrixAttrib::get_class_type()); + if (attrib != (const RenderAttrib *)NULL) { + int override = collect_state->get_override(TexMatrixAttrib::get_class_type()); + collect_state = collect_state->remove_attrib(TexMatrixAttrib::get_class_type()); + keep_state = keep_state->add_attrib(attrib, override); + } + + attrib = collect_state->get_attrib(TextureAttrib::get_class_type()); + if (attrib != (const RenderAttrib *)NULL) { + int override = collect_state->get_override(TextureAttrib::get_class_type()); + collect_state = collect_state->remove_attrib(TextureAttrib::get_class_type()); + keep_state = keep_state->add_attrib(attrib, override); + } + + attrib = collect_state->get_attrib(ClipPlaneAttrib::get_class_type()); + if (attrib != (const RenderAttrib *)NULL) { + int override = collect_state->get_override(ClipPlaneAttrib::get_class_type()); + collect_state = collect_state->remove_attrib(ClipPlaneAttrib::get_class_type()); + keep_state = keep_state->add_attrib(attrib, override); + } + + _other = _other->compose(collect_state); + node->set_state(keep_state); } } @@ -212,6 +272,19 @@ collect(const RenderState *state, int attrib_types) { } } + if ((attrib_types & SceneGraphReducer::TT_clip_plane) != 0) { + const RenderAttrib *node_attrib = + new_state->get_attrib(ClipPlaneAttrib::get_class_type()); + if (node_attrib != (const RenderAttrib *)NULL) { + if (_clip_plane == (const RenderAttrib *)NULL) { + _clip_plane = node_attrib; + } else { + _clip_plane = _clip_plane->compose(node_attrib); + } + new_state = new_state->remove_attrib(ClipPlaneAttrib::get_class_type()); + } + } + if ((attrib_types & SceneGraphReducer::TT_other) != 0) { // Collect everything else. nassertr(_other != (RenderState *)NULL, new_state); @@ -278,6 +351,19 @@ apply_to_node(PandaNode *node, int attrib_types) { } } + if ((attrib_types & SceneGraphReducer::TT_clip_plane) != 0) { + if (_clip_plane != (RenderAttrib *)NULL) { + const RenderAttrib *node_attrib = + node->get_attrib(ClipPlaneAttrib::get_class_type()); + if (node_attrib != (RenderAttrib *)NULL) { + node->set_attrib(_clip_plane->compose(node_attrib)); + } else { + node->set_attrib(_clip_plane); + } + _clip_plane = (RenderAttrib *)NULL; + } + } + if ((attrib_types & SceneGraphReducer::TT_other) != 0) { node->set_state(_other->compose(node->get_state())); _other = RenderState::make_empty(); diff --git a/panda/src/pgraph/accumulatedAttribs.h b/panda/src/pgraph/accumulatedAttribs.h index f2c7ce3b1d..f37d628c35 100644 --- a/panda/src/pgraph/accumulatedAttribs.h +++ b/panda/src/pgraph/accumulatedAttribs.h @@ -51,6 +51,7 @@ public: CPT(RenderAttrib) _color_scale; CPT(RenderAttrib) _tex_matrix; CPT(RenderAttrib) _texture; + CPT(RenderAttrib) _clip_plane; CPT(RenderState) _other; }; diff --git a/panda/src/pgraph/sceneGraphReducer.h b/panda/src/pgraph/sceneGraphReducer.h index 8f6da03e22..ff34944d6f 100644 --- a/panda/src/pgraph/sceneGraphReducer.h +++ b/panda/src/pgraph/sceneGraphReducer.h @@ -53,7 +53,8 @@ PUBLISHED: TT_color = 0x002, TT_color_scale = 0x004, TT_tex_matrix = 0x008, - TT_other = 0x010, + TT_clip_plane = 0x010, + TT_other = 0x020, }; enum CombineSiblings { @@ -123,7 +124,7 @@ PUBLISHED: INLINE void set_combine_radius(float combine_radius); INLINE float get_combine_radius() const; - INLINE void apply_attribs(PandaNode *node, int attrib_types = ~0); + INLINE void apply_attribs(PandaNode *node, int attrib_types = ~TT_clip_plane); INLINE void apply_attribs(PandaNode *node, const AccumulatedAttribs &attribs, int attrib_types, GeomTransformer &transformer);