ropeNode stats and optimizations

This commit is contained in:
David Rose 2005-01-13 17:54:16 +00:00
parent 77012aee2e
commit 8d1a458c00
9 changed files with 74 additions and 4 deletions

View File

@ -54,6 +54,7 @@ PStatCollector GraphicsStateGuardian::_vertices_tristrip_pcollector("Vertices:Tr
PStatCollector GraphicsStateGuardian::_vertices_trifan_pcollector("Vertices:Triangle fans"); PStatCollector GraphicsStateGuardian::_vertices_trifan_pcollector("Vertices:Triangle fans");
PStatCollector GraphicsStateGuardian::_vertices_tri_pcollector("Vertices:Triangles"); PStatCollector GraphicsStateGuardian::_vertices_tri_pcollector("Vertices:Triangles");
PStatCollector GraphicsStateGuardian::_vertices_other_pcollector("Vertices:Other"); PStatCollector GraphicsStateGuardian::_vertices_other_pcollector("Vertices:Other");
PStatCollector GraphicsStateGuardian::_vertices_indexed_tristrip_pcollector("Vertices:Indexed triangle strips");
PStatCollector GraphicsStateGuardian::_state_pcollector("State changes"); PStatCollector GraphicsStateGuardian::_state_pcollector("State changes");
PStatCollector GraphicsStateGuardian::_transform_state_pcollector("State changes:Transforms"); PStatCollector GraphicsStateGuardian::_transform_state_pcollector("State changes:Transforms");
PStatCollector GraphicsStateGuardian::_texture_state_pcollector("State changes:Textures"); PStatCollector GraphicsStateGuardian::_texture_state_pcollector("State changes:Textures");
@ -1282,6 +1283,7 @@ init_frame_pstats() {
_vertices_trifan_pcollector.clear_level(); _vertices_trifan_pcollector.clear_level();
_vertices_tri_pcollector.clear_level(); _vertices_tri_pcollector.clear_level();
_vertices_other_pcollector.clear_level(); _vertices_other_pcollector.clear_level();
_vertices_indexed_tristrip_pcollector.clear_level();
_state_pcollector.clear_level(); _state_pcollector.clear_level();
_transform_state_pcollector.clear_level(); _transform_state_pcollector.clear_level();

View File

@ -301,6 +301,7 @@ public:
static PStatCollector _vertices_trifan_pcollector; static PStatCollector _vertices_trifan_pcollector;
static PStatCollector _vertices_tri_pcollector; static PStatCollector _vertices_tri_pcollector;
static PStatCollector _vertices_other_pcollector; static PStatCollector _vertices_other_pcollector;
static PStatCollector _vertices_indexed_tristrip_pcollector;
static PStatCollector _state_pcollector; static PStatCollector _state_pcollector;
static PStatCollector _transform_state_pcollector; static PStatCollector _transform_state_pcollector;
static PStatCollector _texture_state_pcollector; static PStatCollector _texture_state_pcollector;

View File

@ -1559,7 +1559,11 @@ draw_tristrip(GeomTristrip *geom, GeomContext *gc) {
// PStatTimer timer(_draw_primitive_pcollector); // PStatTimer timer(_draw_primitive_pcollector);
// Using PStatTimer may cause a compiler crash. // Using PStatTimer may cause a compiler crash.
_draw_primitive_pcollector.start(); _draw_primitive_pcollector.start();
if (geom->get_coords_index().is_null()) {
_vertices_tristrip_pcollector.add_level(geom->get_num_vertices()); _vertices_tristrip_pcollector.add_level(geom->get_num_vertices());
} else {
_vertices_indexed_tristrip_pcollector.add_level(geom->get_num_vertices());
}
#endif #endif
issue_scene_graph_color(); issue_scene_graph_color();

View File

@ -32,6 +32,7 @@ CData() {
_normal_mode = RopeNode::NM_none; _normal_mode = RopeNode::NM_none;
_tube_up = LVector3f::up(); _tube_up = LVector3f::up();
_matrix = LMatrix4f::ident_mat(); _matrix = LMatrix4f::ident_mat();
_has_matrix = false;
_use_vertex_color = false; _use_vertex_color = false;
_num_subdiv = 10; _num_subdiv = 10;
_num_slices = 5; _num_slices = 5;
@ -53,6 +54,7 @@ CData(const RopeNode::CData &copy) :
_normal_mode(copy._normal_mode), _normal_mode(copy._normal_mode),
_tube_up(copy._tube_up), _tube_up(copy._tube_up),
_matrix(copy._matrix), _matrix(copy._matrix),
_has_matrix(copy._has_matrix),
_use_vertex_color(copy._use_vertex_color), _use_vertex_color(copy._use_vertex_color),
_num_subdiv(copy._num_subdiv), _num_subdiv(copy._num_subdiv),
_num_slices(copy._num_slices), _num_slices(copy._num_slices),
@ -366,6 +368,32 @@ INLINE void RopeNode::
set_matrix(const LMatrix4f &matrix) { set_matrix(const LMatrix4f &matrix) {
CDWriter cdata(_cycler); CDWriter cdata(_cycler);
cdata->_matrix = matrix; cdata->_matrix = matrix;
cdata->_has_matrix = true;
}
////////////////////////////////////////////////////////////////////
// Function: clear_matrix
// Access: Published
// Description: Resets the node's matrix to identity. See
// set_matrix().
////////////////////////////////////////////////////////////////////
INLINE void RopeNode::
clear_matrix() {
CDWriter cdata(_cycler);
cdata->_matrix = LMatrix4f::ident_mat();
cdata->_has_matrix = false;
}
////////////////////////////////////////////////////////////////////
// Function: has_matrix
// Access: Published
// Description: Returns true if the node has a matrix set, false
// otherwise. See set_matrix().
////////////////////////////////////////////////////////////////////
INLINE bool RopeNode::
has_matrix() const {
CDReader cdata(_cycler);
return cdata->_has_matrix;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -27,9 +27,12 @@
#include "bamReader.h" #include "bamReader.h"
#include "datagram.h" #include "datagram.h"
#include "datagramIterator.h" #include "datagramIterator.h"
#include "pStatTimer.h"
TypeHandle RopeNode::_type_handle; TypeHandle RopeNode::_type_handle;
PStatCollector RopeNode::_rope_node_pcollector("Cull:RopeNode");
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: RopeNode::CData::make_copy // Function: RopeNode::CData::make_copy
// Access: Public, Virtual // Access: Public, Virtual
@ -150,12 +153,19 @@ has_cull_callback() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool RopeNode:: bool RopeNode::
cull_callback(CullTraverser *trav, CullTraverserData &data) { cull_callback(CullTraverser *trav, CullTraverserData &data) {
// Statistics
PStatTimer timer(_rope_node_pcollector);
// Create some geometry on-the-fly to render the rope. // Create some geometry on-the-fly to render the rope.
if (get_num_subdiv() > 0) { if (get_num_subdiv() > 0) {
NurbsCurveEvaluator *curve = get_curve(); NurbsCurveEvaluator *curve = get_curve();
if (curve != (NurbsCurveEvaluator *)NULL) { if (curve != (NurbsCurveEvaluator *)NULL) {
PT(NurbsCurveResult) result = PT(NurbsCurveResult) result;
curve->evaluate(data._node_path.get_node_path(), get_matrix()); if (has_matrix()) {
result = curve->evaluate(data._node_path.get_node_path(), get_matrix());
} else {
result = curve->evaluate(data._node_path.get_node_path());
}
if (result->get_num_segments() > 0) { if (result->get_num_segments() > 0) {
switch (get_render_mode()) { switch (get_render_mode()) {
@ -252,6 +262,15 @@ do_recompute_bound(const NodePath &rel_to) {
pvector<LPoint3f> verts; pvector<LPoint3f> verts;
get_curve()->get_vertices(verts, rel_to); get_curve()->get_vertices(verts, rel_to);
if (has_matrix()) {
// And then apply the indicated matrix.
const LMatrix4f &mat = get_matrix();
pvector<LPoint3f>::iterator vi;
for (vi = verts.begin(); vi != verts.end(); ++vi) {
(*vi) = (*vi) * mat;
}
}
GeometricBoundingVolume *gbv; GeometricBoundingVolume *gbv;
DCAST_INTO_R(gbv, bound, bound); DCAST_INTO_R(gbv, bound, bound);
gbv->around(&verts[0], &verts[0] + verts.size()); gbv->around(&verts[0], &verts[0] + verts.size());

View File

@ -22,6 +22,7 @@
#include "pandabase.h" #include "pandabase.h"
#include "nurbsCurveEvaluator.h" #include "nurbsCurveEvaluator.h"
#include "pandaNode.h" #include "pandaNode.h"
#include "pStatCollector.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : RopeNode // Class : RopeNode
@ -132,6 +133,8 @@ PUBLISHED:
INLINE float get_thickness() const; INLINE float get_thickness() const;
INLINE void set_matrix(const LMatrix4f &matrix); INLINE void set_matrix(const LMatrix4f &matrix);
INLINE void clear_matrix();
INLINE bool has_matrix() const;
INLINE const LMatrix4f &get_matrix() const; INLINE const LMatrix4f &get_matrix() const;
void reset_bound(const NodePath &rel_to); void reset_bound(const NodePath &rel_to);
@ -201,6 +204,7 @@ private:
NormalMode _normal_mode; NormalMode _normal_mode;
LVector3f _tube_up; LVector3f _tube_up;
LMatrix4f _matrix; LMatrix4f _matrix;
bool _has_matrix;
bool _use_vertex_color; bool _use_vertex_color;
int _num_subdiv; int _num_subdiv;
int _num_slices; int _num_slices;
@ -211,6 +215,8 @@ private:
typedef CycleDataReader<CData> CDReader; typedef CycleDataReader<CData> CDReader;
typedef CycleDataWriter<CData> CDWriter; typedef CycleDataWriter<CData> CDWriter;
static PStatCollector _rope_node_pcollector;
public: public:
static void register_with_read_factory(); static void register_with_read_factory();
virtual void write_datagram(BamWriter *manager, Datagram &dg); virtual void write_datagram(BamWriter *manager, Datagram &dg);

View File

@ -26,9 +26,12 @@
#include "bamReader.h" #include "bamReader.h"
#include "datagram.h" #include "datagram.h"
#include "datagramIterator.h" #include "datagramIterator.h"
#include "pStatTimer.h"
TypeHandle SheetNode::_type_handle; TypeHandle SheetNode::_type_handle;
PStatCollector SheetNode::_sheet_node_pcollector("Cull:SheetNode");
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: SheetNode::CData::make_copy // Function: SheetNode::CData::make_copy
// Access: Public, Virtual // Access: Public, Virtual
@ -150,6 +153,9 @@ has_cull_callback() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool SheetNode:: bool SheetNode::
cull_callback(CullTraverser *trav, CullTraverserData &data) { cull_callback(CullTraverser *trav, CullTraverserData &data) {
// Statistics
PStatTimer timer(_sheet_node_pcollector);
// Create some geometry on-the-fly to render the sheet. // Create some geometry on-the-fly to render the sheet.
if (get_num_u_subdiv() > 0 && get_num_v_subdiv() > 0) { if (get_num_u_subdiv() > 0 && get_num_v_subdiv() > 0) {
NurbsSurfaceEvaluator *surface = get_surface(); NurbsSurfaceEvaluator *surface = get_surface();

View File

@ -22,6 +22,7 @@
#include "pandabase.h" #include "pandabase.h"
#include "nurbsSurfaceEvaluator.h" #include "nurbsSurfaceEvaluator.h"
#include "pandaNode.h" #include "pandaNode.h"
#include "pStatCollector.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : SheetNode // Class : SheetNode
@ -94,6 +95,8 @@ private:
typedef CycleDataReader<CData> CDReader; typedef CycleDataReader<CData> CDReader;
typedef CycleDataWriter<CData> CDWriter; typedef CycleDataWriter<CData> CDWriter;
static PStatCollector _sheet_node_pcollector;
public: public:
static void register_with_read_factory(); static void register_with_read_factory();
virtual void write_datagram(BamWriter *manager, Datagram &dg); virtual void write_datagram(BamWriter *manager, Datagram &dg);

View File

@ -155,6 +155,7 @@ static LevelCollectorProperties level_properties[] = {
{ 1, "Vertices:Triangles", { 0.8, 0.8, 0.8 } }, { 1, "Vertices:Triangles", { 0.8, 0.8, 0.8 } },
{ 1, "Vertices:Triangle fans", { 0.8, 0.5, 0.2 } }, { 1, "Vertices:Triangle fans", { 0.8, 0.5, 0.2 } },
{ 1, "Vertices:Triangle strips", { 0.2, 0.5, 0.8 } }, { 1, "Vertices:Triangle strips", { 0.2, 0.5, 0.8 } },
{ 1, "Vertices:Indexed triangle strips", { 0.5, 0.2, 0.8 } },
{ 1, "Vertices:Display lists", { 0.8, 0.5, 1.0 } }, { 1, "Vertices:Display lists", { 0.8, 0.5, 1.0 } },
{ 1, "Nodes", { 0.4, 0.2, 0.8 }, "", 500.0 }, { 1, "Nodes", { 0.4, 0.2, 0.8 }, "", 500.0 },
{ 1, "Nodes:GeomNodes", { 0.8, 0.2, 0.0 } }, { 1, "Nodes:GeomNodes", { 0.8, 0.2, 0.0 } },