From 8d1a458c008c6f318fd286c997a5448134f5f7c2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 13 Jan 2005 17:54:16 +0000 Subject: [PATCH] ropeNode stats and optimizations --- panda/src/display/graphicsStateGuardian.cxx | 2 ++ panda/src/display/graphicsStateGuardian.h | 3 +- .../glstuff/glGraphicsStateGuardian_src.cxx | 6 +++- panda/src/parametrics/ropeNode.I | 28 +++++++++++++++++++ panda/src/parametrics/ropeNode.cxx | 23 +++++++++++++-- panda/src/parametrics/ropeNode.h | 6 ++++ panda/src/parametrics/sheetNode.cxx | 6 ++++ panda/src/parametrics/sheetNode.h | 3 ++ panda/src/pstatclient/pStatProperties.cxx | 1 + 9 files changed, 74 insertions(+), 4 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 0bfa3577ff..3a9a8eaaec 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -54,6 +54,7 @@ PStatCollector GraphicsStateGuardian::_vertices_tristrip_pcollector("Vertices:Tr PStatCollector GraphicsStateGuardian::_vertices_trifan_pcollector("Vertices:Triangle fans"); PStatCollector GraphicsStateGuardian::_vertices_tri_pcollector("Vertices:Triangles"); 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::_transform_state_pcollector("State changes:Transforms"); PStatCollector GraphicsStateGuardian::_texture_state_pcollector("State changes:Textures"); @@ -1282,6 +1283,7 @@ init_frame_pstats() { _vertices_trifan_pcollector.clear_level(); _vertices_tri_pcollector.clear_level(); _vertices_other_pcollector.clear_level(); + _vertices_indexed_tristrip_pcollector.clear_level(); _state_pcollector.clear_level(); _transform_state_pcollector.clear_level(); diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 6d270f37b9..110a3536a6 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -300,7 +300,8 @@ public: static PStatCollector _vertices_tristrip_pcollector; static PStatCollector _vertices_trifan_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 _transform_state_pcollector; static PStatCollector _texture_state_pcollector; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index d40d915563..a3da513045 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1559,7 +1559,11 @@ draw_tristrip(GeomTristrip *geom, GeomContext *gc) { // PStatTimer timer(_draw_primitive_pcollector); // Using PStatTimer may cause a compiler crash. _draw_primitive_pcollector.start(); - _vertices_tristrip_pcollector.add_level(geom->get_num_vertices()); + if (geom->get_coords_index().is_null()) { + _vertices_tristrip_pcollector.add_level(geom->get_num_vertices()); + } else { + _vertices_indexed_tristrip_pcollector.add_level(geom->get_num_vertices()); + } #endif issue_scene_graph_color(); diff --git a/panda/src/parametrics/ropeNode.I b/panda/src/parametrics/ropeNode.I index 0208de453c..737b92be6c 100644 --- a/panda/src/parametrics/ropeNode.I +++ b/panda/src/parametrics/ropeNode.I @@ -32,6 +32,7 @@ CData() { _normal_mode = RopeNode::NM_none; _tube_up = LVector3f::up(); _matrix = LMatrix4f::ident_mat(); + _has_matrix = false; _use_vertex_color = false; _num_subdiv = 10; _num_slices = 5; @@ -53,6 +54,7 @@ CData(const RopeNode::CData ©) : _normal_mode(copy._normal_mode), _tube_up(copy._tube_up), _matrix(copy._matrix), + _has_matrix(copy._has_matrix), _use_vertex_color(copy._use_vertex_color), _num_subdiv(copy._num_subdiv), _num_slices(copy._num_slices), @@ -366,6 +368,32 @@ INLINE void RopeNode:: set_matrix(const LMatrix4f &matrix) { CDWriter cdata(_cycler); 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; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/parametrics/ropeNode.cxx b/panda/src/parametrics/ropeNode.cxx index e8bb10a567..88f25704df 100644 --- a/panda/src/parametrics/ropeNode.cxx +++ b/panda/src/parametrics/ropeNode.cxx @@ -27,9 +27,12 @@ #include "bamReader.h" #include "datagram.h" #include "datagramIterator.h" +#include "pStatTimer.h" TypeHandle RopeNode::_type_handle; +PStatCollector RopeNode::_rope_node_pcollector("Cull:RopeNode"); + //////////////////////////////////////////////////////////////////// // Function: RopeNode::CData::make_copy // Access: Public, Virtual @@ -150,12 +153,19 @@ has_cull_callback() const { //////////////////////////////////////////////////////////////////// bool RopeNode:: cull_callback(CullTraverser *trav, CullTraverserData &data) { + // Statistics + PStatTimer timer(_rope_node_pcollector); + // Create some geometry on-the-fly to render the rope. if (get_num_subdiv() > 0) { NurbsCurveEvaluator *curve = get_curve(); if (curve != (NurbsCurveEvaluator *)NULL) { - PT(NurbsCurveResult) result = - curve->evaluate(data._node_path.get_node_path(), get_matrix()); + PT(NurbsCurveResult) result; + 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) { switch (get_render_mode()) { @@ -251,6 +261,15 @@ do_recompute_bound(const NodePath &rel_to) { if (curve != (NurbsCurveEvaluator *)NULL) { pvector verts; get_curve()->get_vertices(verts, rel_to); + + if (has_matrix()) { + // And then apply the indicated matrix. + const LMatrix4f &mat = get_matrix(); + pvector::iterator vi; + for (vi = verts.begin(); vi != verts.end(); ++vi) { + (*vi) = (*vi) * mat; + } + } GeometricBoundingVolume *gbv; DCAST_INTO_R(gbv, bound, bound); diff --git a/panda/src/parametrics/ropeNode.h b/panda/src/parametrics/ropeNode.h index ff94c1515f..f39490005c 100644 --- a/panda/src/parametrics/ropeNode.h +++ b/panda/src/parametrics/ropeNode.h @@ -22,6 +22,7 @@ #include "pandabase.h" #include "nurbsCurveEvaluator.h" #include "pandaNode.h" +#include "pStatCollector.h" //////////////////////////////////////////////////////////////////// // Class : RopeNode @@ -132,6 +133,8 @@ PUBLISHED: INLINE float get_thickness() const; INLINE void set_matrix(const LMatrix4f &matrix); + INLINE void clear_matrix(); + INLINE bool has_matrix() const; INLINE const LMatrix4f &get_matrix() const; void reset_bound(const NodePath &rel_to); @@ -201,6 +204,7 @@ private: NormalMode _normal_mode; LVector3f _tube_up; LMatrix4f _matrix; + bool _has_matrix; bool _use_vertex_color; int _num_subdiv; int _num_slices; @@ -211,6 +215,8 @@ private: typedef CycleDataReader CDReader; typedef CycleDataWriter CDWriter; + static PStatCollector _rope_node_pcollector; + public: static void register_with_read_factory(); virtual void write_datagram(BamWriter *manager, Datagram &dg); diff --git a/panda/src/parametrics/sheetNode.cxx b/panda/src/parametrics/sheetNode.cxx index 2a4a4d0fb8..4ba3a9aaee 100644 --- a/panda/src/parametrics/sheetNode.cxx +++ b/panda/src/parametrics/sheetNode.cxx @@ -26,9 +26,12 @@ #include "bamReader.h" #include "datagram.h" #include "datagramIterator.h" +#include "pStatTimer.h" TypeHandle SheetNode::_type_handle; +PStatCollector SheetNode::_sheet_node_pcollector("Cull:SheetNode"); + //////////////////////////////////////////////////////////////////// // Function: SheetNode::CData::make_copy // Access: Public, Virtual @@ -150,6 +153,9 @@ has_cull_callback() const { //////////////////////////////////////////////////////////////////// bool SheetNode:: cull_callback(CullTraverser *trav, CullTraverserData &data) { + // Statistics + PStatTimer timer(_sheet_node_pcollector); + // Create some geometry on-the-fly to render the sheet. if (get_num_u_subdiv() > 0 && get_num_v_subdiv() > 0) { NurbsSurfaceEvaluator *surface = get_surface(); diff --git a/panda/src/parametrics/sheetNode.h b/panda/src/parametrics/sheetNode.h index 84f5248448..9d9e207a67 100644 --- a/panda/src/parametrics/sheetNode.h +++ b/panda/src/parametrics/sheetNode.h @@ -22,6 +22,7 @@ #include "pandabase.h" #include "nurbsSurfaceEvaluator.h" #include "pandaNode.h" +#include "pStatCollector.h" //////////////////////////////////////////////////////////////////// // Class : SheetNode @@ -94,6 +95,8 @@ private: typedef CycleDataReader CDReader; typedef CycleDataWriter CDWriter; + static PStatCollector _sheet_node_pcollector; + public: static void register_with_read_factory(); virtual void write_datagram(BamWriter *manager, Datagram &dg); diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index 222ada67f8..fa51bdc8e7 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -155,6 +155,7 @@ static LevelCollectorProperties level_properties[] = { { 1, "Vertices:Triangles", { 0.8, 0.8, 0.8 } }, { 1, "Vertices:Triangle fans", { 0.8, 0.5, 0.2 } }, { 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, "Nodes", { 0.4, 0.2, 0.8 }, "", 500.0 }, { 1, "Nodes:GeomNodes", { 0.8, 0.2, 0.0 } },