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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
/*************************************************************************/
/* visual_server_raster.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* 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. */
/*************************************************************************/
#include "visual_server_raster.h"
#include "default_mouse_cursor.xpm"
#include "io/marshalls.h"
#include "os/os.h"
#include "project_settings.h"
#include "sort.h"
#include "visual_server_canvas.h"
#include "visual_server_global.h"
#include "visual_server_scene.h"
// careful, these may run in different threads than the visual server
int VisualServerRaster::changes = 0;
/* BLACK BARS */
void VisualServerRaster::black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom) {
black_margin[MARGIN_LEFT] = p_left;
black_margin[MARGIN_TOP] = p_top;
black_margin[MARGIN_RIGHT] = p_right;
black_margin[MARGIN_BOTTOM] = p_bottom;
}
void VisualServerRaster::black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom) {
black_image[MARGIN_LEFT] = p_left;
black_image[MARGIN_TOP] = p_top;
black_image[MARGIN_RIGHT] = p_right;
black_image[MARGIN_BOTTOM] = p_bottom;
}
void VisualServerRaster::_draw_margins() {
VSG::canvas_render->draw_window_margins(black_margin, black_image);
};
/* FREE */
void VisualServerRaster::free(RID p_rid) {
if (VSG::storage->free(p_rid))
return;
if (VSG::canvas->free(p_rid))
return;
if (VSG::viewport->free(p_rid))
return;
if (VSG::scene->free(p_rid))
return;
}
/* EVENT QUEUING */
void VisualServerRaster::request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) {
ERR_FAIL_NULL(p_where);
FrameDrawnCallbacks fdc;
fdc.object = p_where->get_instance_id();
fdc.method = p_method;
fdc.param = p_userdata;
frame_drawn_callbacks.push_back(fdc);
}
void VisualServerRaster::draw(bool p_swap_buffers) {
changes = 0;
VS::get_singleton()->emit_signal("frame_pre_draw");
VSG::rasterizer->begin_frame();
VSG::scene->update_dirty_instances(); //update scene stuff
VSG::viewport->draw_viewports();
VSG::scene->render_probes();
_draw_margins();
VSG::rasterizer->end_frame(p_swap_buffers);
while (frame_drawn_callbacks.front()) {
Object *obj = ObjectDB::get_instance(frame_drawn_callbacks.front()->get().object);
if (obj) {
Variant::CallError ce;
const Variant *v = &frame_drawn_callbacks.front()->get().param;
obj->call(frame_drawn_callbacks.front()->get().method, &v, 1, ce);
if (ce.error != Variant::CallError::CALL_OK) {
String err = Variant::get_call_error_text(obj, frame_drawn_callbacks.front()->get().method, &v, 1, ce);
ERR_PRINTS("Error calling frame drawn function: " + err);
}
}
frame_drawn_callbacks.pop_front();
}
VS::get_singleton()->emit_signal("frame_post_draw");
}
void VisualServerRaster::sync() {
}
bool VisualServerRaster::has_changed() const {
return changes > 0;
}
void VisualServerRaster::init() {
VSG::rasterizer->initialize();
}
void VisualServerRaster::finish() {
if (test_cube.is_valid()) {
free(test_cube);
}
VSG::rasterizer->finalize();
}
/* STATUS INFORMATION */
int VisualServerRaster::get_render_info(RenderInfo p_info) {
return VSG::storage->get_render_info(p_info);
}
/* TESTING */
void VisualServerRaster::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) {
redraw_request();
VSG::rasterizer->set_boot_image(p_image, p_color, p_scale);
}
void VisualServerRaster::set_default_clear_color(const Color &p_color) {
}
bool VisualServerRaster::has_feature(Features p_feature) const {
return false;
}
RID VisualServerRaster::get_test_cube() {
if (!test_cube.is_valid()) {
test_cube = _make_test_cube();
}
return test_cube;
}
bool VisualServerRaster::has_os_feature(const String &p_feature) const {
return VSG::storage->has_os_feature(p_feature);
}
void VisualServerRaster::set_debug_generate_wireframes(bool p_generate) {
VSG::storage->set_debug_generate_wireframes(p_generate);
}
void VisualServerRaster::call_set_use_vsync(bool p_enable) {
OS::get_singleton()->_set_use_vsync(p_enable);
}
VisualServerRaster::VisualServerRaster() {
VSG::canvas = memnew(VisualServerCanvas);
VSG::viewport = memnew(VisualServerViewport);
VSG::scene = memnew(VisualServerScene);
VSG::rasterizer = Rasterizer::create();
VSG::storage = VSG::rasterizer->get_storage();
VSG::canvas_render = VSG::rasterizer->get_canvas();
VSG::scene_render = VSG::rasterizer->get_scene();
for (int i = 0; i < 4; i++)
black_margin[i] = 0;
}
VisualServerRaster::~VisualServerRaster() {
memdelete(VSG::canvas);
memdelete(VSG::viewport);
memdelete(VSG::rasterizer);
memdelete(VSG::scene);
}
|