From 160099a0ec45ad3f4547e672a2b4e4560ce799d2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 31 Mar 2005 11:45:57 +0000 Subject: [PATCH] show-cpu-animation --- panda/src/dxgsg8/dxGeomMunger8.cxx | 14 +++-- panda/src/dxgsg8/dxVertexBufferContext8.cxx | 14 ++--- panda/src/gobj/qpgeomVertexArrayFormat.cxx | 2 +- panda/src/gobj/qpgeomVertexColumn.cxx | 4 +- panda/src/gobj/qpgeomVertexData.cxx | 66 ++++++++++++++++++--- panda/src/gobj/qpgeomVertexData.h | 4 ++ panda/src/pgraph/config_pgraph.cxx | 8 +++ panda/src/pgraph/config_pgraph.h | 2 + panda/src/pgraph/cullResult.cxx | 6 +- panda/src/pgraph/cullableObject.cxx | 21 ++++++- 10 files changed, 114 insertions(+), 27 deletions(-) diff --git a/panda/src/dxgsg8/dxGeomMunger8.cxx b/panda/src/dxgsg8/dxGeomMunger8.cxx index aa56e54217..33bcb43c2f 100644 --- a/panda/src/dxgsg8/dxGeomMunger8.cxx +++ b/panda/src/dxgsg8/dxGeomMunger8.cxx @@ -67,12 +67,14 @@ munge_format_impl(const qpGeomVertexFormat *orig, if (animation.get_animation_type() == qpGeomVertexAnimationSpec::AT_hardware && 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()) { // Also, if we'll be indexing into the transfom palette, reserve // space for the index. diff --git a/panda/src/dxgsg8/dxVertexBufferContext8.cxx b/panda/src/dxgsg8/dxVertexBufferContext8.cxx index a4040168ec..3a95634439 100644 --- a/panda/src/dxgsg8/dxVertexBufferContext8.cxx +++ b/panda/src/dxgsg8/dxVertexBufferContext8.cxx @@ -56,14 +56,14 @@ DXVertexBufferContext8(qpGeomVertexArrayData *data) : // We have hardware vertex animation. num_blend_values = array_format->get_column(n)->get_num_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; - } + 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) { diff --git a/panda/src/gobj/qpgeomVertexArrayFormat.cxx b/panda/src/gobj/qpgeomVertexArrayFormat.cxx index 9dbb9b41a8..350ef27247 100644 --- a/panda/src/gobj/qpgeomVertexArrayFormat.cxx +++ b/panda/src/gobj/qpgeomVertexArrayFormat.cxx @@ -217,7 +217,7 @@ add_column(const InternalName *name, int num_components, } return add_column(qpGeomVertexColumn(name, num_components, - numeric_type, contents, start)); + numeric_type, contents, start)); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/gobj/qpgeomVertexColumn.cxx b/panda/src/gobj/qpgeomVertexColumn.cxx index 44c324a483..c7fd1f8d13 100644 --- a/panda/src/gobj/qpgeomVertexColumn.cxx +++ b/panda/src/gobj/qpgeomVertexColumn.cxx @@ -25,8 +25,8 @@ //////////////////////////////////////////////////////////////////// qpGeomVertexColumn:: qpGeomVertexColumn(const InternalName *name, int num_components, - NumericType numeric_type, Contents contents, - int start) : + NumericType numeric_type, Contents contents, + int start) : _name(name), _num_components(num_components), _num_values(num_components), diff --git a/panda/src/gobj/qpgeomVertexData.cxx b/panda/src/gobj/qpgeomVertexData.cxx index 9d8ef52347..9f9c728249 100644 --- a/panda/src/gobj/qpgeomVertexData.cxx +++ b/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), already_added); } - weight.set_data4f(weights); + if (weight.has_column()) { + weight.set_data4f(weights); + } index.set_data4i(indices); } } else { @@ -533,7 +535,9 @@ copy_from(const qpGeomVertexData &source, bool keep_data_objects) { nassertv(index <= 4); 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; } + +//////////////////////////////////////////////////////////////////// +// 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 // Access: Published @@ -622,6 +654,29 @@ scale_color(const LVecBase4f &color_scale, int num_components, 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 // Access: Published @@ -636,11 +691,9 @@ CPT(qpGeomVertexData) qpGeomVertexData:: set_color(const Colorf &color, int num_components, qpGeomVertexColumn::NumericType numeric_type, qpGeomVertexColumn::Contents contents) const { - int num_vertices = get_num_vertices(); - if (gobj_cat.is_debug()) { gobj_cat.debug() - << "Setting color for " << num_vertices << " vertices to " + << "Setting color for " << get_num_vertices() << " vertices to " << color << ".\n"; } 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. qpGeomVertexWriter to(new_data, InternalName::get_color()); - - for (int i = 0; i < num_vertices; i++) { + while (!to.is_at_end()) { to.set_data4f(color); } diff --git a/panda/src/gobj/qpgeomVertexData.h b/panda/src/gobj/qpgeomVertexData.h index 66db4bdfee..cc3b66034b 100644 --- a/panda/src/gobj/qpgeomVertexData.h +++ b/panda/src/gobj/qpgeomVertexData.h @@ -112,10 +112,14 @@ PUBLISHED: void copy_from(const qpGeomVertexData &source, bool keep_data_objects); CPT(qpGeomVertexData) convert_to(const qpGeomVertexFormat *new_format) const; + CPT(qpGeomVertexData) + scale_color(const LVecBase4f &color_scale) const; CPT(qpGeomVertexData) scale_color(const LVecBase4f &color_scale, int num_components, qpGeomVertexColumn::NumericType numeric_type, qpGeomVertexColumn::Contents contents) const; + CPT(qpGeomVertexData) + set_color(const Colorf &color) const; CPT(qpGeomVertexData) set_color(const Colorf &color, int num_components, qpGeomVertexColumn::NumericType numeric_type, diff --git a/panda/src/pgraph/config_pgraph.cxx b/panda/src/pgraph/config_pgraph.cxx index 74f517b541..e352ca5f40 100644 --- a/panda/src/pgraph/config_pgraph.cxx +++ b/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 " "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 ("m-dual", true, PRC_DESC("Set this false to disable TransparencyAttrib::M_dual altogether " diff --git a/panda/src/pgraph/config_pgraph.h b/panda/src/pgraph/config_pgraph.h index aedb4c88d2..6abdfd5401 100644 --- a/panda/src/pgraph/config_pgraph.h +++ b/panda/src/pgraph/config_pgraph.h @@ -44,6 +44,8 @@ extern ConfigVariableBool auto_break_cycles; extern ConfigVariableBool polylight_info; extern ConfigVariableDouble lod_fade_time; +extern ConfigVariableBool show_cpu_animation; + extern ConfigVariableBool m_dual; extern ConfigVariableBool m_dual_opaque; extern ConfigVariableBool m_dual_transparent; diff --git a/panda/src/pgraph/cullResult.cxx b/panda/src/pgraph/cullResult.cxx index 9a4080a012..78be96e7fa 100644 --- a/panda/src/pgraph/cullResult.cxx +++ b/panda/src/pgraph/cullResult.cxx @@ -287,7 +287,7 @@ get_dual_transparent_state() { #ifndef NDEBUG 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) { static CPT(RenderState) flash_state = NULL; if (flash_state == (const RenderState *)NULL) { @@ -325,7 +325,7 @@ get_dual_transparent_state_decals() { #ifndef NDEBUG 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) { static CPT(RenderState) flash_state = NULL; if (flash_state == (const RenderState *)NULL) { @@ -356,7 +356,7 @@ get_dual_opaque_state() { #ifndef NDEBUG 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) { static CPT(RenderState) flash_state = NULL; if (flash_state == (const RenderState *)NULL) { diff --git a/panda/src/pgraph/cullableObject.cxx b/panda/src/pgraph/cullableObject.cxx index 1e99f9ed2e..5b8af8bd82 100644 --- a/panda/src/pgraph/cullableObject.cxx +++ b/panda/src/pgraph/cullableObject.cxx @@ -17,6 +17,9 @@ //////////////////////////////////////////////////////////////////// #include "cullableObject.h" +#include "textureAttrib.h" +#include "renderState.h" +#include "clockObject.h" CullableObject *CullableObject::_deleted_chain = (CullableObject *)NULL; @@ -38,7 +41,23 @@ munge_geom(const qpGeomMunger *munger) { _munger = munger; CPT(qpGeom) qpgeom = DCAST(qpGeom, _geom); 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; } }