Panda3D
Loading...
Searching...
No Matches
frameRateMeter.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file frameRateMeter.h
10 * @author drose
11 * @date 2003-12-23
12 */
13
14#ifndef FRAMERATEMETER_H
15#define FRAMERATEMETER_H
16
17#include "pandabase.h"
18#include "textNode.h"
19#include "nodePath.h"
20#include "graphicsOutput.h"
21#include "displayRegion.h"
22#include "pointerTo.h"
23#include "pStatCollector.h"
24
25class GraphicsChannel;
26class ClockObject;
27
28/**
29 * This is a special TextNode that automatically updates itself with the
30 * current frame rate. It can be placed anywhere in the world where you'd
31 * like to see the frame rate.
32 *
33 * It also has a special mode in which it may be attached directly to a
34 * channel or window. If this is done, it creates a DisplayRegion for itself
35 * and renders itself in the upper-right-hand corner.
36 */
37class EXPCL_PANDA_GRUTIL FrameRateMeter : public TextNode {
38PUBLISHED:
39 explicit FrameRateMeter(const std::string &name);
40 virtual ~FrameRateMeter();
41
42 void setup_window(GraphicsOutput *window);
43 void clear_window();
44
45 INLINE GraphicsOutput *get_window() const;
46 INLINE DisplayRegion *get_display_region() const;
47
48 INLINE void set_update_interval(double update_interval);
49 INLINE double get_update_interval() const;
50
51 INLINE void set_text_pattern(const std::string &text_pattern);
52 INLINE const std::string &get_text_pattern() const;
53
54 INLINE void set_clock_object(ClockObject *clock_object);
55 INLINE ClockObject *get_clock_object() const;
56
57 INLINE void update();
58
59protected:
60 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
61
62private:
63 void do_update(Thread *current_thread);
64
65private:
66 PT(GraphicsOutput) _window;
67 PT(DisplayRegion) _display_region;
68 NodePath _root;
69
70 bool _show_milliseconds;
71 double _update_interval;
72 double _last_update;
73 std::string _text_pattern;
74 ClockObject *_clock_object;
75
76 PN_stdfloat _last_aspect_ratio;
77 CPT(TransformState) _aspect_ratio_transform;
78
79 static PStatCollector _show_fps_pcollector;
80
81public:
82 static TypeHandle get_class_type() {
83 return _type_handle;
84 }
85 static void init_type() {
86 TextNode::init_type();
87 register_type(_type_handle, "FrameRateMeter",
88 TextNode::get_class_type());
89 }
90 virtual TypeHandle get_type() const {
91 return get_class_type();
92 }
93 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
94
95private:
96 static TypeHandle _type_handle;
97};
98
99#include "frameRateMeter.I"
100
101#endif
A ClockObject keeps track of elapsed real time and discrete time.
Definition clockObject.h:58
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
A rectangular subregion within a window for rendering into.
void set_clock_object(ClockObject *clock_object)
Sets the clock that is used to determine the frame rate.
DisplayRegion * get_display_region() const
Returns the DisplayRegion that the meter has created to render itself into the window to setup_window...
const std::string & get_text_pattern() const
Returns the sprintf() pattern that is used to format the text.
double get_update_interval() const
Returns the number of seconds that will elapse between updates to the frame rate indication.
void set_text_pattern(const std::string &text_pattern)
Sets the sprintf() pattern that is used to format the text.
void set_update_interval(double update_interval)
Specifies the number of seconds that should elapse between updates to the frame rate indication.
ClockObject * get_clock_object() const
Returns the clock that is used to determine the frame rate.
void setup_window(GraphicsOutput *window)
Sets up the frame rate meter to create a DisplayRegion to render itself into the indicated window.
GraphicsOutput * get_window() const
Returns the GraphicsOutput that was passed to setup_window(), or NULL if setup_window() has not been ...
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 lightweight class that represents a single element that may be timed and/or counted via stats.
void update()
Can be called after the TextNode has been fully configured, to force the node to recompute its text i...
Definition textNode.I:1166
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.
Definition thread.h:46
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
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.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.