fix white nametag issue

This commit is contained in:
David Rose 2008-01-29 01:56:55 +00:00
parent 48f0aeaddf
commit a3999eff61
6 changed files with 158 additions and 215 deletions

View File

@ -16,49 +16,3 @@
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: AccumulatedAttribs::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE AccumulatedAttribs::
AccumulatedAttribs() {
_transform = TransformState::make_identity();
_other = RenderState::make_empty();
}
////////////////////////////////////////////////////////////////////
// Function: AccumulatedAttribs::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE AccumulatedAttribs::
AccumulatedAttribs(const AccumulatedAttribs &copy) :
_transform(copy._transform),
_color(copy._color),
_color_scale(copy._color_scale),
_tex_matrix(copy._tex_matrix),
_texture(copy._texture),
_clip_plane(copy._clip_plane),
_cull_face(copy._cull_face),
_other(copy._other)
{
}
////////////////////////////////////////////////////////////////////
// Function: AccumulatedAttribs::Copy Assignment
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void AccumulatedAttribs::
operator = (const AccumulatedAttribs &copy) {
_transform = copy._transform;
_color = copy._color;
_color_scale = copy._color_scale;
_tex_matrix = copy._tex_matrix;
_texture = copy._texture;
_clip_plane = copy._clip_plane;
_cull_face = copy._cull_face;
_other = copy._other;
}

View File

@ -28,6 +28,70 @@
#include "config_pgraph.h"
////////////////////////////////////////////////////////////////////
// Function: AccumulatedAttribs::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
AccumulatedAttribs::
AccumulatedAttribs() {
_transform = TransformState::make_identity();
_color_override = 0;
_color_scale_override = 0;
_tex_matrix_override = 0;
_texture_override = 0;
_clip_plane_override = 0;
_cull_face_override = 0;
_other = RenderState::make_empty();
}
////////////////////////////////////////////////////////////////////
// Function: AccumulatedAttribs::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
AccumulatedAttribs::
AccumulatedAttribs(const AccumulatedAttribs &copy) :
_transform(copy._transform),
_color(copy._color),
_color_override(copy._color_override),
_color_scale(copy._color_scale),
_color_scale_override(copy._color_scale_override),
_tex_matrix(copy._tex_matrix),
_tex_matrix_override(copy._tex_matrix_override),
_texture(copy._texture),
_texture_override(copy._texture_override),
_clip_plane(copy._clip_plane),
_clip_plane_override(copy._clip_plane_override),
_cull_face(copy._cull_face),
_cull_face_override(copy._cull_face_override),
_other(copy._other)
{
}
////////////////////////////////////////////////////////////////////
// Function: AccumulatedAttribs::Copy Assignment
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void AccumulatedAttribs::
operator = (const AccumulatedAttribs &copy) {
_transform = copy._transform;
_color = copy._color;
_color_override = copy._color_override;
_color_scale = copy._color_scale;
_color_scale_override = copy._color_scale_override;
_tex_matrix = copy._tex_matrix;
_tex_matrix_override = copy._tex_matrix_override;
_texture = copy._texture;
_texture_override = copy._texture_override;
_clip_plane = copy._clip_plane;
_clip_plane_override = copy._clip_plane_override;
_cull_face = copy._cull_face;
_cull_face_override = copy._cull_face_override;
_other = copy._other;
}
////////////////////////////////////////////////////////////////////
// Function: AccumulatedAttribs::write
// Access: Public
@ -95,136 +159,8 @@ collect(PandaNode *node, int attrib_types) {
node->set_prev_transform(TransformState::make_identity());
}
if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
const RenderAttrib *node_attrib =
node->get_attrib(ColorAttrib::get_class_type());
if (node_attrib != (const RenderAttrib *)NULL) {
// The node has a color attribute; apply it.
if (_color == (const RenderAttrib *)NULL) {
_color = node_attrib;
} else {
_color = _color->compose(node_attrib);
}
node->clear_attrib(ColorAttrib::get_class_type());
}
}
if ((attrib_types & SceneGraphReducer::TT_color_scale) != 0) {
const RenderAttrib *node_attrib =
node->get_attrib(ColorScaleAttrib::get_class_type());
if (node_attrib != (const RenderAttrib *)NULL) {
// The node has a color scale attribute; apply it.
if (_color_scale == (const RenderAttrib *)NULL) {
_color_scale = node_attrib;
} else {
_color_scale = _color_scale->compose(node_attrib);
}
node->clear_attrib(ColorScaleAttrib::get_class_type());
}
}
if ((attrib_types & SceneGraphReducer::TT_tex_matrix) != 0) {
const RenderAttrib *node_attrib =
node->get_attrib(TexMatrixAttrib::get_class_type());
if (node_attrib != (const RenderAttrib *)NULL) {
// The node has a tex matrix attribute; apply it.
if (_tex_matrix == (const RenderAttrib *)NULL) {
_tex_matrix = node_attrib;
} else {
_tex_matrix = _tex_matrix->compose(node_attrib);
}
node->clear_attrib(TexMatrixAttrib::get_class_type());
}
// We also need to accumulate the texture state if we are
// accumulating texture matrix.
const RenderAttrib *tex_attrib =
node->get_attrib(TextureAttrib::get_class_type());
if (tex_attrib != (const RenderAttrib *)NULL) {
if (_texture == (const RenderAttrib *)NULL) {
_texture = tex_attrib;
} else {
_texture = _texture->compose(tex_attrib);
}
// However, we don't remove the texture state from the node.
// We're just accumulating it so we can tell which texture
// coordinates are safe to flatten.
}
}
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_cull_face) != 0) {
const RenderAttrib *node_attrib =
node->get_attrib(CullFaceAttrib::get_class_type());
if (node_attrib != (const RenderAttrib *)NULL) {
// The node has a cull face attribute; apply it.
if (_cull_face == (const RenderAttrib *)NULL) {
_cull_face = node_attrib;
} else {
_cull_face = _cull_face->compose(node_attrib);
}
node->clear_attrib(CullFaceAttrib::get_class_type());
}
}
if ((attrib_types & SceneGraphReducer::TT_other) != 0) {
// Collect everything else.
nassertv(_other != (RenderState *)NULL);
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(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);
}
attrib = collect_state->get_attrib(CullFaceAttrib::get_class_type());
if (attrib != (const RenderAttrib *)NULL) {
int override = collect_state->get_override(CullFaceAttrib::get_class_type());
collect_state = collect_state->remove_attrib(CullFaceAttrib::get_class_type());
keep_state = keep_state->add_attrib(attrib, override);
}
_other = _other->compose(collect_state);
node->set_state(keep_state);
}
CPT(RenderState) new_state = collect(node->get_state(), attrib_types);
node->set_state(new_state);
}
////////////////////////////////////////////////////////////////////
@ -242,11 +178,15 @@ collect(const RenderState *state, int attrib_types) {
const RenderAttrib *node_attrib =
new_state->get_attrib(ColorAttrib::get_class_type());
if (node_attrib != (const RenderAttrib *)NULL) {
// The node has a color attribute; apply it.
if (_color == (const RenderAttrib *)NULL) {
_color = node_attrib;
} else {
_color = _color->compose(node_attrib);
int color_override = new_state->get_override(ColorAttrib::get_class_type());
if (color_override >= _color_override) {
// The node has a color attribute; apply it.
if (_color == (const RenderAttrib *)NULL) {
_color = node_attrib;
} else {
_color = _color->compose(node_attrib);
}
_color_override = color_override;
}
new_state = new_state->remove_attrib(ColorAttrib::get_class_type());
}
@ -256,10 +196,14 @@ collect(const RenderState *state, int attrib_types) {
const RenderAttrib *node_attrib =
new_state->get_attrib(ColorScaleAttrib::get_class_type());
if (node_attrib != (const RenderAttrib *)NULL) {
if (_color_scale == (const RenderAttrib *)NULL) {
_color_scale = node_attrib;
} else {
_color_scale = _color_scale->compose(node_attrib);
int color_scale_override = new_state->get_override(ColorScaleAttrib::get_class_type());
if (color_scale_override >= _color_scale_override) {
if (_color_scale == (const RenderAttrib *)NULL) {
_color_scale = node_attrib;
} else {
_color_scale = _color_scale->compose(node_attrib);
}
_color_scale_override = color_scale_override;
}
new_state = new_state->remove_attrib(ColorScaleAttrib::get_class_type());
}
@ -269,10 +213,14 @@ collect(const RenderState *state, int attrib_types) {
const RenderAttrib *node_attrib =
new_state->get_attrib(TexMatrixAttrib::get_class_type());
if (node_attrib != (const RenderAttrib *)NULL) {
if (_tex_matrix == (const RenderAttrib *)NULL) {
_tex_matrix = node_attrib;
} else {
_tex_matrix = _tex_matrix->compose(node_attrib);
int tex_matrix_override = new_state->get_override(TexMatrixAttrib::get_class_type());
if (tex_matrix_override >= _tex_matrix_override) {
if (_tex_matrix == (const RenderAttrib *)NULL) {
_tex_matrix = node_attrib;
} else {
_tex_matrix = _tex_matrix->compose(node_attrib);
}
_tex_matrix_override = tex_matrix_override;
}
new_state = new_state->remove_attrib(TexMatrixAttrib::get_class_type());
}
@ -282,10 +230,14 @@ collect(const RenderState *state, int attrib_types) {
const RenderAttrib *tex_attrib =
new_state->get_attrib(TextureAttrib::get_class_type());
if (tex_attrib != (const RenderAttrib *)NULL) {
if (_texture == (const RenderAttrib *)NULL) {
_texture = tex_attrib;
} else {
_texture = _texture->compose(tex_attrib);
int texture_override = new_state->get_override(TextureAttrib::get_class_type());
if (texture_override >= _texture_override) {
if (_texture == (const RenderAttrib *)NULL) {
_texture = tex_attrib;
} else {
_texture = _texture->compose(tex_attrib);
}
_texture_override = texture_override;
}
// However, we don't remove the texture state from the node.
@ -298,10 +250,14 @@ collect(const RenderState *state, int attrib_types) {
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);
int clip_plane_override = new_state->get_override(ClipPlaneAttrib::get_class_type());
if (clip_plane_override >= _clip_plane_override) {
if (_clip_plane == (const RenderAttrib *)NULL) {
_clip_plane = node_attrib;
} else {
_clip_plane = _clip_plane->compose(node_attrib);
}
_clip_plane_override = clip_plane_override;
}
new_state = new_state->remove_attrib(ClipPlaneAttrib::get_class_type());
}
@ -311,10 +267,14 @@ collect(const RenderState *state, int attrib_types) {
const RenderAttrib *node_attrib =
new_state->get_attrib(CullFaceAttrib::get_class_type());
if (node_attrib != (const RenderAttrib *)NULL) {
if (_cull_face == (const RenderAttrib *)NULL) {
_cull_face = node_attrib;
} else {
_cull_face = _cull_face->compose(node_attrib);
int cull_face_override = new_state->get_override(CullFaceAttrib::get_class_type());
if (cull_face_override >= _cull_face_override) {
if (_cull_face == (const RenderAttrib *)NULL) {
_cull_face = node_attrib;
} else {
_cull_face = _cull_face->compose(node_attrib);
}
_cull_face_override = cull_face_override;
}
new_state = new_state->remove_attrib(CullFaceAttrib::get_class_type());
}

View File

@ -36,9 +36,9 @@ class PandaNode;
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PGRAPH AccumulatedAttribs {
public:
INLINE AccumulatedAttribs();
INLINE AccumulatedAttribs(const AccumulatedAttribs &copy);
INLINE void operator = (const AccumulatedAttribs &copy);
AccumulatedAttribs();
AccumulatedAttribs(const AccumulatedAttribs &copy);
void operator = (const AccumulatedAttribs &copy);
void write(ostream &out, int attrib_types, int indent_level) const;
@ -48,11 +48,17 @@ public:
CPT(TransformState) _transform;
CPT(RenderAttrib) _color;
int _color_override;
CPT(RenderAttrib) _color_scale;
int _color_scale_override;
CPT(RenderAttrib) _tex_matrix;
int _tex_matrix_override;
CPT(RenderAttrib) _texture;
int _texture_override;
CPT(RenderAttrib) _clip_plane;
int _clip_plane_override;
CPT(RenderAttrib) _cull_face;
int _cull_face_override;
CPT(RenderState) _other;
};

View File

@ -137,12 +137,19 @@ apply_attribs_to_vertices(const AccumulatedAttribs &attribs, int attrib_types,
bool any_changed = false;
if ((attrib_types & SceneGraphReducer::TT_color) != 0) {
const RenderAttrib *ra = geom_attribs._color;
CPT(RenderAttrib) ra = geom_attribs._color;
int override = geom_attribs._color_override;
if (ra == (const RenderAttrib *)NULL) {
// If we don't have a color attrib, implicitly apply the
// "off" attrib. But use an override of -1, so we don't
// replace a color attrib already on the Geom state.
ra = ColorAttrib::make_off();
override = -1;
}
entry._state = entry._state->add_attrib(ra, override);
ra = entry._state->get_attrib(ColorAttrib::get_class_type());
const ColorAttrib *ca = DCAST(ColorAttrib, ra);
entry._state = entry._state->add_attrib(ca);
if (ca->get_color_type() != ColorAttrib::T_vertex) {
if (transformer.remove_column(new_geom, InternalName::get_color())) {
any_changed = true;

View File

@ -524,7 +524,7 @@ make_compatible_state(GeomNode *node) {
for (int i = 0; i < (int)geoms.size(); i++) {
GeomNode::GeomEntry &entry = geoms[i];
CPT(RenderState) canon = entry._state->add_attrib(ColorAttrib::make_vertex());
CPT(RenderState) canon = entry._state->add_attrib(ColorAttrib::make_vertex(), -1);
state_table[canon].push_back(i);
}

View File

@ -510,7 +510,8 @@ invert_compose(const RenderState *other) const {
// Description: Returns a new RenderState object that represents the
// same as the source state, with the new RenderAttrib
// added. If there is already a RenderAttrib with the
// same type, it is replaced.
// same type, it is replaced (unless the override is
// lower).
////////////////////////////////////////////////////////////////////
CPT(RenderState) RenderState::
add_attrib(const RenderAttrib *attrib, int override) const {
@ -526,17 +527,32 @@ add_attrib(const RenderAttrib *attrib, int override) const {
++ai;
++result;
}
*result = new_attribute;
++result;
if (ai != _attributes.end() && !(new_attribute < (*ai))) {
// At this point we know:
// !((*ai) < new_attribute) && !(new_attribute < (*ai))
// which means (*ai) == new_attribute--so we should leave it out,
// to avoid duplicating attributes in the set.
++ai;
// At this point we know: !((*ai) < new_attribute) &&
// !(new_attribute < (*ai)) which means (*ai) == new_attribute, so
// there is another attribute of the same type already in the
// state.
if ((*ai)._override > override) {
// The existing attribute overrides.
*result = *ai;
++ai;
} else {
// The new attribute overrides.
*result = new_attribute;
++ai;
++result;
}
} else {
// There is not another attribute of the same type already in the
// state.
*result = new_attribute;
++result;
}
while (ai != _attributes.end()) {
*result = *ai;
++ai;