fix flatten not to move ClipPlaneAttribs by default

This commit is contained in:
David Rose 2007-05-15 23:20:41 +00:00
parent cff4b286ac
commit d544bb1bad
4 changed files with 94 additions and 4 deletions

View File

@ -40,6 +40,7 @@ AccumulatedAttribs(const AccumulatedAttribs &copy) :
_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 &copy) {
_color_scale = copy._color_scale;
_tex_matrix = copy._tex_matrix;
_texture = copy._texture;
_clip_plane = copy._clip_plane;
_other = copy._other;
}

View File

@ -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();

View File

@ -51,6 +51,7 @@ public:
CPT(RenderAttrib) _color_scale;
CPT(RenderAttrib) _tex_matrix;
CPT(RenderAttrib) _texture;
CPT(RenderAttrib) _clip_plane;
CPT(RenderState) _other;
};

View File

@ -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);