2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-03-28 12:19:05 +00:00
|
|
|
/* rendering_server_raster.cpp */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "rendering_server_raster.h"
|
2017-08-27 19:07:15 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/io/marshalls.h"
|
|
|
|
#include "core/os/os.h"
|
|
|
|
#include "core/project_settings.h"
|
2019-02-12 12:30:56 +00:00
|
|
|
#include "core/sort_array.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "rendering_server_canvas.h"
|
|
|
|
#include "rendering_server_globals.h"
|
|
|
|
#include "rendering_server_scene.h"
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// careful, these may run in different threads than the visual server
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
int RenderingServerRaster::changes = 0;
|
2017-04-07 02:36:37 +00:00
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
/* BLACK BARS */
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::black_bars_set_margins(int p_left, int p_top, int p_right, int p_bottom) {
|
2017-08-07 21:06:57 +00:00
|
|
|
|
|
|
|
black_margin[MARGIN_LEFT] = p_left;
|
|
|
|
black_margin[MARGIN_TOP] = p_top;
|
|
|
|
black_margin[MARGIN_RIGHT] = p_right;
|
|
|
|
black_margin[MARGIN_BOTTOM] = p_bottom;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-08-07 21:06:57 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom) {
|
2017-08-07 21:06:57 +00:00
|
|
|
|
|
|
|
black_image[MARGIN_LEFT] = p_left;
|
|
|
|
black_image[MARGIN_TOP] = p_top;
|
|
|
|
black_image[MARGIN_RIGHT] = p_right;
|
|
|
|
black_image[MARGIN_BOTTOM] = p_bottom;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::_draw_margins() {
|
2017-08-07 21:06:57 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::canvas_render->draw_window_margins(black_margin, black_image);
|
2017-08-07 21:06:57 +00:00
|
|
|
};
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
/* FREE */
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::free(RID p_rid) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
if (RSG::storage->free(p_rid))
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
2020-03-27 18:21:27 +00:00
|
|
|
if (RSG::canvas->free(p_rid))
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
2020-03-27 18:21:27 +00:00
|
|
|
if (RSG::viewport->free(p_rid))
|
2016-10-03 19:33:42 +00:00
|
|
|
return;
|
2020-03-27 18:21:27 +00:00
|
|
|
if (RSG::scene->free(p_rid))
|
2016-10-19 14:14:41 +00:00
|
|
|
return;
|
2020-03-27 18:21:27 +00:00
|
|
|
if (RSG::scene_render->free(p_rid))
|
2019-07-02 14:23:54 +00:00
|
|
|
return;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EVENT QUEUING */
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) {
|
2017-06-09 03:23:50 +00:00
|
|
|
|
|
|
|
ERR_FAIL_NULL(p_where);
|
|
|
|
FrameDrawnCallbacks fdc;
|
2017-08-07 10:17:31 +00:00
|
|
|
fdc.object = p_where->get_instance_id();
|
2017-06-09 03:23:50 +00:00
|
|
|
fdc.method = p_method;
|
|
|
|
fdc.param = p_userdata;
|
|
|
|
|
|
|
|
frame_drawn_callbacks.push_back(fdc);
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::draw(bool p_swap_buffers, double frame_step) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2018-07-16 14:43:26 +00:00
|
|
|
//needs to be done before changes is reset to 0, to not force the editor to redraw
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->emit_signal("frame_pre_draw");
|
2018-07-06 23:21:13 +00:00
|
|
|
|
2018-07-16 14:43:26 +00:00
|
|
|
changes = 0;
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::rasterizer->begin_frame(frame_step);
|
2016-12-20 03:21:07 +00:00
|
|
|
|
2019-10-03 23:15:38 +00:00
|
|
|
TIMESTAMP_BEGIN()
|
2019-09-20 20:58:06 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::scene_render->update(); //update scenes stuff before updating instances
|
2016-10-19 14:14:41 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::scene->update_dirty_instances(); //update scene stuff
|
2019-08-26 20:43:58 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::scene->render_probes();
|
|
|
|
RSG::viewport->draw_viewports();
|
|
|
|
RSG::canvas_render->update();
|
2019-06-16 02:45:24 +00:00
|
|
|
|
2017-10-30 20:20:12 +00:00
|
|
|
_draw_margins();
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::rasterizer->end_frame(p_swap_buffers);
|
2017-06-09 03:23:50 +00:00
|
|
|
|
|
|
|
while (frame_drawn_callbacks.front()) {
|
|
|
|
|
|
|
|
Object *obj = ObjectDB::get_instance(frame_drawn_callbacks.front()->get().object);
|
|
|
|
if (obj) {
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError ce;
|
2017-06-09 03:23:50 +00:00
|
|
|
const Variant *v = &frame_drawn_callbacks.front()->get().param;
|
|
|
|
obj->call(frame_drawn_callbacks.front()->get().method, &v, 1, ce);
|
2020-02-19 19:27:19 +00:00
|
|
|
if (ce.error != Callable::CallError::CALL_OK) {
|
2017-06-09 03:23:50 +00:00
|
|
|
String err = Variant::get_call_error_text(obj, frame_drawn_callbacks.front()->get().method, &v, 1, ce);
|
2019-11-06 16:03:04 +00:00
|
|
|
ERR_PRINT("Error calling frame drawn function: " + err);
|
2017-06-09 03:23:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_drawn_callbacks.pop_front();
|
|
|
|
}
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->emit_signal("frame_post_draw");
|
2019-09-20 20:58:06 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
if (RSG::storage->get_captured_timestamps_count()) {
|
2019-09-20 20:58:06 +00:00
|
|
|
Vector<FrameProfileArea> new_profile;
|
2020-04-10 17:18:42 +00:00
|
|
|
if (RSG::storage->capturing_timestamps) {
|
|
|
|
new_profile.resize(RSG::storage->get_captured_timestamps_count());
|
|
|
|
}
|
2019-09-20 20:58:06 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
uint64_t base_cpu = RSG::storage->get_captured_timestamp_cpu_time(0);
|
|
|
|
uint64_t base_gpu = RSG::storage->get_captured_timestamp_gpu_time(0);
|
|
|
|
for (uint32_t i = 0; i < RSG::storage->get_captured_timestamps_count(); i++) {
|
2020-04-10 17:18:42 +00:00
|
|
|
uint64_t time_cpu = RSG::storage->get_captured_timestamp_cpu_time(i);
|
|
|
|
uint64_t time_gpu = RSG::storage->get_captured_timestamp_gpu_time(i);
|
|
|
|
|
|
|
|
String name = RSG::storage->get_captured_timestamp_name(i);
|
|
|
|
|
|
|
|
if (name.begins_with("vp_")) {
|
|
|
|
RSG::viewport->handle_timestamp(name, time_cpu, time_gpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RSG::storage->capturing_timestamps) {
|
|
|
|
new_profile.write[i].gpu_msec = float((time_gpu - base_gpu) / 1000) / 1000.0;
|
|
|
|
new_profile.write[i].cpu_msec = float(time_cpu - base_cpu) / 1000.0;
|
|
|
|
new_profile.write[i].name = RSG::storage->get_captured_timestamp_name(i);
|
|
|
|
}
|
2019-09-20 20:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frame_profile = new_profile;
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
frame_profile_frame = RSG::storage->get_captured_timestamps_frame();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::sync() {
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2020-03-27 18:21:27 +00:00
|
|
|
bool RenderingServerRaster::has_changed() const {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
return changes > 0;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::init() {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::rasterizer->initialize();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::finish() {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (test_cube.is_valid()) {
|
|
|
|
free(test_cube);
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::rasterizer->finalize();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* STATUS INFORMATION */
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
int RenderingServerRaster::get_render_info(RenderInfo p_info) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
return RSG::storage->get_render_info(p_info);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
String RenderingServerRaster::get_video_adapter_name() const {
|
2019-09-13 18:08:05 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
return RSG::storage->get_video_adapter_name();
|
2019-09-13 18:08:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
String RenderingServerRaster::get_video_adapter_vendor() const {
|
2019-09-13 18:08:05 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
return RSG::storage->get_video_adapter_vendor();
|
2019-09-13 18:08:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::set_frame_profiling_enabled(bool p_enable) {
|
|
|
|
RSG::storage->capturing_timestamps = p_enable;
|
2019-09-20 20:58:06 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
uint64_t RenderingServerRaster::get_frame_profile_frame() {
|
2019-09-20 20:58:06 +00:00
|
|
|
return frame_profile_frame;
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
Vector<RenderingServer::FrameProfileArea> RenderingServerRaster::get_frame_profile() {
|
2019-09-20 20:58:06 +00:00
|
|
|
return frame_profile;
|
|
|
|
}
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
/* TESTING */
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
|
2017-04-09 23:02:04 +00:00
|
|
|
|
2017-04-09 23:40:48 +00:00
|
|
|
redraw_request();
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::rasterizer->set_boot_image(p_image, p_color, p_scale, p_use_filter);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::set_default_clear_color(const Color &p_color) {
|
|
|
|
RSG::viewport->set_default_clear_color(p_color);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
bool RenderingServerRaster::has_feature(Features p_feature) const {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RID RenderingServerRaster::get_test_cube() {
|
2016-10-03 19:33:42 +00:00
|
|
|
if (!test_cube.is_valid()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
test_cube = _make_test_cube();
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
return test_cube;
|
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
bool RenderingServerRaster::has_os_feature(const String &p_feature) const {
|
2017-02-06 03:38:39 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
return RSG::storage->has_os_feature(p_feature);
|
2017-02-06 03:38:39 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::set_debug_generate_wireframes(bool p_generate) {
|
2017-06-11 18:52:03 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::storage->set_debug_generate_wireframes(p_generate);
|
2017-06-11 18:52:03 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void RenderingServerRaster::call_set_use_vsync(bool p_enable) {
|
2020-03-03 13:36:29 +00:00
|
|
|
DisplayServer::get_singleton()->_set_use_vsync(p_enable);
|
2017-12-16 20:09:25 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
bool RenderingServerRaster::is_low_end() const {
|
2019-12-12 16:22:30 +00:00
|
|
|
// FIXME: Commented out when rebasing vulkan branch on master,
|
|
|
|
// causes a crash, it seems rasterizer is not initialized yet the
|
|
|
|
// first time it's called.
|
2020-03-27 18:21:27 +00:00
|
|
|
//return RSG::rasterizer->is_low_end();
|
2019-12-12 16:22:30 +00:00
|
|
|
return false;
|
2018-09-28 23:32:40 +00:00
|
|
|
}
|
2020-03-27 18:21:27 +00:00
|
|
|
RenderingServerRaster::RenderingServerRaster() {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::canvas = memnew(RenderingServerCanvas);
|
|
|
|
RSG::viewport = memnew(RenderingServerViewport);
|
|
|
|
RSG::scene = memnew(RenderingServerScene);
|
|
|
|
RSG::rasterizer = Rasterizer::create();
|
|
|
|
RSG::storage = RSG::rasterizer->get_storage();
|
|
|
|
RSG::canvas_render = RSG::rasterizer->get_canvas();
|
|
|
|
RSG::scene_render = RSG::rasterizer->get_scene();
|
2017-08-07 21:06:57 +00:00
|
|
|
|
2019-09-20 20:58:06 +00:00
|
|
|
frame_profile_frame = 0;
|
|
|
|
|
2019-05-28 17:12:19 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-08-07 21:06:57 +00:00
|
|
|
black_margin[i] = 0;
|
2019-05-28 17:12:19 +00:00
|
|
|
black_image[i] = RID();
|
|
|
|
}
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RenderingServerRaster::~RenderingServerRaster() {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
memdelete(RSG::canvas);
|
|
|
|
memdelete(RSG::viewport);
|
|
|
|
memdelete(RSG::rasterizer);
|
|
|
|
memdelete(RSG::scene);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|