15 #include "frameRateMeter.h"
17 #include "displayRegion.h"
18 #include "orthographicLens.h"
19 #include "clockObject.h"
20 #include "config_grutil.h"
21 #include "depthTestAttrib.h"
22 #include "depthWriteAttrib.h"
23 #include "pStatTimer.h"
24 #include "omniBoundingVolume.h"
37 FrameRateMeter(
const string &name) :
39 _last_aspect_ratio(-1) {
49 _show_milliseconds = frame_rate_meter_milliseconds;
50 if (_show_milliseconds) {
51 _text_pattern = frame_rate_meter_ms_text_pattern;
53 _text_pattern = frame_rate_meter_text_pattern;
56 _update_interval = frame_rate_meter_update_interval;
62 PN_stdfloat height = 1.0f;
71 set_card_color(0.0f, 0.0f, 0.0f, 0.4);
72 set_card_as_margin(frame_rate_meter_side_margins, frame_rate_meter_side_margins, 0.1f, 0.0f);
75 do_update(current_thread);
101 _root =
NodePath(
"frame_rate_root");
104 CPT(
RenderAttrib) dt = DepthTestAttrib::make(DepthTestAttrib::M_none);
105 CPT(
RenderAttrib) dw = DepthWriteAttrib::make(DepthWriteAttrib::M_off);
117 _display_region = _window->make_mono_display_region();
118 _display_region->set_sort(frame_rate_meter_layer_sort);
127 static const PN_stdfloat left = -2.0f;
128 static const PN_stdfloat right = 0.0f;
129 static const PN_stdfloat bottom = -2.0f;
130 static const PN_stdfloat top = 0.0f;
132 lens->set_film_offset((right + left) * 0.5, (top + bottom) * 0.5);
133 lens->set_near_far(-1000, 1000);
135 camera->set_lens(lens);
136 camera->set_scene(_root);
137 _display_region->set_camera(camera_np);
149 _window->remove_display_region(_display_region);
181 bool FrameRateMeter::
185 nassertr(_display_region != NULL,
false);
190 PStatTimer timer(_show_fps_pcollector, current_thread);
194 int width = _display_region->get_pixel_width();
195 int height = _display_region->get_pixel_height();
196 PN_stdfloat aspect_ratio = 1;
197 if (width != 0 && height != 0) {
198 aspect_ratio = (PN_stdfloat)height / (PN_stdfloat)width;
202 if (aspect_ratio != _last_aspect_ratio) {
203 _aspect_ratio_transform = TransformState::make_scale(
LVecBase3(aspect_ratio, 1, 1));
204 _last_aspect_ratio = aspect_ratio;
206 data._net_transform = data._net_transform->compose(_aspect_ratio_transform);
210 double elapsed = now - _last_update;
211 if (elapsed < 0.0 || elapsed >= _update_interval) {
212 do_update(current_thread);
223 void FrameRateMeter::
224 do_update(
Thread *current_thread) {
230 if (_show_milliseconds) {
231 value = 1000.0 / value;
232 deviation = 1000.0 / deviation;
235 static const size_t buffer_size = 1024;
236 char buffer[buffer_size];
237 #if defined(WIN32_VC) || defined(WIN64_VC)
239 sprintf(buffer, _text_pattern.c_str(), value, deviation);
241 snprintf(buffer, buffer_size, _text_pattern.c_str(), value, deviation);
243 nassertv(strlen(buffer) < buffer_size);
static ClockObject * get_global_clock()
Returns a pointer to the global ClockObject.
This is the base class for all three-component vectors and points.
double get_average_frame_rate(Thread *current_thread=Thread::get_current_thread()) const
Returns the average frame rate in number of frames per second over the last get_average_frame_rate_in...
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.
void clear_window()
Undoes the effect of a previous call to setup_window().
void set_film_size(PN_stdfloat width)
Sets the horizontal size of the film without changing its shape.
string get_text() const
Returns the current text, as encoded via the current encoding system.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
PandaNode * node() const
Returns the referenced node of the path.
A lightweight class that can be used to automatically start and stop a PStatCollector around a sectio...
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...
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...
An encapsulation of a font; i.e.
void setup_window(GraphicsOutput *window)
Sets up the frame rate meter to create a DisplayRegion to render itself into the indicated window...
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 lightweight class that represents a single element that may be timed and/or counted via stats...
void set_bin(const string &bin_name, int draw_order, int priority=0)
Assigns the geometry at this level and below to the named rendering bin.
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 ...
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.
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
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.
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_two_sided(bool two_sided, int priority=0)
Specifically sets or disables two-sided rendering mode on this particular node.
PN_stdfloat get_line_height() const
Returns the number of units high each line of text is.
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...
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...