15 #include "sceneGraphAnalyzerMeter.h" 17 #include "displayRegion.h" 18 #include "orthographicLens.h" 19 #include "config_grutil.h" 20 #include "depthTestAttrib.h" 21 #include "depthWriteAttrib.h" 22 #include "pStatTimer.h" 25 PStatCollector SceneGraphAnalyzerMeter::_show_analyzer_pcollector(
"*:Show scene graph analysis");
27 TypeHandle SceneGraphAnalyzerMeter::_type_handle;
34 SceneGraphAnalyzerMeter::
40 _update_interval = scene_graph_analyzer_meter_update_interval;
48 set_card_color(0.0f, 0.0f, 0.0f, 0.4);
49 set_card_as_margin(scene_graph_analyzer_meter_side_margins, scene_graph_analyzer_meter_side_margins, 0.1f, 0.0f);
52 do_update(current_thread);
60 SceneGraphAnalyzerMeter::
61 ~SceneGraphAnalyzerMeter() {
78 _root =
NodePath(
"scene_graph_analyzer_root");
81 CPT(
RenderAttrib) dt = DepthTestAttrib::make(DepthTestAttrib::M_none);
82 CPT(
RenderAttrib) dw = DepthWriteAttrib::make(DepthWriteAttrib::M_off);
89 _display_region = _window->make_display_region();
90 _display_region->set_sort(scene_graph_analyzer_meter_layer_sort);
93 PT(
Camera) camera =
new Camera(
"scene_graph_analyzer_camera");
98 static const PN_stdfloat left = -1.0f;
99 static const PN_stdfloat right = 1.0f;
100 static const PN_stdfloat bottom = -1.0f;
101 static const PN_stdfloat top = 1.0f;
103 lens->set_film_offset((right + left) * 0.5, (top + bottom) * 0.5);
104 lens->set_near_far(-1000, 1000);
106 camera->set_lens(lens);
107 camera->set_scene(_root);
108 _display_region->set_camera(camera_np);
120 _window->remove_display_region(_display_region);
152 bool SceneGraphAnalyzerMeter::
157 PStatTimer timer(_show_analyzer_pcollector, current_thread);
161 double elapsed = now - _last_update;
162 if (elapsed < 0.0 || elapsed >= _update_interval) {
163 do_update(current_thread);
166 return TextNode::cull_callback(trav, data);
174 void SceneGraphAnalyzerMeter::
175 do_update(
Thread *current_thread) {
178 _scene_graph_analyzer.
clear();
179 _scene_graph_analyzer.
add_node( _node );
181 static const size_t buffer_size = 1024;
182 char buffer[buffer_size];
184 const char *pattern =
"Nodes: %d\n" 187 "Nodes with Attribs: %d\n" 190 "GeomVertexDatas: %d\n" 197 "Texture memory: %.1f KB\n";
199 #if defined(WIN32_VC) || defined(WIN64_VC) 200 _snprintf(buffer, buffer_size, pattern,
201 _scene_graph_analyzer.get_num_nodes(),
202 _scene_graph_analyzer.get_num_instances(),
203 _scene_graph_analyzer.get_num_transforms(),
204 _scene_graph_analyzer.get_num_nodes_with_attribs(),
205 _scene_graph_analyzer.get_num_geom_nodes(),
206 _scene_graph_analyzer.get_num_geoms(),
207 _scene_graph_analyzer.get_num_geom_vertex_datas(),
208 _scene_graph_analyzer.get_num_vertices(),
209 _scene_graph_analyzer.get_num_normals(),
210 _scene_graph_analyzer.get_num_texcoords(),
211 _scene_graph_analyzer.get_num_tris(),
212 _scene_graph_analyzer.get_num_lines(),
213 _scene_graph_analyzer.get_num_points(),
214 _scene_graph_analyzer.get_texture_bytes()/1024.0);
216 snprintf(buffer, buffer_size, pattern,
217 _scene_graph_analyzer.get_num_nodes(),
218 _scene_graph_analyzer.get_num_instances(),
219 _scene_graph_analyzer.get_num_transforms(),
220 _scene_graph_analyzer.get_num_nodes_with_attribs(),
221 _scene_graph_analyzer.get_num_geom_nodes(),
222 _scene_graph_analyzer.get_num_geoms(),
223 _scene_graph_analyzer.get_num_geom_vertex_datas(),
224 _scene_graph_analyzer.get_num_vertices(),
225 _scene_graph_analyzer.get_num_normals(),
226 _scene_graph_analyzer.get_num_texcoords(),
227 _scene_graph_analyzer.get_num_tris(),
228 _scene_graph_analyzer.get_num_lines(),
229 _scene_graph_analyzer.get_num_points(),
230 _scene_graph_analyzer.get_texture_bytes()/1024.0);
232 nassertv(strlen(buffer) < buffer_size);
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
A basic node of the scene graph or data graph.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
static LMatrix4f scale_mat(const LVecBase3f &scale)
Returns a matrix that applies the indicated scale in each of the three axes.
A base class for any number of different kinds of lenses, linear and otherwise.
static LMatrix4f translate_mat(const LVecBase3f &trans)
Returns a matrix that applies the indicated translation.
void set_text(const string &text)
Changes the text that is displayed under the TextNode.
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
void set_film_size(PN_stdfloat width)
Sets the horizontal size of the film without changing its shape.
void add_node(PandaNode *node)
Adds a new node to the set of data for analysis.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
double get_frame_time(Thread *current_thread=Thread::get_current_thread()) const
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
void clear()
Resets all of the data in the analyzer in preparation for a new run.
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
static LVector3f rfu(float right, float fwd, float up, CoordinateSystem cs=CS_default)
Returns a vector that is described by its right, forward, and up components, in whatever way the coor...
A lightweight class that represents a single element that may be timed and/or counted via stats...
void set_card_as_margin(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Specifies that a (possibly opaque or semitransparent) card will be held behind the text when it is ne...
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
This is a base class for the various different classes that represent the result of a frame of render...
void set_attrib(const RenderAttrib *attrib, int override=0)
Adds the indicated render attribute to the scene graph on this node.
void clear_window()
Undoes the effect of a previous call to setup_window().
PandaNode * node() const
Returns the referenced node of the path.
A thread; that is, a lightweight process.
void set_material_off(int priority=0)
Sets the geometry at this level and below to render using no material.
The primary interface to this module.
void setup_window(GraphicsOutput *window)
Sets up the frame rate meter to create a DisplayRegion to render itself into the indicated window...
A rectangular subregion within a window for rendering into.
TypeHandle is the identifier used to differentiate C++ class types.
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
void set_usage_hint(Geom::UsageHint usage_hint)
Specifies the UsageHint that will be applied to generated geometry.
void set_two_sided(bool two_sided, int priority=0)
Specifically sets or disables two-sided rendering mode on this particular node.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
void set_transform(const LMatrix4 &transform)
Sets an additional transform that is applied to the entire text paragraph.
string get_text() const
Returns the current text, as encoded via the current encoding system.