From 695f225b103a6164afcf6d6adc003caa8e28e2e8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 18 May 2001 16:27:09 +0000 Subject: [PATCH] Adding vertex counters to PStats. --- panda/src/display/graphicsStateGuardian.cxx | 5 +++ panda/src/display/graphicsStateGuardian.h | 5 +++ panda/src/glgsg/glGraphicsStateGuardian.cxx | 16 +++++++++ panda/src/gobj/geom.cxx | 20 +++++++++++ panda/src/gobj/geom.h | 2 ++ panda/src/pstatclient/pStatProperties.cxx | 9 +++-- .../src/gtk-stats/gtkStatsStripWindow.cxx | 36 ++++++++++++++----- pandatool/src/pstatserver/pStatGraph.cxx | 7 ++-- pandatool/src/pstatserver/pStatPianoRoll.cxx | 7 ++-- pandatool/src/pstatserver/pStatStripChart.cxx | 7 ++-- pandatool/src/pstatserver/pStatViewLevel.cxx | 7 ++-- 11 files changed, 91 insertions(+), 30 deletions(-) diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 68f94b6d46..171348c51b 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -19,6 +19,11 @@ PStatCollector GraphicsStateGuardian::_total_texusage_pcollector("Texture usage" PStatCollector GraphicsStateGuardian::_active_texusage_pcollector("Texture usage:Active"); PStatCollector GraphicsStateGuardian::_total_texmem_pcollector("Texture memory"); PStatCollector GraphicsStateGuardian::_used_texmem_pcollector("Texture memory:In use"); +PStatCollector GraphicsStateGuardian::_vertices_pcollector("Vertices"); +PStatCollector GraphicsStateGuardian::_vertices_tristrip_pcollector("Vertices:Triangle strips"); +PStatCollector GraphicsStateGuardian::_vertices_trifan_pcollector("Vertices:Triangle fans"); +PStatCollector GraphicsStateGuardian::_vertices_tri_pcollector("Vertices:Triangles"); +PStatCollector GraphicsStateGuardian::_vertices_other_pcollector("Vertices:Other"); #endif TypeHandle GraphicsStateGuardian::_type_handle; diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 25cb3b775b..1bf115e9c0 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -175,6 +175,11 @@ protected: static PStatCollector _active_texusage_pcollector; static PStatCollector _total_texmem_pcollector; static PStatCollector _used_texmem_pcollector; + static PStatCollector _vertices_pcollector; + static PStatCollector _vertices_tristrip_pcollector; + static PStatCollector _vertices_trifan_pcollector; + static PStatCollector _vertices_tri_pcollector; + static PStatCollector _vertices_other_pcollector; private: typedef set Textures; diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index a94f60aefe..27b9c34173 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -485,6 +485,12 @@ render_frame(const AllAttributesWrapper &initial_state) { NodeAttributes state; state.set_attribute(TextureTransition::get_class_type(), new TextureAttribute); set_state(state, false); + + // Also clear out our vertex counters while we're here. + _vertices_tristrip_pcollector.set_level(0); + _vertices_trifan_pcollector.set_level(0); + _vertices_tri_pcollector.set_level(0); + _vertices_other_pcollector.set_level(0); #endif if (_clear_buffer_type != 0) { @@ -717,6 +723,7 @@ draw_point(const GeomPoint *geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_point()" << endl; #endif + _vertices_other_pcollector.add_level(geom->get_num_vertices()); call_glPointSize(geom->get_size()); @@ -775,6 +782,7 @@ draw_line(const GeomLine* geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_line()" << endl; #endif + _vertices_other_pcollector.add_level(geom->get_num_vertices()); call_glLineWidth(geom->get_width()); @@ -835,6 +843,7 @@ draw_linestrip(const GeomLinestrip* geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_linestrip()" << endl; #endif + _vertices_other_pcollector.add_level(geom->get_num_vertices()); call_glLineWidth(geom->get_width()); @@ -945,6 +954,7 @@ draw_sprite(const GeomSprite *geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_sprite()" << endl; #endif + _vertices_other_pcollector.add_level(geom->get_num_vertices()); Texture *tex = geom->get_texture(); nassertv(tex != (Texture *) NULL); @@ -1219,6 +1229,7 @@ draw_polygon(const GeomPolygon *geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_polygon()" << endl; #endif + _vertices_other_pcollector.add_level(geom->get_num_vertices()); int nprims = geom->get_num_prims(); const int *plen = geom->get_lengths(); @@ -1291,6 +1302,7 @@ draw_tri(const GeomTri *geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_tri()" << endl; #endif + _vertices_tri_pcollector.add_level(geom->get_num_vertices()); int nprims = geom->get_num_prims(); Geom::VertexIterator vi = geom->make_vertex_iterator(); @@ -1358,6 +1370,7 @@ draw_quad(const GeomQuad *geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_quad()" << endl; #endif + _vertices_other_pcollector.add_level(geom->get_num_vertices()); int nprims = geom->get_num_prims(); Geom::VertexIterator vi = geom->make_vertex_iterator(); @@ -1425,6 +1438,7 @@ draw_tristrip(const GeomTristrip *geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_tristrip()" << endl; #endif + _vertices_tristrip_pcollector.add_level(geom->get_num_vertices()); int nprims = geom->get_num_prims(); const int *plen = geom->get_lengths(); @@ -1514,6 +1528,7 @@ draw_trifan(const GeomTrifan *geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_trifan()" << endl; #endif + _vertices_trifan_pcollector.add_level(geom->get_num_vertices()); int nprims = geom->get_num_prims(); const int *plen = geom->get_lengths(); @@ -1604,6 +1619,7 @@ draw_sphere(const GeomSphere *geom) { #ifdef GSG_VERBOSE glgsg_cat.debug() << "draw_sphere()" << endl; #endif + _vertices_other_pcollector.add_level(geom->get_num_vertices()); int nprims = geom->get_num_prims(); Geom::VertexIterator vi = geom->make_vertex_iterator(); diff --git a/panda/src/gobj/geom.cxx b/panda/src/gobj/geom.cxx index 790840c8b6..2644c24fec 100644 --- a/panda/src/gobj/geom.cxx +++ b/panda/src/gobj/geom.cxx @@ -306,6 +306,26 @@ get_texcoords(PTA_TexCoordf &texcoords, GeomBindType &bind, tindex = _tindex; } +//////////////////////////////////////////////////////////////////// +// Function: Geom::get_num_vertices +// Access: Public +// Description: Returns the number of vertices required by all all +// the prims in the Geom. +//////////////////////////////////////////////////////////////////// +int Geom:: +get_num_vertices() const { + if (!uses_components()) { + return get_num_vertices_per_prim() * get_num_prims(); + } + + int total = 0; + for (int i = 0; i < get_num_prims(); i++) { + total += _primlengths[i]; + } + + return total; +} + //////////////////////////////////////////////////////////////////// // Function: Geom::explode // Access: Public, Virtual diff --git a/panda/src/gobj/geom.h b/panda/src/gobj/geom.h index 4ca2989a2e..2566d0124b 100644 --- a/panda/src/gobj/geom.h +++ b/panda/src/gobj/geom.h @@ -182,6 +182,8 @@ public: virtual int get_num_more_vertices_than_components() const=0; virtual bool uses_components() const=0; + int get_num_vertices() const; + // Returns the length of the indicated primitive. Often this is the // same for all primitives in the Geom. However, geoms which use // the lengths array will redefine this appropriately. diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index c49d530289..f43101f572 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -64,10 +64,15 @@ static TimeCollectorProperties time_properties[] = { }; static LevelCollectorProperties level_properties[] = { - { "Texture usage", { 1.0, 0.0, 0.0 }, "MB", 8.0 }, + { "Texture usage", { 1.0, 0.0, 0.0 }, "MB", 12.0 }, { "Texture usage:Active", { 1.0, 1.0, 0.0 } }, - { "Texture memory", { 0.0, 0.0, 1.0 }, "MB", 8.0 }, + { "Texture memory", { 0.0, 0.0, 1.0 }, "MB", 12.0 }, { "Texture memory:In use", { 0.0, 1.0, 1.0 } }, + { "Vertices", { 0.5, 0.2, 0.0 }, "", 10000.0 }, + { "Vertices:Other", { 0.2, 0.2, 0.2 } }, + { "Vertices:Triangles", { 0.8, 0.8, 0.8 } }, + { "Vertices:Triangle fans", { 0.8, 0.5, 0.2 } }, + { "Vertices:Triangle strips", { 0.2, 0.5, 0.8 } }, { NULL } }; diff --git a/pandatool/src/gtk-stats/gtkStatsStripWindow.cxx b/pandatool/src/gtk-stats/gtkStatsStripWindow.cxx index cf57cb58ec..d1a64c4b0d 100644 --- a/pandatool/src/gtk-stats/gtkStatsStripWindow.cxx +++ b/pandatool/src/gtk-stats/gtkStatsStripWindow.cxx @@ -66,25 +66,45 @@ mark_dead() { void GtkStatsStripWindow:: new_collector() { const PStatClientData *client_data = _monitor->get_client_data(); - _levels_menu->items().clear(); + + // Determine the set of collectors that display level data. We'll + // want to put these on the "Levels" pull-down menu. + + set levels; int num_collectors = client_data->get_num_collectors(); for (int i = 0; i < num_collectors; i++) { if (client_data->has_collector(i) && client_data->get_collector_has_level(i)) { + // We only put top-level entries on the menu. Thus, walk up + // from this collector to its top level (the one below Frame). + int collector_index = i; const PStatCollectorDef &def = - client_data->get_collector_def(i); + client_data->get_collector_def(collector_index); + int parent_index = def._parent_index; - // Normally, we only put top-level entries on the menu. The - // lower entries can take care of themselves. - if (def._parent_index == 0) { - _levels_menu->items().push_back - (MenuElem(client_data->get_collector_name(i), - bind(slot(this, &GtkStatsStripWindow::menu_show_levels), i))); + while (parent_index != 0) { + collector_index = parent_index; + const PStatCollectorDef &def = + client_data->get_collector_def(collector_index); + parent_index = def._parent_index; } + + levels.insert(collector_index); } } + // Now put the collectors we found on the menu. + _levels_menu->items().clear(); + set::const_iterator li; + for (li = levels.begin(); li != levels.end(); ++li) { + int collector_index = (*li); + _levels_menu->items().push_back + (MenuElem(client_data->get_collector_name(collector_index), + bind(slot(this, &GtkStatsStripWindow::menu_show_levels), collector_index))); + } + + // Also re-set-up the scale menu, in case the properties have changed. setup_scale_menu(); } diff --git a/pandatool/src/pstatserver/pStatGraph.cxx b/pandatool/src/pstatserver/pStatGraph.cxx index 15ed252f8b..737916b38f 100644 --- a/pandatool/src/pstatserver/pStatGraph.cxx +++ b/pandatool/src/pstatserver/pStatGraph.cxx @@ -180,12 +180,9 @@ public: _client_data(client_data) { } bool operator () (int a, int b) const { - // By casting the sort numbers to unsigned ints, we cheat and make - // -1 appear to be a very large positive integer, thus placing - // collectors with a -1 sort value at the very end. return - (unsigned int)_client_data->get_collector_def(a)._sort < - (unsigned int)_client_data->get_collector_def(b)._sort; + _client_data->get_collector_def(a)._sort > + _client_data->get_collector_def(b)._sort; } const PStatClientData *_client_data; }; diff --git a/pandatool/src/pstatserver/pStatPianoRoll.cxx b/pandatool/src/pstatserver/pStatPianoRoll.cxx index 4efa7efe88..5d288c1b49 100644 --- a/pandatool/src/pstatserver/pStatPianoRoll.cxx +++ b/pandatool/src/pstatserver/pStatPianoRoll.cxx @@ -258,12 +258,9 @@ public: _client_data(client_data) { } bool operator () (int a, int b) const { - // By casting the sort numbers to unsigned ints, we cheat and make - // -1 appear to be a very large positive integer, thus placing - // collectors with a -1 sort value at the very end. return - (unsigned int)_client_data->get_collector_def(a)._sort > - (unsigned int)_client_data->get_collector_def(b)._sort; + _client_data->get_collector_def(a)._sort > + _client_data->get_collector_def(b)._sort; } const PStatClientData *_client_data; }; diff --git a/pandatool/src/pstatserver/pStatStripChart.cxx b/pandatool/src/pstatserver/pStatStripChart.cxx index ee91bcb4c0..d8d2706a0e 100644 --- a/pandatool/src/pstatserver/pStatStripChart.cxx +++ b/pandatool/src/pstatserver/pStatStripChart.cxx @@ -432,12 +432,9 @@ public: _client_data(client_data) { } bool operator () (int a, int b) const { - // By casting the sort numbers to unsigned ints, we cheat and make - // -1 appear to be a very large positive integer, thus placing - // collectors with a -1 sort value at the very end. return - (unsigned int)_client_data->get_collector_def(a)._sort > - (unsigned int)_client_data->get_collector_def(b)._sort; + _client_data->get_collector_def(a)._sort > + _client_data->get_collector_def(b)._sort; } const PStatClientData *_client_data; }; diff --git a/pandatool/src/pstatserver/pStatViewLevel.cxx b/pandatool/src/pstatserver/pStatViewLevel.cxx index 6e13309a06..814307d142 100644 --- a/pandatool/src/pstatserver/pStatViewLevel.cxx +++ b/pandatool/src/pstatserver/pStatViewLevel.cxx @@ -39,12 +39,9 @@ public: _client_data(client_data) { } bool operator () (const PStatViewLevel *a, const PStatViewLevel *b) const { - // By casting the sort numbers to unsigned ints, we cheat and make - // -1 appear to be a very large positive integer, thus placing - // collectors with a -1 sort value at the very end. return - (unsigned int)_client_data->get_collector_def(a->get_collector())._sort < - (unsigned int)_client_data->get_collector_def(b->get_collector())._sort; + _client_data->get_collector_def(a->get_collector())._sort > + _client_data->get_collector_def(b->get_collector())._sort; } const PStatClientData *_client_data; };