2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visual_server_raster.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* 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
|
|
|
/*************************************************************************/
|
2019-01-01 11:53:14 +00:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 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
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "visual_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"
|
|
|
|
#include "core/sort.h"
|
2016-10-03 19:33:42 +00:00
|
|
|
#include "visual_server_canvas.h"
|
|
|
|
#include "visual_server_global.h"
|
2016-10-19 14:14:41 +00:00
|
|
|
#include "visual_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
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
int VisualServerRaster::changes = 0;
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
/* BLACK BARS */
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerRaster::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
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerRaster::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
|
|
|
}
|
|
|
|
|
2017-08-07 21:06:57 +00:00
|
|
|
void VisualServerRaster::_draw_margins() {
|
|
|
|
|
|
|
|
VSG::canvas_render->draw_window_margins(black_margin, black_image);
|
|
|
|
};
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
/* FREE */
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerRaster::free(RID p_rid) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (VSG::storage->free(p_rid))
|
|
|
|
return;
|
|
|
|
if (VSG::canvas->free(p_rid))
|
|
|
|
return;
|
|
|
|
if (VSG::viewport->free(p_rid))
|
|
|
|
return;
|
2016-10-19 14:14:41 +00:00
|
|
|
if (VSG::scene->free(p_rid))
|
|
|
|
return;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EVENT QUEUING */
|
|
|
|
|
2017-06-09 03:23:50 +00:00
|
|
|
void VisualServerRaster::request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) {
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-05-09 06:11:43 +00:00
|
|
|
void VisualServerRaster::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
|
2018-07-06 23:21:13 +00:00
|
|
|
VS::get_singleton()->emit_signal("frame_pre_draw");
|
|
|
|
|
2018-07-16 14:43:26 +00:00
|
|
|
changes = 0;
|
|
|
|
|
2018-05-09 06:11:43 +00:00
|
|
|
VSG::rasterizer->begin_frame(frame_step);
|
2016-12-20 03:21:07 +00:00
|
|
|
|
2016-10-19 14:14:41 +00:00
|
|
|
VSG::scene->update_dirty_instances(); //update scene stuff
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
VSG::viewport->draw_viewports();
|
2016-11-19 16:23:37 +00:00
|
|
|
VSG::scene->render_probes();
|
2017-10-30 20:20:12 +00:00
|
|
|
_draw_margins();
|
2017-10-30 20:33:36 +00:00
|
|
|
VSG::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) {
|
|
|
|
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();
|
|
|
|
}
|
2017-11-14 20:25:42 +00:00
|
|
|
|
2018-07-06 23:21:13 +00:00
|
|
|
VS::get_singleton()->emit_signal("frame_post_draw");
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerRaster::sync() {
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool VisualServerRaster::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
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerRaster::init() {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
VSG::rasterizer->initialize();
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerRaster::finish() {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
|
|
|
if (test_cube.is_valid()) {
|
|
|
|
free(test_cube);
|
|
|
|
}
|
|
|
|
|
|
|
|
VSG::rasterizer->finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* STATUS INFORMATION */
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int VisualServerRaster::get_render_info(RenderInfo p_info) {
|
2016-10-03 19:33:42 +00:00
|
|
|
|
2017-06-11 21:13:04 +00:00
|
|
|
return VSG::storage->get_render_info(p_info);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* TESTING */
|
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
void VisualServerRaster::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) {
|
2017-04-09 23:02:04 +00:00
|
|
|
|
2017-04-09 23:40:48 +00:00
|
|
|
redraw_request();
|
2017-04-09 23:02:04 +00:00
|
|
|
VSG::rasterizer->set_boot_image(p_image, p_color, p_scale);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void VisualServerRaster::set_default_clear_color(const Color &p_color) {
|
2018-07-29 18:09:42 +00:00
|
|
|
VSG::viewport->set_default_clear_color(p_color);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualServerRaster::has_feature(Features p_feature) const {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID VisualServerRaster::get_test_cube() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool VisualServerRaster::has_os_feature(const String &p_feature) const {
|
2017-02-06 03:38:39 +00:00
|
|
|
|
|
|
|
return VSG::storage->has_os_feature(p_feature);
|
|
|
|
}
|
|
|
|
|
2017-06-11 18:52:03 +00:00
|
|
|
void VisualServerRaster::set_debug_generate_wireframes(bool p_generate) {
|
|
|
|
|
|
|
|
VSG::storage->set_debug_generate_wireframes(p_generate);
|
|
|
|
}
|
|
|
|
|
2017-12-16 20:09:25 +00:00
|
|
|
void VisualServerRaster::call_set_use_vsync(bool p_enable) {
|
|
|
|
OS::get_singleton()->_set_use_vsync(p_enable);
|
|
|
|
}
|
|
|
|
|
2018-09-28 23:32:40 +00:00
|
|
|
bool VisualServerRaster::is_low_end() const {
|
|
|
|
return VSG::rasterizer->is_low_end();
|
|
|
|
}
|
2016-10-03 19:33:42 +00:00
|
|
|
VisualServerRaster::VisualServerRaster() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VSG::canvas = memnew(VisualServerCanvas);
|
|
|
|
VSG::viewport = memnew(VisualServerViewport);
|
|
|
|
VSG::scene = memnew(VisualServerScene);
|
2016-10-03 19:33:42 +00:00
|
|
|
VSG::rasterizer = Rasterizer::create();
|
2017-03-05 15:44:50 +00:00
|
|
|
VSG::storage = VSG::rasterizer->get_storage();
|
|
|
|
VSG::canvas_render = VSG::rasterizer->get_canvas();
|
|
|
|
VSG::scene_render = VSG::rasterizer->get_scene();
|
2017-08-07 21:06:57 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
black_margin[i] = 0;
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualServerRaster::~VisualServerRaster() {
|
|
|
|
|
|
|
|
memdelete(VSG::canvas);
|
|
|
|
memdelete(VSG::viewport);
|
|
|
|
memdelete(VSG::rasterizer);
|
2018-03-13 01:40:47 +00:00
|
|
|
memdelete(VSG::scene);
|
2016-10-03 19:33:42 +00:00
|
|
|
}
|