show-cpu-animation

This commit is contained in:
David Rose 2005-03-31 11:45:57 +00:00
parent f2091d2f69
commit 160099a0ec
10 changed files with 114 additions and 27 deletions

View File

@ -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.

View File

@ -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) {

View File

@ -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));
}
////////////////////////////////////////////////////////////////////

View File

@ -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),

View File

@ -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);
}

View File

@ -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,

View File

@ -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 "

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}
}