SceneGraphReducer needs to support new ColorAttrib semantics (not quite finished yet)

This commit is contained in:
Josh Yelon 2008-01-25 03:35:58 +00:00
parent 1d44682463
commit d0aac98dac
6 changed files with 89 additions and 1 deletions

View File

@ -98,6 +98,7 @@
#include "transformState.h"
#include "transparencyAttrib.h"
#include "nodePathLerps.h"
#include "shaderGenerator.h"
#include "dconfig.h"
@ -434,7 +435,7 @@ init_libpgraph() {
ShadeModelAttrib::init_type();
ShaderInput::init_type();
ShaderAttrib::init_type();
Shader::init_type();
ShaderGenerator::init_type();
ShowBoundsEffect::init_type();
Spotlight::init_type();
StateMunger::init_type();

View File

@ -141,6 +141,7 @@ apply_attribs_to_vertices(const AccumulatedAttribs &attribs, int attrib_types,
const ColorAttrib *ca = DCAST(ColorAttrib, geom_attribs._color);
if (ca->get_color_type() == ColorAttrib::T_flat) {
if (transformer.set_color(new_geom, ca->get_color())) {
entry._state = entry._state->add_attrib(ColorAttrib::make_vertex());
any_changed = true;
}
}

View File

@ -477,6 +477,44 @@ remove_column(GeomNode *node, const InternalName *column) {
return any_changed;
}
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::apply_colors
// Access: Public
// Description: Checks if the GeomNode has differing ColorAttribs.
// If so, all the colors for all the Geoms are pushed
// down into the vertices, and the differing
// ColorAttribs are removed.
////////////////////////////////////////////////////////////////////
bool GeomTransformer::
apply_colors(GeomNode *node) {
if (node->get_num_geoms() < 2) {
return false;
}
bool need_apply = false;
GeomNode::CDWriter cdata(node->_cycler);
GeomNode::GeomList::iterator gi;
GeomNode::GeomList &geoms = *(cdata->modify_geoms());
const RenderAttrib *first = geoms[0]._state->get_attrib(ColorAttrib::get_class_type());
for (gi = geoms.begin(); gi != geoms.end(); ++gi) {
GeomNode::GeomEntry &entry = (*gi);
if (entry._state->get_attrib(ColorAttrib::get_class_type()) != first) {
need_apply = true;
break;
}
}
if (!need_apply) {
return false;
}
// NOT IMPLEMENTED YET. DOESNT DO ANYTHING.
return true;
}
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::reverse_normals
// Access: Public

View File

@ -75,6 +75,8 @@ public:
bool remove_column(Geom *geom, const InternalName *column);
bool remove_column(GeomNode *node, const InternalName *column);
bool apply_colors(GeomNode *node);
bool reverse_normals(Geom *geom);
bool doubleside(GeomNode *node);
bool reverse(GeomNode *node);

View File

@ -31,6 +31,7 @@
PStatCollector SceneGraphReducer::_flatten_collector("*:Flatten:flatten");
PStatCollector SceneGraphReducer::_apply_collector("*:Flatten:apply");
PStatCollector SceneGraphReducer::_remove_column_collector("*:Flatten:remove column");
PStatCollector SceneGraphReducer::_apply_colors_collector("*:Flatten:apply colors");
PStatCollector SceneGraphReducer::_collect_collector("*:Flatten:collect");
PStatCollector SceneGraphReducer::_make_nonindexed_collector("*:Flatten:make nonindexed");
PStatCollector SceneGraphReducer::_unify_collector("*:Flatten:unify");
@ -147,6 +148,21 @@ remove_column(PandaNode *root, const InternalName *column) {
return r_remove_column(root, column, _transformer);
}
////////////////////////////////////////////////////////////////////
// Function: SceneGraphReducer::apply_colors
// Access: Published
// Description: Searches for GeomNodes that contain multiple Geoms
// that differ only in their ColorAttribs. If such a
// GeomNode is found, then all the colors are pushed
// down into the vertices. This makes it feasible for
// the geoms to be unified later.
////////////////////////////////////////////////////////////////////
int SceneGraphReducer::
apply_colors(PandaNode *root) {
PStatTimer timer(_apply_colors_collector);
return r_apply_colors(root, _transformer);
}
////////////////////////////////////////////////////////////////////
// Function: SceneGraphReducer::unify
// Access: Published
@ -741,6 +757,31 @@ r_remove_column(PandaNode *node, const InternalName *column,
return num_changed;
}
////////////////////////////////////////////////////////////////////
// Function: SceneGraphReducer::r_apply_colors
// Access: Private
// Description: The recursive implementation of apply_colors().
////////////////////////////////////////////////////////////////////
int SceneGraphReducer::
r_apply_colors(PandaNode *node, GeomTransformer &transformer) {
int num_changed = 0;
if (node->is_geom_node()) {
if (transformer.apply_colors(DCAST(GeomNode, node))) {
++num_changed;
}
}
PandaNode::Children children = node->get_children();
int num_children = children.get_num_children();
for (int i = 0; i < num_children; ++i) {
num_changed +=
r_apply_colors(children.get_child(i), transformer);
}
return num_changed;
}
////////////////////////////////////////////////////////////////////
// Function: SceneGraphReducer::r_collect_vertex_data
// Access: Private

View File

@ -138,6 +138,8 @@ PUBLISHED:
int remove_column(PandaNode *root, const InternalName *column);
int apply_colors(PandaNode *root);
INLINE int make_compatible_format(PandaNode *root, int collect_bits = ~0);
void decompose(PandaNode *root);
@ -175,6 +177,8 @@ protected:
int r_remove_column(PandaNode *node, const InternalName *column,
GeomTransformer &transformer);
int r_apply_colors(PandaNode *node, GeomTransformer &transformer);
int r_collect_vertex_data(PandaNode *node, int collect_bits,
GeomTransformer &transformer, bool format_only);
int r_make_nonindexed(PandaNode *node, int collect_bits);
@ -191,6 +195,7 @@ private:
static PStatCollector _flatten_collector;
static PStatCollector _apply_collector;
static PStatCollector _remove_column_collector;
static PStatCollector _apply_colors_collector;
static PStatCollector _collect_collector;
static PStatCollector _make_nonindexed_collector;
static PStatCollector _unify_collector;