diff --git a/panda/src/gobj/config_gobj.cxx b/panda/src/gobj/config_gobj.cxx index 1f1f3ea29b..3a815f4340 100644 --- a/panda/src/gobj/config_gobj.cxx +++ b/panda/src/gobj/config_gobj.cxx @@ -98,7 +98,7 @@ ConfigVariableBool display_lists "on dynamic geometry (e.g. soft-skinned animation).")); ConfigVariableBool hardware_animated_vertices -("hardware-animated-vertices", false, +("hardware-animated-vertices", true, PRC_DESC("Set this true to allow the transforming of soft-skinned " "animated vertices via hardware, if supported, or false always " "to perform the vertex animation via software within Panda. " diff --git a/panda/src/pgraph/config_pgraph.cxx b/panda/src/pgraph/config_pgraph.cxx index 5bc61f20f3..40b8617f82 100644 --- a/panda/src/pgraph/config_pgraph.cxx +++ b/panda/src/pgraph/config_pgraph.cxx @@ -195,12 +195,11 @@ ConfigVariableDouble lod_fade_time "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 show_vertex_animation +("show-vertex-animation", false, + PRC_DESC("Set this true to flash any objects whose vertices are animated " + "by Panda on the CPU (flash red) or by hardware (flash blue). " + "This only has effect when NDEBUG is defined.")); ConfigVariableBool m_dual ("m-dual", true, diff --git a/panda/src/pgraph/config_pgraph.h b/panda/src/pgraph/config_pgraph.h index 5a9354d96f..a7a382a58c 100644 --- a/panda/src/pgraph/config_pgraph.h +++ b/panda/src/pgraph/config_pgraph.h @@ -48,7 +48,7 @@ extern ConfigVariableInt max_collect_indices; extern ConfigVariableBool polylight_info; extern ConfigVariableDouble lod_fade_time; -extern ConfigVariableBool show_cpu_animation; +extern ConfigVariableBool show_vertex_animation; extern ConfigVariableBool m_dual; extern ConfigVariableBool m_dual_opaque; diff --git a/panda/src/pgraph/cullableObject.cxx b/panda/src/pgraph/cullableObject.cxx index c405ad5d33..57c736a1a6 100644 --- a/panda/src/pgraph/cullableObject.cxx +++ b/panda/src/pgraph/cullableObject.cxx @@ -17,7 +17,11 @@ //////////////////////////////////////////////////////////////////// #include "cullableObject.h" -#include "textureAttrib.h" +#include "ambientLight.h" +#include "lightAttrib.h" +#include "nodePath.h" +#include "material.h" +#include "materialAttrib.h" #include "texGenAttrib.h" #include "renderState.h" #include "clockObject.h" @@ -93,22 +97,16 @@ munge_geom(GraphicsStateGuardianBase *gsg, CPT(GeomVertexData) animated_vertices = _munged_data->animate_vertices(); #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 & 1) == 0) { - static Colorf flash_color(0.8f, 0.2f, 0.2f, 1.0f); - if (animated_vertices->has_color()) { - animated_vertices = animated_vertices->set_color(flash_color); - } else { - // We have to add a color column, which means we have to - // re-munge. - animated_vertices = animated_vertices->set_color - (flash_color, 1, Geom::NT_packed_dabc, Geom::C_color); - animated_vertices = munger->munge_data(animated_vertices); + if (show_vertex_animation) { + bool cpu_animated = (animated_vertices != _munged_data); + bool hardware_animated = (animated_vertices->get_format()->get_animation().get_animation_type() == Geom::AT_hardware); + if (cpu_animated || hardware_animated) { + // These vertices were animated, so flash them red or blue. + 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 & 1) == 0) { + _state = cpu_animated ? get_flash_cpu_state() : get_flash_hardware_state(); } - _state = _state->remove_attrib(TextureAttrib::get_class_type()); } } #endif @@ -530,3 +528,71 @@ munge_texcoord_light_vector(const CullTraverser *traverser) { } } } + +//////////////////////////////////////////////////////////////////// +// Function: CullableObject::get_flash_cpu_state +// Access: Private, Static +// Description: Returns a RenderState for flashing the object red, to +// show it is animated by the CPU when +// show-vertex-animation is on. +//////////////////////////////////////////////////////////////////// +CPT(RenderState) CullableObject:: +get_flash_cpu_state() { + static const Colorf flash_cpu_color(0.8f, 0.2f, 0.2f, 1.0f); + + // Once someone asks for this pointer, we hold its reference count + // and never free it. + static CPT(RenderState) flash_cpu_state = (const RenderState *)NULL; + if (flash_cpu_state == (const RenderState *)NULL) { + PT(AmbientLight) ambient_light = new AmbientLight("alight"); + ambient_light->set_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)); + NodePath alight(ambient_light); + + CPT(LightAttrib) light_attrib = DCAST(LightAttrib, LightAttrib::make_all_off()); + light_attrib = DCAST(LightAttrib, light_attrib->add_on_light(alight)); + + PT(Material) material = new Material; + material->set_ambient(flash_cpu_color); + material->set_diffuse(flash_cpu_color); + + flash_cpu_state = RenderState::make + (light_attrib, + MaterialAttrib::make(material)); + } + + return flash_cpu_state; +} + +//////////////////////////////////////////////////////////////////// +// Function: CullableObject::get_flash_hardware_state +// Access: Private, Static +// Description: Returns a RenderState for flashing the object blue, +// to show it is animated by the hardware when +// show-vertex-animation is on. +//////////////////////////////////////////////////////////////////// +CPT(RenderState) CullableObject:: +get_flash_hardware_state() { + static const Colorf flash_hardware_color(0.2f, 0.2f, 0.8f, 1.0f); + + // Once someone asks for this pointer, we hold its reference count + // and never free it. + static CPT(RenderState) flash_hardware_state = (const RenderState *)NULL; + if (flash_hardware_state == (const RenderState *)NULL) { + PT(AmbientLight) ambient_light = new AmbientLight("alight"); + ambient_light->set_color(Colorf(1.0f, 1.0f, 1.0f, 1.0f)); + NodePath alight(ambient_light); + + CPT(LightAttrib) light_attrib = DCAST(LightAttrib, LightAttrib::make_all_off()); + light_attrib = DCAST(LightAttrib, light_attrib->add_on_light(alight)); + + PT(Material) material = new Material; + material->set_ambient(flash_hardware_color); + material->set_diffuse(flash_hardware_color); + + flash_hardware_state = RenderState::make + (light_attrib, + MaterialAttrib::make(material)); + } + + return flash_hardware_state; +} diff --git a/panda/src/pgraph/cullableObject.h b/panda/src/pgraph/cullableObject.h index 426dfa0b7d..c33db6c95e 100644 --- a/panda/src/pgraph/cullableObject.h +++ b/panda/src/pgraph/cullableObject.h @@ -87,6 +87,9 @@ private: void munge_points_to_quads(const CullTraverser *traverser); void munge_texcoord_light_vector(const CullTraverser *traverser); + static CPT(RenderState) get_flash_cpu_state(); + static CPT(RenderState) get_flash_hardware_state(); + private: // This class is used internally by munge_points_to_quads(). class PointData {