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
25 class GraphicsChannel;
26 class 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 */
37 class 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
59 protected:
60 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
61
62 private:
63 void do_update(Thread *current_thread);
64
65 private:
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
81 public:
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
95 private:
96 static TypeHandle _type_handle;
97};
98
99#include "frameRateMeter.I"
100
101#endif
ClockObject
A ClockObject keeps track of elapsed real time and discrete time.
Definition clockObject.h:58
CullTraverser
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition cullTraverser.h:45
DisplayRegion
A rectangular subregion within a window for rendering into.
Definition displayRegion.h:57
FrameRateMeter::set_clock_object
void set_clock_object(ClockObject *clock_object)
Sets the clock that is used to determine the frame rate.
Definition frameRateMeter.I:78
FrameRateMeter::get_display_region
DisplayRegion * get_display_region() const
Returns the DisplayRegion that the meter has created to render itself into the window to setup_window...
Definition frameRateMeter.I:29
FrameRateMeter::get_text_pattern
const std::string & get_text_pattern() const
Returns the sprintf() pattern that is used to format the text.
Definition frameRateMeter.I:69
FrameRateMeter::get_update_interval
double get_update_interval() const
Returns the number of seconds that will elapse between updates to the frame rate indication.
Definition frameRateMeter.I:49
FrameRateMeter::set_text_pattern
void set_text_pattern(const std::string &text_pattern)
Sets the sprintf() pattern that is used to format the text.
Definition frameRateMeter.I:59
FrameRateMeter::set_update_interval
void set_update_interval(double update_interval)
Specifies the number of seconds that should elapse between updates to the frame rate indication.
Definition frameRateMeter.I:40
FrameRateMeter::get_clock_object
ClockObject * get_clock_object() const
Returns the clock that is used to determine the frame rate.
Definition frameRateMeter.I:87
FrameRateMeter::setup_window
void setup_window(GraphicsOutput *window)
Sets up the frame rate meter to create a DisplayRegion to render itself into the indicated window.
Definition frameRateMeter.cxx:88
FrameRateMeter::get_window
GraphicsOutput * get_window() const
Returns the GraphicsOutput that was passed to setup_window(), or NULL if setup_window() has not been ...
Definition frameRateMeter.I:19
FrameRateMeter::clear_window
void clear_window()
Undoes the effect of a previous call to setup_window().
Definition frameRateMeter.cxx:136
GraphicsOutput
This is a base class for the various different classes that represent the result of a frame of render...
Definition graphicsOutput.h:63
PStatCollector
A lightweight class that represents a single element that may be timed and/or counted via stats.
Definition pStatCollector.h:43
TextNode::update
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
TextNode::cull_callback
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
Thread
A thread; that is, a lightweight process.
Definition thread.h:46
TransformState
Indicates a coordinate-system transform on vertices.
Definition transformState.h:54
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
displayRegion.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
frameRateMeter.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
graphicsOutput.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
nodePath.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pStatCollector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22
textNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.