Browse Source

show-cpu-animation

David Rose 21 years ago
parent
commit
160099a0ec

+ 8 - 6
panda/src/dxgsg8/dxGeomMunger8.cxx

@@ -67,12 +67,14 @@ munge_format_impl(const qpGeomVertexFormat *orig,
 
 
   if (animation.get_animation_type() == qpGeomVertexAnimationSpec::AT_hardware &&
   if (animation.get_animation_type() == qpGeomVertexAnimationSpec::AT_hardware &&
       animation.get_num_transforms() > 0) {
       animation.get_num_transforms() > 0) {
-    // If we want hardware animation, we need to reserve space for the
-    // blend weights.
-    new_array_format->add_column
-      (InternalName::get_transform_weight(), animation.get_num_transforms() - 1,
-       qpGeomVertexColumn::NT_float32, qpGeomVertexColumn::C_other);
-
+    if (animation.get_num_transforms() > 1) {
+      // If we want hardware animation, we need to reserve space for the
+      // blend weights.
+      new_array_format->add_column
+        (InternalName::get_transform_weight(), animation.get_num_transforms() - 1,
+         qpGeomVertexColumn::NT_float32, qpGeomVertexColumn::C_other);
+    }
+      
     if (animation.get_indexed_transforms()) {
     if (animation.get_indexed_transforms()) {
       // Also, if we'll be indexing into the transfom palette, reserve
       // Also, if we'll be indexing into the transfom palette, reserve
       // space for the index.
       // space for the index.

+ 7 - 7
panda/src/dxgsg8/dxVertexBufferContext8.cxx

@@ -56,14 +56,14 @@ DXVertexBufferContext8(qpGeomVertexArrayData *data) :
       // We have hardware vertex animation.
       // We have hardware vertex animation.
       num_blend_values = array_format->get_column(n)->get_num_values();
       num_blend_values = array_format->get_column(n)->get_num_values();
       ++n;
       ++n;
+    }
       
       
-      if (n < num_columns &&
-          array_format->get_column(n)->get_name() == InternalName::get_transform_index()) {
-        // Furthermore, it's indexed vertex animation.
-        _fvf |= D3DFVF_LASTBETA_UBYTE4;
-        ++num_blend_values;
-        ++n;
-      }
+    if (n < num_columns &&
+        array_format->get_column(n)->get_name() == InternalName::get_transform_index()) {
+      // Furthermore, it's indexed vertex animation.
+      _fvf |= D3DFVF_LASTBETA_UBYTE4;
+      ++num_blend_values;
+      ++n;
     }
     }
 
 
     switch (num_blend_values) {
     switch (num_blend_values) {

+ 1 - 1
panda/src/gobj/qpgeomVertexArrayFormat.cxx

@@ -217,7 +217,7 @@ add_column(const InternalName *name, int num_components,
   }
   }
 
 
   return add_column(qpGeomVertexColumn(name, num_components, 
   return add_column(qpGeomVertexColumn(name, num_components, 
-                                            numeric_type, contents, start));
+                                       numeric_type, contents, start));
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 2 - 2
panda/src/gobj/qpgeomVertexColumn.cxx

@@ -25,8 +25,8 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 qpGeomVertexColumn::
 qpGeomVertexColumn::
 qpGeomVertexColumn(const InternalName *name, int num_components,
 qpGeomVertexColumn(const InternalName *name, int num_components,
-                     NumericType numeric_type, Contents contents,
-                     int start) :
+                   NumericType numeric_type, Contents contents,
+                   int start) :
   _name(name),
   _name(name),
   _num_components(num_components),
   _num_components(num_components),
   _num_values(num_components),
   _num_values(num_components),

+ 59 - 7
panda/src/gobj/qpgeomVertexData.cxx

@@ -514,7 +514,9 @@ copy_from(const qpGeomVertexData &source, bool keep_data_objects) {
               indices[i] = add_transform(transform_palette, blend.get_transform(i),
               indices[i] = add_transform(transform_palette, blend.get_transform(i),
                                          already_added);
                                          already_added);
             }
             }
-            weight.set_data4f(weights);
+            if (weight.has_column()) {
+              weight.set_data4f(weights);
+            }
             index.set_data4i(indices);
             index.set_data4i(indices);
           }
           }
         } else {
         } else {
@@ -533,7 +535,9 @@ copy_from(const qpGeomVertexData &source, bool keep_data_objects) {
               nassertv(index <= 4);
               nassertv(index <= 4);
               weights[index] = blend.get_weight(i);
               weights[index] = blend.get_weight(i);
             }
             }
-            weight.set_data4f(weights);
+            if (weight.has_column()) {
+              weight.set_data4f(weights);
+            }
           }
           }
         }
         }
         
         
@@ -574,6 +578,34 @@ convert_to(const qpGeomVertexFormat *new_format) const {
   return new_data;
   return new_data;
 }
 }
 
 
+
+////////////////////////////////////////////////////////////////////
+//     Function: qpGeomVertexData::scale_color
+//       Access: Published
+//  Description: Returns a new GeomVertexData object with the color
+//               table modified in-place to apply the indicated scale.
+////////////////////////////////////////////////////////////////////
+CPT(qpGeomVertexData) qpGeomVertexData::
+scale_color(const LVecBase4f &color_scale) const {
+  const qpGeomVertexColumn *old_column = 
+    _format->get_column(InternalName::get_color());
+  if (old_column == (qpGeomVertexColumn *)NULL) {
+    return this;
+  }
+
+  PT(qpGeomVertexData) new_data = new qpGeomVertexData(*this);
+  qpGeomVertexRewriter data(new_data, InternalName::get_color());
+  while (!data.is_at_end()) {
+    Colorf color = data.get_data4f();
+    data.set_data4f(color[0] * color_scale[0],
+                    color[1] * color_scale[1],
+                    color[2] * color_scale[2],
+                    color[3] * color_scale[3]);
+  }
+
+  return new_data;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: qpGeomVertexData::scale_color
 //     Function: qpGeomVertexData::scale_color
 //       Access: Published
 //       Access: Published
@@ -622,6 +654,29 @@ scale_color(const LVecBase4f &color_scale, int num_components,
   return new_data;
   return new_data;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: qpGeomVertexData::set_color
+//       Access: Published
+//  Description: Returns a new GeomVertexData object with the color
+//               data modified in-place with the new value.
+////////////////////////////////////////////////////////////////////
+CPT(qpGeomVertexData) qpGeomVertexData::
+set_color(const Colorf &color) const {
+  const qpGeomVertexColumn *old_column = 
+    _format->get_column(InternalName::get_color());
+  if (old_column == (qpGeomVertexColumn *)NULL) {
+    return this;
+  }
+
+  PT(qpGeomVertexData) new_data = new qpGeomVertexData(*this);
+  qpGeomVertexWriter to(new_data, InternalName::get_color());
+  while (!to.is_at_end()) {
+    to.set_data4f(color);
+  }
+
+  return new_data;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: qpGeomVertexData::set_color
 //     Function: qpGeomVertexData::set_color
 //       Access: Published
 //       Access: Published
@@ -636,11 +691,9 @@ CPT(qpGeomVertexData) qpGeomVertexData::
 set_color(const Colorf &color, int num_components,
 set_color(const Colorf &color, int num_components,
           qpGeomVertexColumn::NumericType numeric_type,
           qpGeomVertexColumn::NumericType numeric_type,
           qpGeomVertexColumn::Contents contents) const {
           qpGeomVertexColumn::Contents contents) const {
-  int num_vertices = get_num_vertices();
-
   if (gobj_cat.is_debug()) {
   if (gobj_cat.is_debug()) {
     gobj_cat.debug()
     gobj_cat.debug()
-      << "Setting color for " << num_vertices << " vertices to "
+      << "Setting color for " << get_num_vertices() << " vertices to "
       << color << ".\n";
       << color << ".\n";
   }
   }
   PStatTimer timer(_set_color_pcollector);
   PStatTimer timer(_set_color_pcollector);
@@ -651,8 +704,7 @@ set_color(const Colorf &color, int num_components,
 
 
   // Now go through and set the new color value.
   // Now go through and set the new color value.
   qpGeomVertexWriter to(new_data, InternalName::get_color());
   qpGeomVertexWriter to(new_data, InternalName::get_color());
-
-  for (int i = 0; i < num_vertices; i++) {
+  while (!to.is_at_end()) {
     to.set_data4f(color);
     to.set_data4f(color);
   }
   }
 
 

+ 4 - 0
panda/src/gobj/qpgeomVertexData.h

@@ -112,10 +112,14 @@ PUBLISHED:
 
 
   void copy_from(const qpGeomVertexData &source, bool keep_data_objects);
   void copy_from(const qpGeomVertexData &source, bool keep_data_objects);
   CPT(qpGeomVertexData) convert_to(const qpGeomVertexFormat *new_format) const;
   CPT(qpGeomVertexData) convert_to(const qpGeomVertexFormat *new_format) const;
+  CPT(qpGeomVertexData) 
+    scale_color(const LVecBase4f &color_scale) const;
   CPT(qpGeomVertexData) 
   CPT(qpGeomVertexData) 
     scale_color(const LVecBase4f &color_scale, int num_components,
     scale_color(const LVecBase4f &color_scale, int num_components,
                 qpGeomVertexColumn::NumericType numeric_type,
                 qpGeomVertexColumn::NumericType numeric_type,
                 qpGeomVertexColumn::Contents contents) const;
                 qpGeomVertexColumn::Contents contents) const;
+  CPT(qpGeomVertexData) 
+    set_color(const Colorf &color) const;
   CPT(qpGeomVertexData) 
   CPT(qpGeomVertexData) 
     set_color(const Colorf &color, int num_components,
     set_color(const Colorf &color, int num_components,
               qpGeomVertexColumn::NumericType numeric_type,
               qpGeomVertexColumn::NumericType numeric_type,

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

@@ -164,6 +164,14 @@ ConfigVariableDouble lod_fade_time
  PRC_DESC("The default amount of time (in seconds) over which a FadeLODNode "
  PRC_DESC("The default amount of time (in seconds) over which a FadeLODNode "
           "transitions between its different levels."));
           "transitions between its different levels."));
 
 
+
+ConfigVariableBool show_cpu_animation
+("show-cpu-animation", false,
+ PRC_DESC("Set this true to flash any objects that are animated via Panda, "
+          "on the CPU, so you can visually see what's being animated on "
+          "the CPU and what's being animated by hardware.  This only "
+          "has effect when NDEBUG is defined."));
+
 ConfigVariableBool m_dual
 ConfigVariableBool m_dual
 ("m-dual", true,
 ("m-dual", true,
  PRC_DESC("Set this false to disable TransparencyAttrib::M_dual altogether "
  PRC_DESC("Set this false to disable TransparencyAttrib::M_dual altogether "

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

@@ -44,6 +44,8 @@ extern ConfigVariableBool auto_break_cycles;
 extern ConfigVariableBool polylight_info;
 extern ConfigVariableBool polylight_info;
 extern ConfigVariableDouble lod_fade_time;
 extern ConfigVariableDouble lod_fade_time;
 
 
+extern ConfigVariableBool show_cpu_animation;
+
 extern ConfigVariableBool m_dual;
 extern ConfigVariableBool m_dual;
 extern ConfigVariableBool m_dual_opaque;
 extern ConfigVariableBool m_dual_opaque;
 extern ConfigVariableBool m_dual_transparent;
 extern ConfigVariableBool m_dual_transparent;

+ 3 - 3
panda/src/pgraph/cullResult.cxx

@@ -287,7 +287,7 @@ get_dual_transparent_state() {
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG
   if (m_dual_flash) {
   if (m_dual_flash) {
-    int cycle = (int)(ClockObject::get_global_clock()->get_real_time() * m_dual_flash_rate);
+    int cycle = (int)(ClockObject::get_global_clock()->get_frame_time() * m_dual_flash_rate);
     if ((cycle & 1) == 0) {
     if ((cycle & 1) == 0) {
       static CPT(RenderState) flash_state = NULL;
       static CPT(RenderState) flash_state = NULL;
       if (flash_state == (const RenderState *)NULL) {
       if (flash_state == (const RenderState *)NULL) {
@@ -325,7 +325,7 @@ get_dual_transparent_state_decals() {
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG
   if (m_dual_flash) {
   if (m_dual_flash) {
-    int cycle = (int)(ClockObject::get_global_clock()->get_real_time() * m_dual_flash_rate);
+    int cycle = (int)(ClockObject::get_global_clock()->get_frame_time() * m_dual_flash_rate);
     if ((cycle & 1) == 0) {
     if ((cycle & 1) == 0) {
       static CPT(RenderState) flash_state = NULL;
       static CPT(RenderState) flash_state = NULL;
       if (flash_state == (const RenderState *)NULL) {
       if (flash_state == (const RenderState *)NULL) {
@@ -356,7 +356,7 @@ get_dual_opaque_state() {
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG
   if (m_dual_flash) {
   if (m_dual_flash) {
-    int cycle = (int)(ClockObject::get_global_clock()->get_real_time() * m_dual_flash_rate);
+    int cycle = (int)(ClockObject::get_global_clock()->get_frame_time() * m_dual_flash_rate);
     if ((cycle & 1) == 0) {
     if ((cycle & 1) == 0) {
       static CPT(RenderState) flash_state = NULL;
       static CPT(RenderState) flash_state = NULL;
       if (flash_state == (const RenderState *)NULL) {
       if (flash_state == (const RenderState *)NULL) {

+ 20 - 1
panda/src/pgraph/cullableObject.cxx

@@ -17,6 +17,9 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 
 
 #include "cullableObject.h"
 #include "cullableObject.h"
+#include "textureAttrib.h"
+#include "renderState.h"
+#include "clockObject.h"
 
 
 
 
 CullableObject *CullableObject::_deleted_chain = (CullableObject *)NULL;
 CullableObject *CullableObject::_deleted_chain = (CullableObject *)NULL;
@@ -38,7 +41,23 @@ munge_geom(const qpGeomMunger *munger) {
       _munger = munger;
       _munger = munger;
       CPT(qpGeom) qpgeom = DCAST(qpGeom, _geom);
       CPT(qpGeom) qpgeom = DCAST(qpGeom, _geom);
       qpgeom->munge_geom(munger, qpgeom, _munged_data);
       qpgeom->munge_geom(munger, qpgeom, _munged_data);
-      _munged_data = _munged_data->animate_vertices_cull();
+      CPT(qpGeomVertexData) animated_vertices = 
+        _munged_data->animate_vertices_cull();
+#ifndef NDEBUG
+      if (show_cpu_animation && animated_vertices != _munged_data) {
+        // These vertices were CPU-animated, so flash them.
+        static const double flash_rate = 1.0;  // 1 state change per second
+        int cycle = (int)(ClockObject::get_global_clock()->get_frame_time() * flash_rate);
+        if ((cycle & 3) == 0) {
+          animated_vertices = animated_vertices->set_color(Colorf(0.8f, 0.2f, 0.2f, 1.0f));
+          _state = _state->remove_attrib(TextureAttrib::get_class_type());
+        } else if ((cycle & 3) == 2) {
+          animated_vertices = animated_vertices->set_color(Colorf(0.1f, 0.2f, 0.8f, 1.0f));
+          _state = _state->remove_attrib(TextureAttrib::get_class_type());
+        }
+      }
+#endif
+      _munged_data = animated_vertices;
       _geom = qpgeom;
       _geom = qpgeom;
     }
     }
   }
   }