diff --git a/panda/src/pgraph/config_pgraph.cxx b/panda/src/pgraph/config_pgraph.cxx index 57f443f340..0a9774581d 100644 --- a/panda/src/pgraph/config_pgraph.cxx +++ b/panda/src/pgraph/config_pgraph.cxx @@ -254,6 +254,23 @@ ConfigVariableBool premunge_data "encoding requirements, as appropriate. When this is false, the " "data will be munged at render time instead.")); +ConfigVariableBool preserve_geom_nodes +("preserve-geom-nodes", false, + PRC_DESC("This specifies the default value for the \"preserved\" flag on " + "every GeomNode created. When this is true, GeomNodes will not " + "be flattened, so setting this true effectively disables the " + "use of flatten to combine GeomNodes.")); + +ConfigVariableBool flatten_geoms +("flatten-geoms", true, + PRC_DESC("When this is true (the default), NodePath::flatten_strong() and " + "flatten_medium() will attempt to combine multiple Geoms into " + "as few Geoms as possible, by combing GeomVertexDatas and then " + "unifying. Setting this false disables this behavior, so that " + "NodePath flatten operations will only reduce nodes. This affects " + "only the NodePath interfaces; you may still make the lower-level " + "SceneGraphReducer calls directly.")); + ConfigVariableBool polylight_info ("polylight-info", false, PRC_DESC("Set this true to view some info statements regarding the polylight. " diff --git a/panda/src/pgraph/config_pgraph.h b/panda/src/pgraph/config_pgraph.h index 95373bdbf7..76839d6abf 100644 --- a/panda/src/pgraph/config_pgraph.h +++ b/panda/src/pgraph/config_pgraph.h @@ -55,6 +55,8 @@ extern ConfigVariableBool depth_offset_decals; extern ConfigVariableInt max_collect_vertices; extern ConfigVariableInt max_collect_indices; extern ConfigVariableBool premunge_data; +extern ConfigVariableBool preserve_geom_nodes; +extern ConfigVariableBool flatten_geoms; extern ConfigVariableBool polylight_info; extern ConfigVariableDouble lod_fade_time; diff --git a/panda/src/pgraph/geomNode.I b/panda/src/pgraph/geomNode.I index f9d80b304c..dddab8025a 100644 --- a/panda/src/pgraph/geomNode.I +++ b/panda/src/pgraph/geomNode.I @@ -17,9 +17,33 @@ //////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// Function: GeomNode::set_preserved +// Access: Published +// Description: Sets the "preserved" flag. When this is true, the +// GeomNode will be left untouched by any flatten +// operations. +//////////////////////////////////////////////////////////////////// +INLINE void GeomNode:: +set_preserved(bool value) { + _preserved = value; +} + +//////////////////////////////////////////////////////////////////// +// Function: GeomNode::get_preserved +// Access: Published +// Description: Returns the "preserved" flag. When this is true, the +// GeomNode will be left untouched by any flatten +// operations. +//////////////////////////////////////////////////////////////////// +INLINE bool GeomNode:: +get_preserved() const { + return _preserved; +} + //////////////////////////////////////////////////////////////////// // Function: GeomNode::get_num_geoms -// Access: Public +// Access: Published // Description: Returns the number of geoms in the node. //////////////////////////////////////////////////////////////////// INLINE int GeomNode:: @@ -29,19 +53,9 @@ get_num_geoms() const { } -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::get_num_geoms -// Access: Public -// Description: Returns the number of geoms in the node. -//////////////////////////////////////////////////////////////////// -INLINE void GeomNode:: -set_preserved(bool value){ - _preserved = value; -} - //////////////////////////////////////////////////////////////////// // Function: GeomNode::get_geom -// Access: Public +// Access: Published // Description: Returns the nth geom of the node. This object should // not be modified, since the same object might be // shared between multiple different GeomNodes, but see @@ -57,7 +71,7 @@ get_geom(int n) const { //////////////////////////////////////////////////////////////////// // Function: GeomNode::modify_geom -// Access: Public +// Access: Published // Description: Returns the nth geom of the node, suitable for // modifying it. If the nth Geom has multiple reference // counts to it, reassigns it to an identical copy @@ -84,7 +98,7 @@ modify_geom(int n) { //////////////////////////////////////////////////////////////////// // Function: GeomNode::get_geom_state -// Access: Public +// Access: Published // Description: Returns the RenderState associated with the nth geom // of the node. This is just the RenderState directly // associated with the Geom; the actual state in which @@ -102,7 +116,7 @@ get_geom_state(int n) const { //////////////////////////////////////////////////////////////////// // Function: GeomNode::set_geom_state -// Access: Public +// Access: Published // Description: Changes the RenderState associated with the nth geom // of the node. This is just the RenderState directly // associated with the Geom; the actual state in which @@ -194,7 +208,7 @@ get_name_count(const GeomNode::NameCount &name_count, const InternalName *name) //////////////////////////////////////////////////////////////////// // Function: GeomNode::get_geoms -// Access: Public +// Access: Published // Description: Returns an object that can be used to walk through // the list of geoms of the node. When you intend to // visit multiple geoms, using this is slightly diff --git a/panda/src/pgraph/geomNode.cxx b/panda/src/pgraph/geomNode.cxx index ad952e61b9..6274f07009 100644 --- a/panda/src/pgraph/geomNode.cxx +++ b/panda/src/pgraph/geomNode.cxx @@ -47,8 +47,9 @@ GeomNode:: GeomNode(const string &name) : PandaNode(name) { + _preserved = preserve_geom_nodes; + // GeomNodes have a certain set of bits on by default. - _preserved = false; set_into_collide_mask(get_default_collide_mask()); } @@ -280,38 +281,38 @@ xform(const LMatrix4f &mat) { //////////////////////////////////////////////////////////////////// // Function: GeomNode::safe_to_flatten // Access: Public, Virtual -// Description: Transforms the contents of this node by the indicated -// matrix, if it means anything to do so. For most -// kinds of nodes, this does nothing. -// -// For a GeomNode, this does the right thing, but it is -// better to use a GeomTransformer instead, since it -// will share the new arrays properly between different -// GeomNodes. +// Description: Returns true if it is generally safe to flatten out +// this particular kind of PandaNode by duplicating +// instances (by calling dupe_for_flatten()), false +// otherwise (for instance, a Camera cannot be safely +// flattened, because the Camera pointer itself is +// meaningful). //////////////////////////////////////////////////////////////////// bool GeomNode:: safe_to_flatten() const { - if(_preserved) + if (_preserved) { return false; + } + return true; } //////////////////////////////////////////////////////////////////// // Function: GeomNode::safe_to_combine // Access: Public, Virtual -// Description: Transforms the contents of this node by the indicated -// matrix, if it means anything to do so. For most -// kinds of nodes, this does nothing. -// -// For a GeomNode, this does the right thing, but it is -// better to use a GeomTransformer instead, since it -// will share the new arrays properly between different -// GeomNodes. +// Description: Returns true if it is generally safe to combine this +// particular kind of PandaNode with other kinds of +// PandaNodes of compatible type, adding children or +// whatever. For instance, an LODNode should not be +// combined with any other PandaNode, because its set of +// children is meaningful. //////////////////////////////////////////////////////////////////// bool GeomNode:: safe_to_combine() const { - if(_preserved) + if (_preserved) { return false; + } + return true; } diff --git a/panda/src/pgraph/geomNode.h b/panda/src/pgraph/geomNode.h index 29141893f7..8fc6dac96d 100644 --- a/panda/src/pgraph/geomNode.h +++ b/panda/src/pgraph/geomNode.h @@ -64,8 +64,9 @@ public: virtual bool safe_to_combine() const; PUBLISHED: - INLINE void set_preserved(bool value); + INLINE bool get_preserved() const; + INLINE int get_num_geoms() const; INLINE CPT(Geom) get_geom(int n) const; INLINE PT(Geom) modify_geom(int n); diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index e9a280bb61..1fb6a2f113 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -5838,8 +5838,10 @@ flatten_medium() { gr.apply_attribs(node()); int num_removed = gr.flatten(node(), 0); - gr.collect_vertex_data(node()); - gr.unify(node(), true); + if (flatten_geoms) { + gr.collect_vertex_data(node()); + gr.unify(node(), true); + } return num_removed; } @@ -5868,8 +5870,10 @@ flatten_strong() { gr.apply_attribs(node()); int num_removed = gr.flatten(node(), ~0); - gr.collect_vertex_data(node(), ~(SceneGraphReducer::CVD_format | SceneGraphReducer::CVD_name | SceneGraphReducer::CVD_animation_type)); - gr.unify(node(), false); + if (flatten_geoms) { + gr.collect_vertex_data(node(), ~(SceneGraphReducer::CVD_format | SceneGraphReducer::CVD_name | SceneGraphReducer::CVD_animation_type)); + gr.unify(node(), false); + } return num_removed; }