minor performance enhancements

This commit is contained in:
David Rose 2005-04-22 23:53:43 +00:00
parent f8d209d90c
commit 9b560c9370
15 changed files with 161 additions and 135 deletions

View File

@ -609,15 +609,13 @@ recompute_geom(Geom *geom, const LMatrix4f &rel_mat) {
if (!vdata->has_column(_texcoord_name)) {
// We need to add a new column for the new texcoords.
vdata = vdata->replace_column
(_texcoord_name, 2, qpGeom::NT_float32,
qpGeom::C_texcoord, qpGeom::UH_dynamic, true);
(_texcoord_name, 2, qpGeom::NT_float32, qpGeom::C_texcoord);
qpgeom->set_vertex_data(vdata);
}
if (_vignette_on && !vdata->has_column(InternalName::get_color())) {
// We need to add a column for color.
vdata = vdata->replace_column
(InternalName::get_color(), 1, qpGeom::NT_packed_dabc,
qpGeom::C_color, qpGeom::UH_dynamic, true);
(InternalName::get_color(), 1, qpGeom::NT_packed_dabc, qpGeom::C_color);
qpgeom->set_vertex_data(vdata);
}

View File

@ -92,6 +92,39 @@ qpGeomVertexData(const qpGeomVertexData &copy) :
{
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexData::Constructor
// Access: Published
// Description: This constructor copies all of the basic properties
// of the source VertexData, like usage_hint and
// animation tables, but does not copy the actual data,
// and it allows you to specify a different format.
////////////////////////////////////////////////////////////////////
qpGeomVertexData::
qpGeomVertexData(const qpGeomVertexData &copy,
const qpGeomVertexFormat *format) :
TypedWritableReferenceCount(copy),
_name(copy._name),
_format(format),
_cycler(copy._cycler),
_app_char_pcollector(copy._app_char_pcollector),
_cull_char_pcollector(copy._cull_char_pcollector)
{
nassertv(_format->is_registered());
// Create some empty arrays as required by the format.
CDWriter cdata(_cycler);
UsageHint usage_hint = cdata->_usage_hint;
cdata->_arrays.clear();
int num_arrays = _format->get_num_arrays();
for (int i = 0; i < num_arrays; i++) {
PT(qpGeomVertexArrayData) array = new qpGeomVertexArrayData
(_format->get_array(i), usage_hint);
cdata->_arrays.push_back(array);
}
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexData::Copy Assignment Operator
// Access: Published
@ -723,8 +756,7 @@ scale_color(const LVecBase4f &color_scale, int num_components,
PStatTimer timer(_scale_color_pcollector);
PT(qpGeomVertexData) new_data = replace_column
(InternalName::get_color(), num_components, numeric_type,
contents, get_usage_hint(), true);
(InternalName::get_color(), num_components, numeric_type, contents);
// Now go through and apply the scale, copying it to the new data.
qpGeomVertexWriter to(new_data, InternalName::get_color());
@ -789,8 +821,7 @@ set_color(const Colorf &color, int num_components,
PStatTimer timer(_set_color_pcollector);
PT(qpGeomVertexData) new_data = replace_column
(InternalName::get_color(), num_components, numeric_type,
contents, get_usage_hint(), true);
(InternalName::get_color(), num_components, numeric_type, contents);
// Now go through and set the new color value.
qpGeomVertexWriter to(new_data, InternalName::get_color());
@ -818,9 +849,7 @@ set_color(const Colorf &color, int num_components,
PT(qpGeomVertexData) qpGeomVertexData::
replace_column(const InternalName *name, int num_components,
qpGeomVertexData::NumericType numeric_type,
qpGeomVertexData::Contents contents,
qpGeomVertexData::UsageHint usage_hint,
bool keep_animation) const {
qpGeomVertexData::Contents contents) const {
PT(qpGeomVertexFormat) new_format = new qpGeomVertexFormat(*_format);
// Remove the old description of the type from the format.
@ -859,12 +888,7 @@ replace_column(const InternalName *name, int num_components,
<< *_format << " to " << *format << "\n";
}
PT(qpGeomVertexData) new_data =
new qpGeomVertexData(get_name(), format, usage_hint);
if (keep_animation) {
new_data->set_transform_blend_table(get_transform_blend_table());
new_data->set_slider_table(get_slider_table());
}
PT(qpGeomVertexData) new_data = new qpGeomVertexData(*this, format);
int j = 0;
int num_arrays = get_num_arrays();
@ -1370,17 +1394,18 @@ update_animated_vertices(qpGeomVertexData::CDWriter &cdata, bool from_app) {
}
// Now go through and apply the transforms.
qpGeomVertexReader blendi(this, InternalName::get_transform_blend());
if (!blendi.has_column()) {
gobj_cat.warning()
<< "Vertex data " << get_name()
<< " has a transform_blend_table, but no transform_blend data.\n";
return;
}
int ci;
for (ci = 0; ci < _format->get_num_points(); ci++) {
qpGeomVertexRewriter data(new_data, _format->get_point(ci));
qpGeomVertexReader blendi(this, InternalName::get_transform_blend());
if (!blendi.has_column()) {
gobj_cat.warning()
<< "Vertex data " << get_name()
<< " has a transform_blend_table, but no transform_blend data.\n";
return;
}
blendi.set_row(0);
if (data.get_column()->get_num_values() == 4) {
for (int i = 0; i < num_rows; i++) {
@ -1400,14 +1425,7 @@ update_animated_vertices(qpGeomVertexData::CDWriter &cdata, bool from_app) {
}
for (ci = 0; ci < _format->get_num_vectors(); ci++) {
qpGeomVertexRewriter data(new_data, _format->get_vector(ci));
qpGeomVertexReader blendi(this, InternalName::get_transform_blend());
if (!blendi.has_column()) {
gobj_cat.warning()
<< "Vertex data " << get_name()
<< " has a transform_blend_table, but no transform_blend data.\n";
return;
}
blendi.set_row(0);
for (int i = 0; i < num_rows; i++) {
LVector3f vertex = data.get_data3f();

View File

@ -81,6 +81,8 @@ PUBLISHED:
const qpGeomVertexFormat *format,
UsageHint usage_hint);
qpGeomVertexData(const qpGeomVertexData &copy);
qpGeomVertexData(const qpGeomVertexData &copy,
const qpGeomVertexFormat *format);
void operator = (const qpGeomVertexData &copy);
virtual ~qpGeomVertexData();
@ -137,8 +139,7 @@ PUBLISHED:
PT(qpGeomVertexData)
replace_column(const InternalName *name, int num_components,
NumericType numeric_type, Contents contents,
UsageHint usage_hint, bool keep_animation) const;
NumericType numeric_type, Contents contents) const;
void output(ostream &out) const;
void write(ostream &out, int indent_level = 0) const;

View File

@ -239,7 +239,7 @@ INLINE void qpGeomVertexReader::
set_row(int row) {
_start_row = row;
if (has_column()) {
set_pointer(_start_row);
quick_set_pointer(_start_row);
}
}
@ -255,6 +255,17 @@ get_start_row() const {
return _start_row;
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexReader::get_read_row
// Access: Published
// Description: Returns the row index from which the data will be
// retrieved by the next call to get_data*().
////////////////////////////////////////////////////////////////////
INLINE int qpGeomVertexReader::
get_read_row() const {
return (int)(_pointer - _pointer_begin) / _stride;
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexReader::is_at_end
// Access: Published
@ -375,23 +386,45 @@ get_data4i() {
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexReader::set_pointer
// Access: Private
// Description: Sets up the internal read pointer, etc. to read from
// the indicated row.
// Description: Sets up the array pointers freshly from the source
// object (in case they have been reallocated recently),
// and sets the internal pointer to the indicated row.
////////////////////////////////////////////////////////////////////
INLINE void qpGeomVertexReader::
set_pointer(int row) {
nassertv(has_column());
if (_vertex_data != (const qpGeomVertexData *)NULL) {
const qpGeomVertexArrayData *array_data = _vertex_data->get_array(_array);
_pointer = array_data->get_data();
_pointer_end = _pointer + array_data->get_data_size_bytes();
_pointer += _packer->_column->get_start() + _stride * row;
_pointer_begin = array_data->get_data();
_pointer_end = _pointer_begin + array_data->get_data_size_bytes();
} else {
_pointer = _array_data->get_data();
_pointer_end = _pointer + _array_data->get_data_size_bytes();
_pointer += _packer->_column->get_start() + _stride * row;
_pointer_begin = _array_data->get_data();
_pointer_end = _pointer_begin + _array_data->get_data_size_bytes();
}
quick_set_pointer(row);
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexReader::quick_set_pointer
// Access: Private
// Description: Sets up the internal pointer to the indicated row,
// without first verifying that arrays haven't been
// reallocated.
////////////////////////////////////////////////////////////////////
INLINE void qpGeomVertexReader::
quick_set_pointer(int row) {
nassertv(has_column());
#ifdef _DEBUG
if (_vertex_data != (const qpGeomVertexData *)NULL) {
const qpGeomVertexArrayData *array_data = _vertex_data->get_array(_array);
nassertv(_pointer_begin == array_data->get_data());
} else {
nassertv(_pointer_begin == _array_data->get_data());
}
#endif
_pointer = _pointer_begin + _packer->_column->get_start() + _stride * row;
}
////////////////////////////////////////////////////////////////////
@ -402,7 +435,7 @@ set_pointer(int row) {
////////////////////////////////////////////////////////////////////
INLINE const unsigned char *qpGeomVertexReader::
inc_pointer() {
#ifndef NDEBUG
#ifdef _DEBUG
nassertr(_pointer < _pointer_end, empty_buffer);
if (_vertex_data != (const qpGeomVertexData *)NULL){
const qpGeomVertexArrayData *array_data = _vertex_data->get_array(_array);

View File

@ -86,7 +86,8 @@ void qpGeomVertexReader::
initialize() {
_array = 0;
_packer = NULL;
_pointer = NULL;
_pointer_begin = NULL;
_pointer_end = NULL;
_pointer = NULL;
_start_row = 0;
}

View File

@ -86,6 +86,7 @@ PUBLISHED:
INLINE void set_row(int row);
INLINE int get_start_row() const;
INLINE int get_read_row() const;
INLINE bool is_at_end() const;
INLINE float get_data1f();
@ -102,6 +103,7 @@ private:
void initialize();
INLINE void set_pointer(int row);
INLINE void quick_set_pointer(int row);
INLINE const unsigned char *inc_pointer();
// It is important that we only store *one* of the following two
@ -116,8 +118,9 @@ private:
qpGeomVertexColumn::Packer *_packer;
int _stride;
const unsigned char *_pointer;
const unsigned char *_pointer_begin;
const unsigned char *_pointer_end;
const unsigned char *_pointer;
int _start_row;

View File

@ -238,7 +238,7 @@ INLINE void qpGeomVertexWriter::
set_row(int row) {
_start_row = row;
if (has_column()) {
set_pointer(_start_row);
quick_set_pointer(_start_row);
}
}
@ -254,6 +254,18 @@ get_start_row() const {
return _start_row;
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexWriter::get_write_row
// Access: Published
// Description: Returns the row index to which the data will be
// written at the next call to set_data*() or
// add_data*().
////////////////////////////////////////////////////////////////////
INLINE int qpGeomVertexWriter::
get_write_row() const {
return (int)(_pointer - _pointer_begin) / _stride;
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexWriter::is_at_end
// Access: Published
@ -679,24 +691,45 @@ add_data4i(const int data[4]) {
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexWriter::set_pointer
// Access: Private
// Description: Sets up the internal write pointer, etc. to use the
// indicated row.
// Description: Sets up the array pointers freshly from the source
// object (in case they have been reallocated recently),
// and sets the internal pointer to the indicated row.
////////////////////////////////////////////////////////////////////
INLINE void qpGeomVertexWriter::
set_pointer(int row) {
nassertv(has_column());
if (_vertex_data != (qpGeomVertexData *)NULL) {
if (_vertex_data != (const qpGeomVertexData *)NULL) {
qpGeomVertexArrayData *array_data = _vertex_data->modify_array(_array);
_pointer = array_data->modify_data();
_pointer_end = _pointer + array_data->get_data_size_bytes();
_pointer += _packer->_column->get_start() + _stride * row;
_pointer_begin = array_data->modify_data();
_pointer_end = _pointer_begin + array_data->get_data_size_bytes();
} else {
_pointer = _array_data->modify_data();
_pointer_end = _pointer + _array_data->get_data_size_bytes();
_pointer += _packer->_column->get_start() + _stride * row;
_pointer_begin = _array_data->modify_data();
_pointer_end = _pointer_begin + _array_data->get_data_size_bytes();
}
_write_row = row;
quick_set_pointer(row);
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexWriter::quick_set_pointer
// Access: Private
// Description: Sets up the internal pointer to the indicated row,
// without first verifying that arrays haven't been
// reallocated.
////////////////////////////////////////////////////////////////////
INLINE void qpGeomVertexWriter::
quick_set_pointer(int row) {
nassertv(has_column());
#ifdef _DEBUG
if (_vertex_data != (const qpGeomVertexData *)NULL) {
const qpGeomVertexArrayData *array_data = _vertex_data->get_array(_array);
nassertv(_pointer_begin == array_data->get_data());
} else {
nassertv(_pointer_begin == _array_data->get_data());
}
#endif
_pointer = _pointer_begin + _packer->_column->get_start() + _stride * row;
}
////////////////////////////////////////////////////////////////////
@ -707,7 +740,7 @@ set_pointer(int row) {
////////////////////////////////////////////////////////////////////
INLINE unsigned char *qpGeomVertexWriter::
inc_pointer() {
#ifndef NDEBUG
#ifdef _DEBUG
nassertr(_pointer < _pointer_end, empty_buffer);
if (_vertex_data != (qpGeomVertexData *)NULL){
const qpGeomVertexArrayData *array_data = _vertex_data->get_array(_array);
@ -719,7 +752,6 @@ inc_pointer() {
unsigned char *orig_pointer = _pointer;
_pointer += _stride;
++_write_row;
return orig_pointer;
}
@ -735,12 +767,13 @@ INLINE unsigned char *qpGeomVertexWriter::
inc_add_pointer() {
if (_pointer >= _pointer_end) {
// Reset the data pointer.
int write_row = get_write_row();
if (_vertex_data != (qpGeomVertexData *)NULL) {
_vertex_data->set_num_rows(max(_write_row + 1, _vertex_data->get_num_rows()));
_vertex_data->set_num_rows(max(write_row + 1, _vertex_data->get_num_rows()));
} else {
_array_data->set_num_rows(max(_write_row + 1, _array_data->get_num_rows()));
_array_data->set_num_rows(max(write_row + 1, _array_data->get_num_rows()));
}
set_pointer(_write_row);
set_pointer(write_row);
}
return inc_pointer();
}

View File

@ -86,8 +86,8 @@ void qpGeomVertexWriter::
initialize() {
_array = 0;
_packer = NULL;
_pointer = NULL;
_pointer_begin = NULL;
_pointer_end = NULL;
_pointer = NULL;
_start_row = 0;
_write_row = 0;
}

View File

@ -99,6 +99,7 @@ PUBLISHED:
INLINE void set_row(int row);
INLINE int get_start_row() const;
INLINE int get_write_row() const;
INLINE bool is_at_end() const;
INLINE void set_data1f(float data);
@ -139,6 +140,7 @@ private:
void initialize();
INLINE void set_pointer(int row);
INLINE void quick_set_pointer(int row);
INLINE unsigned char *inc_pointer();
INLINE unsigned char *inc_add_pointer();
@ -154,11 +156,11 @@ private:
qpGeomVertexColumn::Packer *_packer;
int _stride;
unsigned char *_pointer;
unsigned char *_pointer_begin;
unsigned char *_pointer_end;
unsigned char *_pointer;
int _start_row;
int _write_row;
#ifndef NDEBUG
// This is defined just for the benefit of having something non-NULL

View File

@ -812,6 +812,7 @@ transfer_geom(GeomNode *geom_node, const InternalName *texcoord_name,
if (orig_geom->is_of_type(qpGeom::get_class_type())) {
PT(qpGeom) geom = new qpGeom(*DCAST(qpGeom, orig_geom));
PT(qpGeomVertexData) vdata = geom->modify_vertex_data();
vdata->set_usage_hint(qpGeom::UH_stream);
if (vdata->has_column(_target_stage->get_texcoord_name())) {
qpGeomVertexWriter vertex(vdata, InternalName::get_vertex());
@ -831,8 +832,7 @@ transfer_geom(GeomNode *geom_node, const InternalName *texcoord_name,
vdata->get_format()->get_column(texcoord_name);
vdata = vdata->replace_column
(InternalName::get_texcoord(), column->get_num_components(),
column->get_numeric_type(), column->get_contents(),
qpGeom::UH_stream, true);
column->get_numeric_type(), column->get_contents());
geom->set_vertex_data(vdata);
qpGeomVertexReader from(vdata, texcoord_name);

View File

@ -17,32 +17,6 @@
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::set_usage_hint
// Access: Published
// Description: Specifies the ceiling UsageHint that will be applied
// to transformed geometry. If the source geometry's
// usage hint is greater (more static) than this, it
// will be reduced to this level. If the source
// geometry's usage hit is less (more dynamic) than
// this, it will be preserved at its current level.
////////////////////////////////////////////////////////////////////
INLINE void GeomTransformer::
set_usage_hint(qpGeom::UsageHint usage_hint) {
_usage_hint = usage_hint;
}
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::get_usage_hint
// Access: Published
// Description: Returns the UsageHint that will be applied to
// generated geometry. See set_usage_hint().
////////////////////////////////////////////////////////////////////
INLINE qpGeom::UsageHint GeomTransformer::
get_usage_hint() const {
return _usage_hint;
}
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::get_max_collect_vertices
// Access: Public

View File

@ -33,7 +33,6 @@
////////////////////////////////////////////////////////////////////
GeomTransformer::
GeomTransformer() :
_usage_hint(qpGeom::UH_static),
// The default value here comes from the Config file.
_max_collect_vertices(max_collect_vertices)
{
@ -46,7 +45,6 @@ GeomTransformer() :
////////////////////////////////////////////////////////////////////
GeomTransformer::
GeomTransformer(const GeomTransformer &copy) :
_usage_hint(copy._usage_hint),
_max_collect_vertices(copy._max_collect_vertices)
{
}
@ -239,9 +237,7 @@ transform_texcoords(Geom *geom, const InternalName *from_name,
new_data = st._vertex_data->replace_column
(to_name, old_column->get_num_components(),
old_column->get_numeric_type(),
old_column->get_contents(),
min(_usage_hint, st._vertex_data->get_usage_hint()),
false);
old_column->get_contents());
}
CPT(qpGeomVertexFormat) format = new_data->get_format();

View File

@ -51,9 +51,6 @@ public:
GeomTransformer(const GeomTransformer &copy);
~GeomTransformer();
INLINE void set_usage_hint(qpGeom::UsageHint usage_hint);
INLINE qpGeom::UsageHint get_usage_hint() const;
INLINE int get_max_collect_vertices() const;
INLINE void set_max_collect_vertices(int max_collect_vertices);
@ -79,7 +76,6 @@ public:
int collect_vertex_data(GeomNode *node, int collect_bits);
private:
qpGeom::UsageHint _usage_hint;
int _max_collect_vertices;
class qpSourceVertices {

View File

@ -37,32 +37,6 @@ INLINE SceneGraphReducer::
~SceneGraphReducer() {
}
////////////////////////////////////////////////////////////////////
// Function: SceneGraphReducer::set_usage_hint
// Access: Published
// Description: Specifies the ceiling UsageHint that will be applied
// to transformed geometry. If the source geometry's
// usage hint is greater (more static) than this, it
// will be reduced to this level. If the source
// geometry's usage hit is less (more dynamic) than
// this, it will be preserved at its current level.
////////////////////////////////////////////////////////////////////
INLINE void SceneGraphReducer::
set_usage_hint(qpGeom::UsageHint usage_hint) {
_transformer.set_usage_hint(usage_hint);
}
////////////////////////////////////////////////////////////////////
// Function: SceneGraphReducer::get_usage_hint
// Access: Published
// Description: Returns the UsageHint that will be applied to
// generated geometry. See set_usage_hint().
////////////////////////////////////////////////////////////////////
INLINE qpGeom::UsageHint SceneGraphReducer::
get_usage_hint() const {
return _transformer.get_usage_hint();
}
////////////////////////////////////////////////////////////////////
// Function: SceneGraphReducer::set_combine_radius
// Access: Published

View File

@ -104,9 +104,6 @@ PUBLISHED:
MN_avoid_dynamic = 0x004,
};
INLINE void set_usage_hint(qpGeom::UsageHint usage_hint);
INLINE qpGeom::UsageHint get_usage_hint() const;
INLINE void set_combine_radius(float combine_radius);
INLINE float get_combine_radius() const;