forked from godotengine/godot
/
benchmark.h
176 lines (152 loc) · 5.05 KB
/
benchmark.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**************************************************************************/
/* benchmark.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef BENCHMARK_H
#define BENCHMARK_H
#include "core/map.h"
#include "core/method_bind.h"
#include "main/performance.h"
#include "scene/main/node.h"
#include "scene/resources/font.h"
#include "scene/resources/mesh.h"
class Label;
class GdHistoryPlot;
class Benchmark : public Node {
GDCLASS(Benchmark, Node);
bool active;
Ref<BitmapFont> screen_font;
Ref<SpatialMaterial> model_mat;
int num_objects;
int curr_model;
real_t glob_yaw;
real_t viewport_scale;
public:
// Available models
typedef enum {
FIRST_MODEL_TYPE = 0,
CUBE_MODEL = 0,
FROG_MODEL,
KID_MODEL,
TREX_MODEL,
ROBOT_MODEL,
NUM_MODEL_TYPES
} ModelType;
// Render and display options
typedef enum {
OPTION_CULLING,
OPTION_DEPTHTEST,
OPTION_FXAA,
OPTION_TEXTURING,
OPTION_LINEAR_FILTERING,
OPTION_MIPMAPING,
OPTION_CAMERA_LOOKAWAY,
OPTION_SKY,
OPTION_STATS,
NUM_OPTIONS,
} RenderOptions;
private:
// Postprocess effects
typedef enum {
FX_GRAYSCALE = 0,
FX_POSTERIZATION,
FX_DREAM_VISION,
FX_PIXELIZER,
FX_CROSS_HATCHING,
FX_CROSS_STITCHING,
FX_PREDATOR_VIEW,
FX_SCANLINES,
FX_FISHEYE,
FX_SOBEL,
FX_BLOOM,
FX_BLUR,
NUM_FX_TYPES,
FX_NONE = NUM_FX_TYPES,
} PostproShader;
// Shaders info.
typedef enum {
FIRST_SHADER_TYPE = 0,
PHONG = 0,
GOURAUD,
UNTEXTURED_PHONG,
UNTEXTURED_GOURAUD,
FLAT,
NUM_SHADER_TYPES,
} ShaderType;
bool opts[NUM_OPTIONS] = { false };
real_t camera_distance, camera_yaw;
// Models info
struct ModelInfo {
String name;
Ref<Mesh> mesh;
struct {
const uint8_t *data;
size_t size;
} tex_data; // for texture rebuilding
Ref<Texture> tex;
uint32_t tris;
};
ModelInfo models[NUM_MODEL_TYPES];
// instane & model assign
Vector<std::pair<RID, int>> instances;
RID _create_instance_from_model(const ModelInfo &info);
int _get_texture_flags();
ModelInfo _make_model_from_data(const uint8_t *p_data, const uint8_t *p_tex_img, size_t p_tex_img_size, const String &p_name);
String _get_stats();
void _load_resources();
void _update_viewport();
void _check_instances();
void _update(float p_delta);
void _finalize();
Ref<Environment> _sky;
Label *_stats_label;
Size2 _stats_text_size;
Map<Performance::Monitor, GdHistoryPlot *> _monitors;
int plot_buf_index, plot_hist_size;
bool _dirty;
protected:
void _notification(int p_notification);
void _input(const Ref<InputEvent> &p_event);
static void _bind_methods();
public:
void set_active(bool p_state);
bool is_active() const;
void set_autostart(bool p_state);
bool is_autostart() const;
void set_num_objects(int p_num);
int get_num_objects() const;
void set_display_model(int p_model);
int get_display_model() const;
void set_display_option(int p_opt, bool p_state);
bool get_display_option(int p_opt) const;
Benchmark();
~Benchmark();
};
VARIANT_ENUM_CAST(Benchmark::ModelType);
VARIANT_ENUM_CAST(Benchmark::RenderOptions);
#endif // BENCHMARK_H