Browse Source

early-out on empty Geoms

David Rose 18 years ago
parent
commit
b706a17f25
3 changed files with 24 additions and 0 deletions
  1. 13 0
      panda/src/gobj/geom.I
  2. 2 0
      panda/src/gobj/geom.h
  3. 9 0
      panda/src/pgraph/cullTraverser.cxx

+ 13 - 0
panda/src/gobj/geom.I

@@ -91,6 +91,19 @@ get_vertex_data(Thread *current_thread) const {
   return cdata->_data.get_read_pointer();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Geom::is_empty
+//       Access: Published
+//  Description: Returns true if there appear to be no vertices to be
+//               rendered by this Geom, false if has some actual data.
+////////////////////////////////////////////////////////////////////
+INLINE bool Geom::
+is_empty() const {
+  CDReader cdata(_cycler);
+  return (cdata->_data.get_read_pointer()->get_num_rows() == 0 ||
+          cdata->_primitives.empty());
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Geom::get_num_primitives
 //       Access: Published

+ 2 - 0
panda/src/gobj/geom.h

@@ -89,6 +89,8 @@ PUBLISHED:
   void offset_vertices(const GeomVertexData *data, int offset);
   int make_nonindexed(bool composite_only);
 
+  INLINE bool is_empty() const;
+
   INLINE int get_num_primitives() const;
   INLINE CPT(GeomPrimitive) get_primitive(int i) const;
   INLINE PT(GeomPrimitive) modify_primitive(int i);

+ 9 - 0
panda/src/pgraph/cullTraverser.cxx

@@ -266,6 +266,9 @@ traverse_below(CullTraverserData &data) {
 
       for (int i = 0; i < num_geoms; i++) {
         const Geom *geom = geoms.get_geom(i);
+        if (geom->is_empty()) {
+          continue;
+        }
 
         CPT(RenderState) state = data._state->compose(geoms.get_geom_state(i));
         if (state->has_cull_callback() && !state->cull_callback(this, data)) {
@@ -730,6 +733,9 @@ start_decal(const CullTraverserData &data) {
   
   for (int i = num_geoms - 1; i >= 0; i--) {
     const Geom *geom = geoms.get_geom(i);
+    if (geom->is_empty()) {
+      continue;
+    }
 
     CPT(RenderState) state = data._state->compose(geoms.get_geom_state(i));
     if (state->has_cull_callback() && !state->cull_callback(this, data)) {
@@ -839,6 +845,9 @@ r_get_decals(CullTraverserData &data, CullableObject *decals) {
 
       for (int i = num_geoms - 1; i >= 0; i--) {
         const Geom *geom = geoms.get_geom(i);
+        if (geom->is_empty()) {
+          continue;
+        }
 
         CPT(RenderState) state = data._state->compose(geoms.get_geom_state(i));
         if (state->has_cull_callback() && !state->cull_callback(this, data)) {