Browse Source

add preserve-geom-nodes, flatten-geoms

David Rose 18 years ago
parent
commit
e11487f81f

+ 17 - 0
panda/src/pgraph/config_pgraph.cxx

@@ -254,6 +254,23 @@ ConfigVariableBool premunge_data
           "encoding requirements, as appropriate.  When this is false, the "
           "encoding requirements, as appropriate.  When this is false, the "
           "data will be munged at render time instead."));
           "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
 ConfigVariableBool polylight_info
 ("polylight-info", false,
 ("polylight-info", false,
  PRC_DESC("Set this true to view some info statements regarding the polylight. "
  PRC_DESC("Set this true to view some info statements regarding the polylight. "

+ 2 - 0
panda/src/pgraph/config_pgraph.h

@@ -55,6 +55,8 @@ extern ConfigVariableBool depth_offset_decals;
 extern ConfigVariableInt max_collect_vertices;
 extern ConfigVariableInt max_collect_vertices;
 extern ConfigVariableInt max_collect_indices;
 extern ConfigVariableInt max_collect_indices;
 extern ConfigVariableBool premunge_data;
 extern ConfigVariableBool premunge_data;
+extern ConfigVariableBool preserve_geom_nodes;
+extern ConfigVariableBool flatten_geoms;
 
 
 extern ConfigVariableBool polylight_info;
 extern ConfigVariableBool polylight_info;
 extern ConfigVariableDouble lod_fade_time;
 extern ConfigVariableDouble lod_fade_time;

+ 30 - 16
panda/src/pgraph/geomNode.I

@@ -18,30 +18,44 @@
 
 
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: GeomNode::get_num_geoms
-//       Access: Public
-//  Description: Returns the number of geoms in the node.
+//     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 int GeomNode::
-get_num_geoms() const {
-  CDReader cdata(_cycler);
-  return cdata->get_geoms()->size();
+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
 //     Function: GeomNode::get_num_geoms
-//       Access: Public
+//       Access: Published
 //  Description: Returns the number of geoms in the node.
 //  Description: Returns the number of geoms in the node.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-INLINE void GeomNode::
-set_preserved(bool value){
-  _preserved = value;
+INLINE int GeomNode::
+get_num_geoms() const {
+  CDReader cdata(_cycler);
+  return cdata->get_geoms()->size();
 }
 }
 
 
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomNode::get_geom
 //     Function: GeomNode::get_geom
-//       Access: Public
+//       Access: Published
 //  Description: Returns the nth geom of the node.  This object should
 //  Description: Returns the nth geom of the node.  This object should
 //               not be modified, since the same object might be
 //               not be modified, since the same object might be
 //               shared between multiple different GeomNodes, but see
 //               shared between multiple different GeomNodes, but see
@@ -57,7 +71,7 @@ get_geom(int n) const {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomNode::modify_geom
 //     Function: GeomNode::modify_geom
-//       Access: Public
+//       Access: Published
 //  Description: Returns the nth geom of the node, suitable for
 //  Description: Returns the nth geom of the node, suitable for
 //               modifying it.  If the nth Geom has multiple reference
 //               modifying it.  If the nth Geom has multiple reference
 //               counts to it, reassigns it to an identical copy
 //               counts to it, reassigns it to an identical copy
@@ -84,7 +98,7 @@ modify_geom(int n) {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomNode::get_geom_state
 //     Function: GeomNode::get_geom_state
-//       Access: Public
+//       Access: Published
 //  Description: Returns the RenderState associated with the nth geom
 //  Description: Returns the RenderState associated with the nth geom
 //               of the node.  This is just the RenderState directly
 //               of the node.  This is just the RenderState directly
 //               associated with the Geom; the actual state in which
 //               associated with the Geom; the actual state in which
@@ -102,7 +116,7 @@ get_geom_state(int n) const {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomNode::set_geom_state
 //     Function: GeomNode::set_geom_state
-//       Access: Public
+//       Access: Published
 //  Description: Changes the RenderState associated with the nth geom
 //  Description: Changes the RenderState associated with the nth geom
 //               of the node.  This is just the RenderState directly
 //               of the node.  This is just the RenderState directly
 //               associated with the Geom; the actual state in which
 //               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
 //     Function: GeomNode::get_geoms
-//       Access: Public
+//       Access: Published
 //  Description: Returns an object that can be used to walk through
 //  Description: Returns an object that can be used to walk through
 //               the list of geoms of the node.  When you intend to
 //               the list of geoms of the node.  When you intend to
 //               visit multiple geoms, using this is slightly
 //               visit multiple geoms, using this is slightly

+ 20 - 19
panda/src/pgraph/geomNode.cxx

@@ -47,8 +47,9 @@ GeomNode::
 GeomNode(const string &name) :
 GeomNode(const string &name) :
   PandaNode(name)
   PandaNode(name)
 {
 {
+  _preserved = preserve_geom_nodes;
+
   // GeomNodes have a certain set of bits on by default.
   // GeomNodes have a certain set of bits on by default.
-  _preserved = false;
   set_into_collide_mask(get_default_collide_mask());
   set_into_collide_mask(get_default_collide_mask());
 }
 }
 
 
@@ -280,38 +281,38 @@ xform(const LMatrix4f &mat) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomNode::safe_to_flatten
 //     Function: GeomNode::safe_to_flatten
 //       Access: Public, Virtual
 //       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::
 bool GeomNode::
 safe_to_flatten() const {
 safe_to_flatten() const {
-  if(_preserved)
+  if (_preserved) {
     return false;
     return false;
+  }
+
   return true;
   return true;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GeomNode::safe_to_combine
 //     Function: GeomNode::safe_to_combine
 //       Access: Public, Virtual
 //       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::
 bool GeomNode::
 safe_to_combine() const {
 safe_to_combine() const {
-  if(_preserved)
+  if (_preserved) {
     return false;
     return false;
+  }
+
   return true;
   return true;
 }
 }
 
 

+ 2 - 1
panda/src/pgraph/geomNode.h

@@ -64,8 +64,9 @@ public:
   virtual bool safe_to_combine() const;
   virtual bool safe_to_combine() const;
 
 
 PUBLISHED:
 PUBLISHED:
-
   INLINE void set_preserved(bool value);
   INLINE void set_preserved(bool value);
+  INLINE bool get_preserved() const;
+
   INLINE int get_num_geoms() const;
   INLINE int get_num_geoms() const;
   INLINE CPT(Geom) get_geom(int n) const;
   INLINE CPT(Geom) get_geom(int n) const;
   INLINE PT(Geom) modify_geom(int n);
   INLINE PT(Geom) modify_geom(int n);

+ 8 - 4
panda/src/pgraph/nodePath.cxx

@@ -5838,8 +5838,10 @@ flatten_medium() {
   gr.apply_attribs(node());
   gr.apply_attribs(node());
   int num_removed = gr.flatten(node(), 0);
   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;
   return num_removed;
 }
 }
@@ -5868,8 +5870,10 @@ flatten_strong() {
   gr.apply_attribs(node());
   gr.apply_attribs(node());
   int num_removed = gr.flatten(node(), ~0);
   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;
   return num_removed;
 }
 }