34 FrameRateMeter(
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);
96 CPT(
RenderAttrib) dt = DepthTestAttrib::make(DepthTestAttrib::M_none);
97 CPT(
RenderAttrib) dw = DepthWriteAttrib::make(DepthWriteAttrib::M_off);
109 _display_region = _window->make_mono_display_region();
110 _display_region->set_sort(frame_rate_meter_layer_sort);
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;
163 bool FrameRateMeter::
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);
192 double elapsed = now - _last_update;
193 if (elapsed < 0.0 || elapsed >= _update_interval) {
194 do_update(current_thread);
197 return TextNode::cull_callback(trav, data);
203 void FrameRateMeter::
204 do_update(
Thread *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);
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
get_average_frame_rate
Returns the average frame rate in number of frames per second over the last get_average_frame_rate_in...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
double calc_frame_rate_deviation(Thread *current_thread=Thread::get_current_thread()) const
Returns the standard deviation of the frame times of the frames rendered over the past get_average_fr...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear_window()
Undoes the effect of a previous call to setup_window().
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.
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.
An encapsulation of a font; i.e.
set_text
Changes the text that is stored in the encoder.
void setup_window(GraphicsOutput *window)
Sets up the frame rate meter to create a DisplayRegion to render itself into the indicated window.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
get_line_height
Returns the number of units high each line of text is.
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.
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.