34FrameRateMeter(
const std::string &name) :
36 _last_aspect_ratio(-1) {
46 _show_milliseconds = frame_rate_meter_milliseconds;
47 if (_show_milliseconds) {
48 _text_pattern = frame_rate_meter_ms_text_pattern;
50 _text_pattern = frame_rate_meter_text_pattern;
53 _update_interval = frame_rate_meter_update_interval;
59 PN_stdfloat height = 1.0f;
66 set_transform(LMatrix4::scale_mat(frame_rate_meter_scale) *
67 LMatrix4::translate_mat(LVector3::rfu(-frame_rate_meter_side_margins * frame_rate_meter_scale, 0.0f, -frame_rate_meter_scale * height)));
68 set_card_color(0.0f, 0.0f, 0.0f, 0.4);
69 set_card_as_margin(frame_rate_meter_side_margins, frame_rate_meter_side_margins, 0.1f, 0.0f);
72 do_update(current_thread);
93 _root = NodePath(
"frame_rate_root");
94 _root.attach_new_node(
this);
98 _root.node()->set_attrib(dt, 1);
99 _root.node()->set_attrib(dw, 1);
100 _root.set_material_off(1);
101 _root.set_two_sided(1, 1);
106 _root.set_bin(
"unsorted", 0);
109 _display_region = _window->make_mono_display_region();
110 _display_region->set_sort(frame_rate_meter_layer_sort);
114 NodePath camera_np = _root.attach_new_node(camera);
119 static const PN_stdfloat left = -2.0f;
120 static const PN_stdfloat right = 0.0f;
121 static const PN_stdfloat bottom = -2.0f;
122 static const PN_stdfloat top = 0.0f;
124 lens->set_film_offset((right + left) * 0.5, (top + bottom) * 0.5);
125 lens->set_near_far(-1000, 1000);
127 camera->set_lens(lens);
128 camera->set_scene(_root);
129 _display_region->set_camera(camera_np);
137 if (_window !=
nullptr) {
138 _window->remove_display_region(_display_region);
140 _display_region =
nullptr;
167 nassertr(_display_region !=
nullptr,
false);
172 PStatTimer timer(_show_fps_pcollector, current_thread);
176 int width = _display_region->get_pixel_width();
177 int height = _display_region->get_pixel_height();
178 PN_stdfloat aspect_ratio = 1;
179 if (width != 0 && height != 0) {
180 aspect_ratio = (PN_stdfloat)height / (PN_stdfloat)width;
184 if (aspect_ratio != _last_aspect_ratio) {
185 _aspect_ratio_transform = TransformState::make_scale(LVecBase3(aspect_ratio, 1, 1));
186 _last_aspect_ratio = aspect_ratio;
188 data._net_transform = data._net_transform->compose(_aspect_ratio_transform);
191 double now = _clock_object->get_frame_time(current_thread);
192 double elapsed = now - _last_update;
193 if (elapsed < 0.0 || elapsed >= _update_interval) {
194 do_update(current_thread);
204do_update(
Thread *current_thread) {
205 _last_update = _clock_object->get_frame_time(current_thread);
207 double value = _clock_object->get_average_frame_rate(current_thread);
208 double deviation = _clock_object->calc_frame_rate_deviation(current_thread);
210 if (_show_milliseconds) {
211 value = 1000.0 / value;
212 deviation = 1000.0 / deviation;
215 static const size_t buffer_size = 1024;
216 char buffer[buffer_size];
217#if defined(WIN32_VC) || defined(WIN64_VC)
219 sprintf(buffer, _text_pattern.c_str(), value, deviation);
221 snprintf(buffer, buffer_size, _text_pattern.c_str(), value, deviation);
223 nassertv(strlen(buffer) < buffer_size);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
static ConstPointerTo< RenderAttrib > make(PandaCompareFunc mode)
Constructs a new DepthTestAttrib object.
static ConstPointerTo< RenderAttrib > make(Mode mode)
Constructs a new DepthWriteAttrib object.
void setup_window(GraphicsOutput *window)
Sets up the frame rate meter to create a DisplayRegion to render itself into the indicated window.
void clear_window()
Undoes the effect of a previous call to setup_window().
This is a base class for the various different classes that represent the result of a frame of render...
A base class for any number of different kinds of lenses, linear and otherwise.
set_film_size
Sets the horizontal size of the film without changing its shape.
This is a special kind of GeometricBoundingVolume that fills all of space.
A lightweight class that represents a single element that may be timed and/or counted via stats.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
This is the base class for a number of render attributes (other than transform) that may be set on sc...
set_text
Changes the text that is stored in the encoder.
get_text
Returns the current text, as encoded via the current encoding system.
An encapsulation of a font; i.e.
get_line_height
Returns the number of units high each line of text is.
The primary interface to this module.
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
A thread; that is, a lightweight process.
get_current_thread
Returns a pointer to the currently-executing Thread object.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.