1
+ /**
2
+ * This renderer module provides a series of statistical information
3
+ * about the GPU memory and the rendering process. Useful for debugging
4
+ * and monitoring.
5
+ */
1
6
class Info {
2
7
8
+ /**
9
+ * Constructs a new info component.
10
+ */
3
11
constructor ( ) {
4
12
13
+ /**
14
+ * Whether frame related metrics should automatically
15
+ * be resetted or not. This property should be set to `false`
16
+ * by apps which manage their own animation loop. They must
17
+ * then call `renderer.info.reset()` once per frame manually.
18
+ *
19
+ * @type {Boolean }
20
+ * @default true
21
+ */
5
22
this . autoReset = true ;
6
23
24
+ /**
25
+ * The current frame ID. This ID is managed
26
+ * by `NodeFrame`.
27
+ *
28
+ * @type {Number }
29
+ * @readonly
30
+ * @default 0
31
+ */
7
32
this . frame = 0 ;
33
+
34
+ /**
35
+ * The number of render calls since the
36
+ * app has been started.
37
+ *
38
+ * @type {Number }
39
+ * @readonly
40
+ * @default 0
41
+ */
8
42
this . calls = 0 ;
9
43
44
+ /**
45
+ * Render related metrics.
46
+ *
47
+ * @type {Object }
48
+ * @readonly
49
+ * @property {Number } calls - The number of render calls since the app has been started.
50
+ * @property {Number } frameCalls - The number of render calls of the current frame.
51
+ * @property {Number } drawCalls - The number of draw calls of the current frame.
52
+ * @property {Number } triangles - The number of rendered triangle primitives of the current frame.
53
+ * @property {Number } points - The number of rendered point primitives of the current frame.
54
+ * @property {Number } lines - The number of rendered line primitives of the current frame.
55
+ * @property {Number } previousFrameCalls - The number of render calls of the previous frame.
56
+ * @property {Number } timestamp - The timestamp of the frame when using `renderer.renderAsync()`.
57
+ * @property {Number } timestampCalls - The number of render calls using `renderer.renderAsync()`.
58
+ */
10
59
this . render = {
11
60
calls : 0 ,
12
61
frameCalls : 0 ,
@@ -19,6 +68,17 @@ class Info {
19
68
timestampCalls : 0
20
69
} ;
21
70
71
+ /**
72
+ * Compute related metrics.
73
+ *
74
+ * @type {Object }
75
+ * @readonly
76
+ * @property {Number } calls - The number of compute calls since the app has been started.
77
+ * @property {Number } frameCalls - The number of compute calls of the current frame.
78
+ * @property {Number } previousFrameCalls - The number of compute calls of the previous frame.
79
+ * @property {Number } timestamp - The timestamp of the frame when using `renderer.computeAsync()`.
80
+ * @property {Number } timestampCalls - The number of render calls using `renderer.computeAsync()`.
81
+ */
22
82
this . compute = {
23
83
calls : 0 ,
24
84
frameCalls : 0 ,
@@ -27,13 +87,28 @@ class Info {
27
87
timestampCalls : 0
28
88
} ;
29
89
90
+ /**
91
+ * Memory related metrics.
92
+ *
93
+ * @type {Object }
94
+ * @readonly
95
+ * @property {Number } geometries - The number of active geometries.
96
+ * @property {Number } frameCalls - The number of active textures.
97
+ */
30
98
this . memory = {
31
99
geometries : 0 ,
32
100
textures : 0
33
101
} ;
34
102
35
103
}
36
104
105
+ /**
106
+ * This method should be executed per draw call and updates the corresponding metrics.
107
+ *
108
+ * @param {Object3D } object - The 3D object that is going to be rendered.
109
+ * @param {Number } count - The vertex or index count.
110
+ * @param {Number } instanceCount - The instance count.
111
+ */
37
112
update ( object , count , instanceCount ) {
38
113
39
114
this . render . drawCalls ++ ;
@@ -62,6 +137,12 @@ class Info {
62
137
63
138
}
64
139
140
+ /**
141
+ * Used by async render methods to updated timestamp metrics.
142
+ *
143
+ * @param {('render'|'compute') } type - The type of render call.
144
+ * @param {Number } time - The duration of the compute/render call in milliseconds.
145
+ */
65
146
updateTimestamp ( type , time ) {
66
147
67
148
if ( this [ type ] . timestampCalls === 0 ) {
@@ -85,6 +166,9 @@ class Info {
85
166
86
167
}
87
168
169
+ /**
170
+ * Resets frame related metrics.
171
+ */
88
172
reset ( ) {
89
173
90
174
const previousRenderFrameCalls = this . render . frameCalls ;
@@ -105,6 +189,9 @@ class Info {
105
189
106
190
}
107
191
192
+ /**
193
+ * Performs a complete reset of the object.
194
+ */
108
195
dispose ( ) {
109
196
110
197
this . reset ( ) ;
0 commit comments