25 PStatCollector SceneGraphAnalyzerMeter::_show_analyzer_pcollector(
"*:Show scene graph analysis");
27 TypeHandle SceneGraphAnalyzerMeter::_type_handle;
32 SceneGraphAnalyzerMeter::
33 SceneGraphAnalyzerMeter(
const std::string &name,
PandaNode *node) :
35 _last_aspect_ratio(-1) {
45 _update_interval = scene_graph_analyzer_meter_update_interval;
51 set_transform(LMatrix4::scale_mat(scene_graph_analyzer_meter_scale) *
52 LMatrix4::translate_mat(LVector3::rfu(scene_graph_analyzer_meter_side_margins * scene_graph_analyzer_meter_scale, 0.0f, -scene_graph_analyzer_meter_scale)));
53 set_card_color(0.0f, 0.0f, 0.0f, 0.4);
54 set_card_as_margin(scene_graph_analyzer_meter_side_margins, scene_graph_analyzer_meter_side_margins, 0.1f, 0.0f);
55 set_usage_hint(Geom::UH_client);
57 do_update(current_thread);
63 SceneGraphAnalyzerMeter::
64 ~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);
94 _display_region = _window->make_display_region();
95 _display_region->set_sort(scene_graph_analyzer_meter_layer_sort);
98 PT(
Camera) camera =
new Camera(
"scene_graph_analyzer_camera");
104 static const PN_stdfloat left = 0.0f;
105 static const PN_stdfloat right = 2.0f;
106 static const PN_stdfloat bottom = -2.0f;
107 static const PN_stdfloat top = 0.0f;
109 lens->set_film_offset((right + left) * 0.5, (top + bottom) * 0.5);
110 lens->set_near_far(-1000, 1000);
112 camera->set_lens(lens);
113 camera->set_scene(_root);
114 _display_region->set_camera(camera_np);
122 if (_window !=
nullptr) {
123 _window->remove_display_region(_display_region);
125 _display_region =
nullptr;
148 bool SceneGraphAnalyzerMeter::
153 PStatTimer timer(_show_analyzer_pcollector, current_thread);
157 int width = _display_region->get_pixel_width();
158 int height = _display_region->get_pixel_height();
159 PN_stdfloat aspect_ratio = 1;
160 if (width != 0 && height != 0) {
161 aspect_ratio = (PN_stdfloat)height / (PN_stdfloat)width;
165 if (aspect_ratio != _last_aspect_ratio) {
166 _aspect_ratio_transform = TransformState::make_scale(LVecBase3(aspect_ratio, 1, 1));
167 _last_aspect_ratio = aspect_ratio;
169 data._net_transform = data._net_transform->compose(_aspect_ratio_transform);
173 double elapsed = now - _last_update;
174 if (elapsed < 0.0 || elapsed >= _update_interval) {
175 do_update(current_thread);
178 return TextNode::cull_callback(trav, data);
184 void SceneGraphAnalyzerMeter::
185 do_update(
Thread *current_thread) {
188 _scene_graph_analyzer.
clear();
189 _scene_graph_analyzer.
add_node( _node );
191 static const size_t buffer_size = 1024;
192 char buffer[buffer_size];
194 const char *pattern =
"Nodes: %d\n" 197 "Nodes with Attribs: %d\n" 200 "GeomVertexDatas: %d\n" 207 "Texture memory: %.1f KB\n";
209 #if defined(WIN32_VC) || defined(WIN64_VC) 210 _snprintf(buffer, buffer_size, pattern,
211 _scene_graph_analyzer.get_num_nodes(),
212 _scene_graph_analyzer.get_num_instances(),
213 _scene_graph_analyzer.get_num_transforms(),
214 _scene_graph_analyzer.get_num_nodes_with_attribs(),
215 _scene_graph_analyzer.get_num_geom_nodes(),
216 _scene_graph_analyzer.get_num_geoms(),
217 _scene_graph_analyzer.get_num_geom_vertex_datas(),
218 _scene_graph_analyzer.get_num_vertices(),
219 _scene_graph_analyzer.get_num_normals(),
220 _scene_graph_analyzer.get_num_texcoords(),
221 _scene_graph_analyzer.get_num_tris(),
222 _scene_graph_analyzer.get_num_lines(),
223 _scene_graph_analyzer.get_num_points(),
224 _scene_graph_analyzer.get_texture_bytes()/1024.0);
226 snprintf(buffer, buffer_size, pattern,
227 _scene_graph_analyzer.get_num_nodes(),
228 _scene_graph_analyzer.get_num_instances(),
229 _scene_graph_analyzer.get_num_transforms(),
230 _scene_graph_analyzer.get_num_nodes_with_attribs(),
231 _scene_graph_analyzer.get_num_geom_nodes(),
232 _scene_graph_analyzer.get_num_geoms(),
233 _scene_graph_analyzer.get_num_geom_vertex_datas(),
234 _scene_graph_analyzer.get_num_vertices(),
235 _scene_graph_analyzer.get_num_normals(),
236 _scene_graph_analyzer.get_num_texcoords(),
237 _scene_graph_analyzer.get_num_tris(),
238 _scene_graph_analyzer.get_num_lines(),
239 _scene_graph_analyzer.get_num_points(),
240 _scene_graph_analyzer.get_texture_bytes()/1024.0);
242 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...
A base class for any number of different kinds of lenses, linear and otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_bounds(const BoundingVolume *volume)
Resets the bounding volume so that it is the indicated volume.
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_bin(const std::string &bin_name, int draw_order, int priority=0)
Assigns the geometry at this level and below to the named rendering bin.
void add_node(PandaNode *node)
Adds a new node to the set of data for analysis.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear()
Resets all of the data in the analyzer in preparation for a new run.
set_text
Changes the text that is stored in the encoder.
set_transform
Sets the transform that will be applied to this node and below.
A lightweight class that represents a single element that may be timed and/or counted via stats.
get_current_thread
Returns a pointer to the currently-executing Thread object.
set_film_size
Sets the horizontal size of the film without changing its shape.
get_frame_time
Returns the time in seconds as of the last time tick() was called (typically, this will be as of the ...
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_text
Returns the current text, as encoded via the current encoding system.
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.
This is a special kind of GeometricBoundingVolume that fills all of space.
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_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,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.