diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-06-09 00:23:50 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-06-09 00:24:18 -0300 |
commit | 612ab8fcdb94bf0cd9d7b4a3006b4e4f76c9a13b (patch) | |
tree | 1e7b4fdb8154098319b0c44ee0289288610a77c3 /servers | |
parent | 01ed55987c4c044191e50ecc94c277b97962ffc7 (diff) |
-Restored multithread capability to VisualServer
-Restored resource previews!
Diffstat (limited to 'servers')
-rw-r--r-- | servers/server_wrap_mt_common.h | 21 | ||||
-rw-r--r-- | servers/visual/rasterizer.h | 1 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.cpp | 29 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.h | 14 | ||||
-rw-r--r-- | servers/visual/visual_server_viewport.cpp | 43 | ||||
-rw-r--r-- | servers/visual/visual_server_viewport.h | 3 | ||||
-rw-r--r-- | servers/visual/visual_server_wrap_mt.cpp | 193 | ||||
-rw-r--r-- | servers/visual/visual_server_wrap_mt.h | 571 | ||||
-rw-r--r-- | servers/visual_server.h | 12 |
9 files changed, 881 insertions, 6 deletions
diff --git a/servers/server_wrap_mt_common.h b/servers/server_wrap_mt_common.h index f6b78e8f40..d434a6622e 100644 --- a/servers/server_wrap_mt_common.h +++ b/servers/server_wrap_mt_common.h @@ -41,8 +41,9 @@ } #define FUNCRID(m_type) \ + List<RID> m_type##_id_pool; \ int m_type##allocn() { \ - for (int i = 0; i < m_type##_pool_max_size; i++) { \ + for (int i = 0; i < pool_max_size; i++) { \ m_type##_id_pool.push_back(server_name->m_type##_create()); \ } \ return 0; \ @@ -747,3 +748,21 @@ server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8); \ } \ } + +#define FUNC9(m_type, m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8, m_arg9) \ + virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8, m_arg9 p9) { \ + if (Thread::get_caller_ID() != server_thread) { \ + command_queue.push(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, p7, p8, p9); \ + } else { \ + server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8, p9); \ + } \ + } + +#define FUNC10(m_type, m_arg1, m_arg2, m_arg3, m_arg4, m_arg5, m_arg6, m_arg7, m_arg8, m_arg9, m_arg10) \ + virtual void m_type(m_arg1 p1, m_arg2 p2, m_arg3 p3, m_arg4 p4, m_arg5 p5, m_arg6 p6, m_arg7 p7, m_arg8 p8, m_arg9 p9, m_arg10 p10) { \ + if (Thread::get_caller_ID() != server_thread) { \ + command_queue.push(server_name, &ServerName::m_type, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ + } else { \ + server_name->m_type(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); \ + } \ + } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 9dfb0b2e71..d7c56505be 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -468,6 +468,7 @@ public: enum RenderTargetFlags { RENDER_TARGET_VFLIP, RENDER_TARGET_TRANSPARENT, + RENDER_TARGET_NO_3D_EFFECTS, RENDER_TARGET_NO_3D, RENDER_TARGET_NO_SAMPLING, RENDER_TARGET_HDR, diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 2fdff29f0a..c4f22fdc0b 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -74,6 +74,19 @@ void VisualServerRaster::free(RID p_rid) { /* 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); + + print_line("added callback to draw"); +} + void VisualServerRaster::draw() { /* @@ -92,6 +105,22 @@ void VisualServerRaster::draw() { //_draw_cursors_and_margins(); VSG::rasterizer->end_frame(); //draw_extra_frame=VS:rasterizer->needs_to_draw_next_frame(); + + 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(); + } } void VisualServerRaster::sync() { } diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 8c311300ad..f37c4735c7 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -61,6 +61,15 @@ class VisualServerRaster : public VisualServer { bool draw_extra_frame; RID test_cube; + struct FrameDrawnCallbacks { + + ObjectID object; + StringName method; + Variant param; + }; + + List<FrameDrawnCallbacks> frame_drawn_callbacks; + #if 0 struct Room { @@ -632,7 +641,6 @@ public: BIND1RC(uint32_t, texture_get_width, RID) BIND1RC(uint32_t, texture_get_height, RID) BIND3(texture_set_size_override, RID, int, int) - BIND2RC(RID, texture_create_radiance_cubemap, RID, int) BIND3(texture_set_detect_3d_callback, RID, TextureDetectCallback, void *) BIND3(texture_set_detect_srgb_callback, RID, TextureDetectCallback, void *) @@ -922,6 +930,7 @@ public: BIND3(viewport_set_shadow_atlas_quadrant_subdivision, RID, int, int) BIND2(viewport_set_msaa, RID, ViewportMSAA) BIND2(viewport_set_hdr, RID, bool) + BIND2(viewport_set_usage, RID, ViewportUsage) /* ENVIRONMENT API */ @@ -944,7 +953,6 @@ public: BIND6(environment_set_dof_blur_near, RID, bool, float, float, float, EnvironmentDOFBlurQuality) BIND6(environment_set_dof_blur_far, RID, bool, float, float, float, EnvironmentDOFBlurQuality) BIND10(environment_set_glow, RID, bool, int, float, float, float, EnvironmentGlowBlendMode, float, float, bool) - BIND5(environment_set_fog, RID, bool, float, float, RID) BIND9(environment_set_tonemap, RID, EnvironmentToneMapper, float, float, bool, float, float, float, float) @@ -1100,6 +1108,8 @@ public: /* EVENT QUEUING */ + virtual void request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata); + virtual void draw(); virtual void sync(); virtual bool has_changed() const; diff --git a/servers/visual/visual_server_viewport.cpp b/servers/visual/visual_server_viewport.cpp index c1f1922255..3292d3feb4 100644 --- a/servers/visual/visual_server_viewport.cpp +++ b/servers/visual/visual_server_viewport.cpp @@ -88,7 +88,7 @@ void VisualServerViewport::_draw_viewport(Viewport *p_viewport) { } } - if (!p_viewport->disable_3d && p_viewport->camera.is_valid()) { + if (!p_viewport->disable_3d && !p_viewport->disable_3d_by_usage && p_viewport->camera.is_valid()) { VSG::scene->render_camera(p_viewport->camera, p_viewport->scenario, p_viewport->size, p_viewport->shadow_atlas); } @@ -409,7 +409,8 @@ void VisualServerViewport::viewport_set_disable_3d(RID p_viewport, bool p_disabl ERR_FAIL_COND(!viewport); viewport->disable_3d = p_disable; - VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, p_disable); + //VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, p_disable); + //this should be just for disabling rendering of 3D, to actually disable it, set usage } void VisualServerViewport::viewport_attach_camera(RID p_viewport, RID p_camera) { @@ -518,6 +519,44 @@ void VisualServerViewport::viewport_set_hdr(RID p_viewport, bool p_enabled) { VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_HDR, p_enabled); } +void VisualServerViewport::viewport_set_usage(RID p_viewport, VS::ViewportUsage p_usage) { + + Viewport *viewport = viewport_owner.getornull(p_viewport); + ERR_FAIL_COND(!viewport); + + switch (p_usage) { + case VS::VIEWPORT_USAGE_2D: { + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false); + + viewport->disable_3d_by_usage = true; + } break; + case VS::VIEWPORT_USAGE_2D_NO_SAMPLING: { + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, true); + viewport->disable_3d_by_usage = true; + } break; + case VS::VIEWPORT_USAGE_3D: { + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, false); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, false); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false); + viewport->disable_3d_by_usage = false; + } break; + case VS::VIEWPORT_USAGE_3D_NO_EFFECTS: { + + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D, false); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_3D_EFFECTS, true); + VSG::storage->render_target_set_flag(viewport->render_target, RasterizerStorage::RENDER_TARGET_NO_SAMPLING, false); + viewport->disable_3d_by_usage = false; + } break; + } +} + bool VisualServerViewport::free(RID p_rid) { if (viewport_owner.owns(p_rid)) { diff --git a/servers/visual/visual_server_viewport.h b/servers/visual/visual_server_viewport.h index 118d11a111..ad3bfe9cb8 100644 --- a/servers/visual/visual_server_viewport.h +++ b/servers/visual/visual_server_viewport.h @@ -59,6 +59,7 @@ public: bool hide_canvas; bool disable_environment; bool disable_3d; + bool disable_3d_by_usage; RID shadow_atlas; int shadow_atlas_size; @@ -101,6 +102,7 @@ public: viewport_to_screen = 0; shadow_atlas_size = 0; disable_3d = false; + disable_3d_by_usage = false; } }; @@ -164,6 +166,7 @@ public: void viewport_set_msaa(RID p_viewport, VS::ViewportMSAA p_msaa); void viewport_set_hdr(RID p_viewport, bool p_enabled); + void viewport_set_usage(RID p_viewport, VS::ViewportUsage p_usage); void draw_viewports(); diff --git a/servers/visual/visual_server_wrap_mt.cpp b/servers/visual/visual_server_wrap_mt.cpp new file mode 100644 index 0000000000..fd15633244 --- /dev/null +++ b/servers/visual/visual_server_wrap_mt.cpp @@ -0,0 +1,193 @@ +/*************************************************************************/ +/* visual_server_wrap_mt.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 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. */ +/*************************************************************************/ +#include "visual_server_wrap_mt.h" +#include "global_config.h" +#include "os/os.h" + +void VisualServerWrapMT::thread_exit() { + + exit = true; +} + +void VisualServerWrapMT::thread_draw() { + + draw_mutex->lock(); + + draw_pending--; + bool draw = (draw_pending == 0); // only draw when no more flushes are pending + + draw_mutex->unlock(); + + if (draw) { + + visual_server->draw(); + } +} + +void VisualServerWrapMT::thread_flush() { + + draw_mutex->lock(); + + draw_pending--; + + draw_mutex->unlock(); +} + +void VisualServerWrapMT::_thread_callback(void *_instance) { + + VisualServerWrapMT *vsmt = reinterpret_cast<VisualServerWrapMT *>(_instance); + + vsmt->thread_loop(); +} + +void VisualServerWrapMT::thread_loop() { + + server_thread = Thread::get_caller_ID(); + + OS::get_singleton()->make_rendering_thread(); + + visual_server->init(); + + exit = false; + draw_thread_up = true; + while (!exit) { + // flush commands one by one, until exit is requested + command_queue.wait_and_flush_one(); + } + + command_queue.flush_all(); // flush all + + visual_server->finish(); +} + +/* EVENT QUEUING */ + +void VisualServerWrapMT::sync() { + + if (create_thread) { + + /* TODO: sync with the thread */ + + /* + ERR_FAIL_COND(!draw_mutex); + draw_mutex->lock(); + draw_pending++; //cambiar por un saferefcount + draw_mutex->unlock(); + */ + //command_queue.push( this, &VisualServerWrapMT::thread_flush); + } else { + + command_queue.flush_all(); //flush all pending from other threads + } +} + +void VisualServerWrapMT::draw() { + + if (create_thread) { + + /* TODO: Make it draw + ERR_FAIL_COND(!draw_mutex); + draw_mutex->lock(); + draw_pending++; //cambiar por un saferefcount + draw_mutex->unlock(); + + command_queue.push( this, &VisualServerWrapMT::thread_draw); + */ + } else { + + visual_server->draw(); + } +} + +void VisualServerWrapMT::init() { + + if (create_thread) { + + draw_mutex = Mutex::create(); + print_line("CREATING RENDER THREAD"); + OS::get_singleton()->release_rendering_thread(); + if (create_thread) { + thread = Thread::create(_thread_callback, this); + print_line("STARTING RENDER THREAD"); + } + while (!draw_thread_up) { + OS::get_singleton()->delay_usec(1000); + } + print_line("DONE RENDER THREAD"); + } else { + + visual_server->init(); + } +} + +void VisualServerWrapMT::finish() { + + if (thread) { + + command_queue.push(this, &VisualServerWrapMT::thread_exit); + Thread::wait_to_finish(thread); + memdelete(thread); + + texture_free_cached_ids(); + //mesh_free_cached_ids(); + + thread = NULL; + } else { + visual_server->finish(); + } + + if (draw_mutex) + memdelete(draw_mutex); +} + +VisualServerWrapMT::VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread) + : command_queue(p_create_thread) { + + visual_server = p_contained; + create_thread = p_create_thread; + thread = NULL; + draw_mutex = NULL; + draw_pending = 0; + draw_thread_up = false; + alloc_mutex = Mutex::create(); + pool_max_size = GLOBAL_DEF("memory/servers/thread_rid_prealloc_amount", 20); + + if (!p_create_thread) { + server_thread = Thread::get_caller_ID(); + } else { + server_thread = 0; + } +} + +VisualServerWrapMT::~VisualServerWrapMT() { + + memdelete(visual_server); + memdelete(alloc_mutex); + //finish(); +} diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h new file mode 100644 index 0000000000..7653bf740a --- /dev/null +++ b/servers/visual/visual_server_wrap_mt.h @@ -0,0 +1,571 @@ +/*************************************************************************/ +/* visual_server_wrap_mt.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 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 VISUAL_SERVER_WRAP_MT_H +#define VISUAL_SERVER_WRAP_MT_H + +#include "command_queue_mt.h" +#include "os/thread.h" +#include "servers/visual_server.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class VisualServerWrapMT : public VisualServer { + + // the real visual server + mutable VisualServer *visual_server; + + mutable CommandQueueMT command_queue; + + static void _thread_callback(void *_instance); + void thread_loop(); + + Thread::ID server_thread; + volatile bool exit; + Thread *thread; + volatile bool draw_thread_up; + bool create_thread; + + Mutex *draw_mutex; + int draw_pending; + void thread_draw(); + void thread_flush(); + + void thread_exit(); + + Mutex *alloc_mutex; + + int pool_max_size; + +//#define DEBUG_SYNC + +#ifdef DEBUG_SYNC +#define SYNC_DEBUG print_line("sync on: " + String(__FUNCTION__)); +#else +#define SYNC_DEBUG +#endif + +public: +#define ServerName VisualServer +#define ServerNameWrapMT VisualServerWrapMT +#define server_name visual_server +#include "servers/server_wrap_mt_common.h" + + /* EVENT QUEUING */ + FUNCRID(texture) + FUNC5(texture_allocate, RID, int, int, Image::Format, uint32_t) + FUNC3(texture_set_data, RID, const Ref<Image> &, CubeMapSide) + FUNC2RC(Ref<Image>, texture_get_data, RID, CubeMapSide) + FUNC2(texture_set_flags, RID, uint32_t) + FUNC1RC(uint32_t, texture_get_flags, RID) + FUNC1RC(Image::Format, texture_get_format, RID) + FUNC1RC(uint32_t, texture_get_texid, RID) + FUNC1RC(uint32_t, texture_get_width, RID) + FUNC1RC(uint32_t, texture_get_height, RID) + FUNC3(texture_set_size_override, RID, int, int) + + FUNC3(texture_set_detect_3d_callback, RID, TextureDetectCallback, void *) + FUNC3(texture_set_detect_srgb_callback, RID, TextureDetectCallback, void *) + + FUNC2(texture_set_path, RID, const String &) + FUNC1RC(String, texture_get_path, RID) + FUNC1(texture_set_shrink_all_x2_on_set_data, bool) + FUNC1(texture_debug_usage, List<TextureInfo> *) + + FUNC1(textures_keep_original, bool) + + /* SKY API */ + + FUNC0R(RID, sky_create) + FUNC3(sky_set_texture, RID, RID, int) + + /* SHADER API */ + + FUNC0R(RID, shader_create) + + FUNC2(shader_set_code, RID, const String &) + FUNC1RC(String, shader_get_code, RID) + + FUNC2C(shader_get_param_list, RID, List<PropertyInfo> *) + + FUNC3(shader_set_default_texture_param, RID, const StringName &, RID) + FUNC2RC(RID, shader_get_default_texture_param, RID, const StringName &) + + /* COMMON MATERIAL API */ + + FUNC0R(RID, material_create) + + FUNC2(material_set_shader, RID, RID) + FUNC1RC(RID, material_get_shader, RID) + + FUNC3(material_set_param, RID, const StringName &, const Variant &) + FUNC2RC(Variant, material_get_param, RID, const StringName &) + + FUNC2(material_set_line_width, RID, float) + + /* MESH API */ + + FUNC0R(RID, mesh_create) + + FUNC10(mesh_add_surface, RID, uint32_t, PrimitiveType, const PoolVector<uint8_t> &, int, const PoolVector<uint8_t> &, int, const Rect3 &, const Vector<PoolVector<uint8_t> > &, const Vector<Rect3> &) + + FUNC2(mesh_set_blend_shape_count, RID, int) + FUNC1RC(int, mesh_get_blend_shape_count, RID) + + FUNC2(mesh_set_blend_shape_mode, RID, BlendShapeMode) + FUNC1RC(BlendShapeMode, mesh_get_blend_shape_mode, RID) + + FUNC3(mesh_surface_set_material, RID, int, RID) + FUNC2RC(RID, mesh_surface_get_material, RID, int) + + FUNC2RC(int, mesh_surface_get_array_len, RID, int) + FUNC2RC(int, mesh_surface_get_array_index_len, RID, int) + + FUNC2RC(PoolVector<uint8_t>, mesh_surface_get_array, RID, int) + FUNC2RC(PoolVector<uint8_t>, mesh_surface_get_index_array, RID, int) + + FUNC2RC(uint32_t, mesh_surface_get_format, RID, int) + FUNC2RC(PrimitiveType, mesh_surface_get_primitive_type, RID, int) + + FUNC2RC(Rect3, mesh_surface_get_aabb, RID, int) + FUNC2RC(Vector<PoolVector<uint8_t> >, mesh_surface_get_blend_shapes, RID, int) + FUNC2RC(Vector<Rect3>, mesh_surface_get_skeleton_aabb, RID, int) + + FUNC2(mesh_remove_surface, RID, int) + FUNC1RC(int, mesh_get_surface_count, RID) + + FUNC2(mesh_set_custom_aabb, RID, const Rect3 &) + FUNC1RC(Rect3, mesh_get_custom_aabb, RID) + + FUNC1(mesh_clear, RID) + + /* MULTIMESH API */ + + FUNC0R(RID, multimesh_create) + + FUNC4(multimesh_allocate, RID, int, MultimeshTransformFormat, MultimeshColorFormat) + FUNC1RC(int, multimesh_get_instance_count, RID) + + FUNC2(multimesh_set_mesh, RID, RID) + FUNC3(multimesh_instance_set_transform, RID, int, const Transform &) + FUNC3(multimesh_instance_set_transform_2d, RID, int, const Transform2D &) + FUNC3(multimesh_instance_set_color, RID, int, const Color &) + + FUNC1RC(RID, multimesh_get_mesh, RID) + FUNC1RC(Rect3, multimesh_get_aabb, RID) + + FUNC2RC(Transform, multimesh_instance_get_transform, RID, int) + FUNC2RC(Transform2D, multimesh_instance_get_transform_2d, RID, int) + FUNC2RC(Color, multimesh_instance_get_color, RID, int) + + FUNC2(multimesh_set_visible_instances, RID, int) + FUNC1RC(int, multimesh_get_visible_instances, RID) + + /* IMMEDIATE API */ + + FUNC0R(RID, immediate_create) + FUNC3(immediate_begin, RID, PrimitiveType, RID) + FUNC2(immediate_vertex, RID, const Vector3 &) + FUNC2(immediate_normal, RID, const Vector3 &) + FUNC2(immediate_tangent, RID, const Plane &) + FUNC2(immediate_color, RID, const Color &) + FUNC2(immediate_uv, RID, const Vector2 &) + FUNC2(immediate_uv2, RID, const Vector2 &) + FUNC1(immediate_end, RID) + FUNC1(immediate_clear, RID) + FUNC2(immediate_set_material, RID, RID) + FUNC1RC(RID, immediate_get_material, RID) + + /* SKELETON API */ + + FUNC0R(RID, skeleton_create) + FUNC3(skeleton_allocate, RID, int, bool) + FUNC1RC(int, skeleton_get_bone_count, RID) + FUNC3(skeleton_bone_set_transform, RID, int, const Transform &) + FUNC2RC(Transform, skeleton_bone_get_transform, RID, int) + FUNC3(skeleton_bone_set_transform_2d, RID, int, const Transform2D &) + FUNC2RC(Transform2D, skeleton_bone_get_transform_2d, RID, int) + + /* Light API */ + + FUNC1R(RID, light_create, LightType) + + FUNC2(light_set_color, RID, const Color &) + FUNC3(light_set_param, RID, LightParam, float) + FUNC2(light_set_shadow, RID, bool) + FUNC2(light_set_shadow_color, RID, const Color &) + FUNC2(light_set_projector, RID, RID) + FUNC2(light_set_negative, RID, bool) + FUNC2(light_set_cull_mask, RID, uint32_t) + + FUNC2(light_omni_set_shadow_mode, RID, LightOmniShadowMode) + FUNC2(light_omni_set_shadow_detail, RID, LightOmniShadowDetail) + + FUNC2(light_directional_set_shadow_mode, RID, LightDirectionalShadowMode) + FUNC2(light_directional_set_blend_splits, RID, bool) + + /* PROBE API */ + + FUNC0R(RID, reflection_probe_create) + + FUNC2(reflection_probe_set_update_mode, RID, ReflectionProbeUpdateMode) + FUNC2(reflection_probe_set_intensity, RID, float) + FUNC2(reflection_probe_set_interior_ambient, RID, const Color &) + FUNC2(reflection_probe_set_interior_ambient_energy, RID, float) + FUNC2(reflection_probe_set_interior_ambient_probe_contribution, RID, float) + FUNC2(reflection_probe_set_max_distance, RID, float) + FUNC2(reflection_probe_set_extents, RID, const Vector3 &) + FUNC2(reflection_probe_set_origin_offset, RID, const Vector3 &) + FUNC2(reflection_probe_set_as_interior, RID, bool) + FUNC2(reflection_probe_set_enable_box_projection, RID, bool) + FUNC2(reflection_probe_set_enable_shadows, RID, bool) + FUNC2(reflection_probe_set_cull_mask, RID, uint32_t) + + /* ROOM API */ + + FUNC0R(RID, room_create) + FUNC4(room_add_bounds, RID, const PoolVector<Vector2> &, float, const Transform &) + FUNC1(room_clear_bounds, RID) + + /* PORTAL API */ + + // portals are only (x/y) points, forming a convex shape, which its clockwise + // order points outside. (z is 0); + + FUNC0R(RID, portal_create) + FUNC2(portal_set_shape, RID, const Vector<Point2> &) + FUNC2(portal_set_enabled, RID, bool) + FUNC2(portal_set_disable_distance, RID, float) + FUNC2(portal_set_disabled_color, RID, const Color &) + + /* BAKED LIGHT API */ + + FUNC0R(RID, gi_probe_create) + + FUNC2(gi_probe_set_bounds, RID, const Rect3 &) + FUNC1RC(Rect3, gi_probe_get_bounds, RID) + + FUNC2(gi_probe_set_cell_size, RID, float) + FUNC1RC(float, gi_probe_get_cell_size, RID) + + FUNC2(gi_probe_set_to_cell_xform, RID, const Transform &) + FUNC1RC(Transform, gi_probe_get_to_cell_xform, RID) + + FUNC2(gi_probe_set_dynamic_range, RID, int) + FUNC1RC(int, gi_probe_get_dynamic_range, RID) + + FUNC2(gi_probe_set_energy, RID, float) + FUNC1RC(float, gi_probe_get_energy, RID) + + FUNC2(gi_probe_set_bias, RID, float) + FUNC1RC(float, gi_probe_get_bias, RID) + + FUNC2(gi_probe_set_propagation, RID, float) + FUNC1RC(float, gi_probe_get_propagation, RID) + + FUNC2(gi_probe_set_interior, RID, bool) + FUNC1RC(bool, gi_probe_is_interior, RID) + + FUNC2(gi_probe_set_compress, RID, bool) + FUNC1RC(bool, gi_probe_is_compressed, RID) + + FUNC2(gi_probe_set_dynamic_data, RID, const PoolVector<int> &) + FUNC1RC(PoolVector<int>, gi_probe_get_dynamic_data, RID) + + /* PARTICLES */ + + FUNC0R(RID, particles_create) + + FUNC2(particles_set_emitting, RID, bool) + FUNC2(particles_set_amount, RID, int) + FUNC2(particles_set_lifetime, RID, float) + FUNC2(particles_set_pre_process_time, RID, float) + FUNC2(particles_set_explosiveness_ratio, RID, float) + FUNC2(particles_set_randomness_ratio, RID, float) + FUNC2(particles_set_custom_aabb, RID, const Rect3 &) + FUNC2(particles_set_speed_scale, RID, float) + FUNC2(particles_set_use_local_coordinates, RID, bool) + FUNC2(particles_set_process_material, RID, RID) + FUNC2(particles_set_fixed_fps, RID, int) + FUNC2(particles_set_fractional_delta, RID, bool) + + FUNC2(particles_set_draw_order, RID, VS::ParticlesDrawOrder) + + FUNC2(particles_set_draw_passes, RID, int) + FUNC3(particles_set_draw_pass_mesh, RID, int, RID) + + FUNC1R(Rect3, particles_get_current_aabb, RID) + + /* CAMERA API */ + + FUNC0R(RID, camera_create) + FUNC4(camera_set_perspective, RID, float, float, float) + FUNC4(camera_set_orthogonal, RID, float, float, float) + FUNC2(camera_set_transform, RID, const Transform &) + FUNC2(camera_set_cull_mask, RID, uint32_t) + FUNC2(camera_set_environment, RID, RID) + FUNC2(camera_set_use_vertical_aspect, RID, bool) + + /* VIEWPORT TARGET API */ + + FUNC0R(RID, viewport_create) + + FUNC3(viewport_set_size, RID, int, int) + + FUNC2(viewport_set_active, RID, bool) + FUNC2(viewport_set_parent_viewport, RID, RID) + + FUNC2(viewport_set_clear_mode, RID, ViewportClearMode) + + FUNC3(viewport_attach_to_screen, RID, const Rect2 &, int) + FUNC1(viewport_detach, RID) + + FUNC2(viewport_set_update_mode, RID, ViewportUpdateMode) + FUNC2(viewport_set_vflip, RID, bool) + + FUNC1RC(RID, viewport_get_texture, RID) + + FUNC2(viewport_set_hide_scenario, RID, bool) + FUNC2(viewport_set_hide_canvas, RID, bool) + FUNC2(viewport_set_disable_environment, RID, bool) + FUNC2(viewport_set_disable_3d, RID, bool) + + FUNC2(viewport_attach_camera, RID, RID) + FUNC2(viewport_set_scenario, RID, RID) + FUNC2(viewport_attach_canvas, RID, RID) + + FUNC2(viewport_remove_canvas, RID, RID) + FUNC3(viewport_set_canvas_transform, RID, RID, const Transform2D &) + FUNC2(viewport_set_transparent_background, RID, bool) + + FUNC2(viewport_set_global_canvas_transform, RID, const Transform2D &) + FUNC3(viewport_set_canvas_layer, RID, RID, int) + FUNC2(viewport_set_shadow_atlas_size, RID, int) + FUNC3(viewport_set_shadow_atlas_quadrant_subdivision, RID, int, int) + FUNC2(viewport_set_msaa, RID, ViewportMSAA) + FUNC2(viewport_set_hdr, RID, bool) + FUNC2(viewport_set_usage, RID, ViewportUsage) + + /* ENVIRONMENT API */ + + FUNC0R(RID, environment_create) + + FUNC2(environment_set_background, RID, EnvironmentBG) + FUNC2(environment_set_sky, RID, RID) + FUNC2(environment_set_sky_scale, RID, float) + FUNC2(environment_set_bg_color, RID, const Color &) + FUNC2(environment_set_bg_energy, RID, float) + FUNC2(environment_set_canvas_max_layer, RID, int) + FUNC4(environment_set_ambient_light, RID, const Color &, float, float) + FUNC8(environment_set_ssr, RID, bool, int, float, float, float, bool, bool) + FUNC10(environment_set_ssao, RID, bool, float, float, float, float, float, float, const Color &, bool) + + FUNC6(environment_set_dof_blur_near, RID, bool, float, float, float, EnvironmentDOFBlurQuality) + FUNC6(environment_set_dof_blur_far, RID, bool, float, float, float, EnvironmentDOFBlurQuality) + FUNC10(environment_set_glow, RID, bool, int, float, float, float, EnvironmentGlowBlendMode, float, float, bool) + + FUNC9(environment_set_tonemap, RID, EnvironmentToneMapper, float, float, bool, float, float, float, float) + + FUNC6(environment_set_adjustment, RID, bool, float, float, float, RID) + + FUNC5(environment_set_fog, RID, bool, const Color &, const Color &, float) + FUNC6(environment_set_fog_depth, RID, bool, float, float, bool, float) + FUNC5(environment_set_fog_height, RID, bool, float, float, float) + + FUNC0R(RID, scenario_create) + + FUNC2(scenario_set_debug, RID, ScenarioDebugMode) + FUNC2(scenario_set_environment, RID, RID) + FUNC3(scenario_set_reflection_atlas_size, RID, int, int) + FUNC2(scenario_set_fallback_environment, RID, RID) + + /* INSTANCING API */ + // from can be mesh, light, area and portal so far. + FUNC0R(RID, instance_create) + + FUNC2(instance_set_base, RID, RID) // from can be mesh, light, poly, area and portal so far. + FUNC2(instance_set_scenario, RID, RID) // from can be mesh, light, poly, area and portal so far. + FUNC2(instance_set_layer_mask, RID, uint32_t) + FUNC2(instance_set_transform, RID, const Transform &) + FUNC2(instance_attach_object_instance_ID, RID, ObjectID) + FUNC3(instance_set_blend_shape_weight, RID, int, float) + FUNC3(instance_set_surface_material, RID, int, RID) + FUNC2(instance_set_visible, RID, bool) + + FUNC2(instance_attach_skeleton, RID, RID) + FUNC2(instance_set_exterior, RID, bool) + FUNC2(instance_set_room, RID, RID) + + FUNC2(instance_set_extra_visibility_margin, RID, real_t) + + // don't use these in a game! + FUNC2RC(Vector<ObjectID>, instances_cull_aabb, const Rect3 &, RID) + FUNC3RC(Vector<ObjectID>, instances_cull_ray, const Vector3 &, const Vector3 &, RID) + FUNC2RC(Vector<ObjectID>, instances_cull_convex, const Vector<Plane> &, RID) + + FUNC3(instance_geometry_set_flag, RID, InstanceFlags, bool) + FUNC2(instance_geometry_set_cast_shadows_setting, RID, ShadowCastingSetting) + FUNC2(instance_geometry_set_material_override, RID, RID) + + FUNC5(instance_geometry_set_draw_range, RID, float, float, float, float) + FUNC2(instance_geometry_set_as_instance_lod, RID, RID) + + /* CANVAS (2D) */ + + FUNC0R(RID, canvas_create) + FUNC3(canvas_set_item_mirroring, RID, RID, const Point2 &) + FUNC2(canvas_set_modulate, RID, const Color &) + + FUNC0R(RID, canvas_item_create) + FUNC2(canvas_item_set_parent, RID, RID) + + FUNC2(canvas_item_set_visible, RID, bool) + FUNC2(canvas_item_set_light_mask, RID, int) + + FUNC2(canvas_item_set_transform, RID, const Transform2D &) + FUNC2(canvas_item_set_clip, RID, bool) + FUNC2(canvas_item_set_distance_field_mode, RID, bool) + FUNC3(canvas_item_set_custom_rect, RID, bool, const Rect2 &) + FUNC2(canvas_item_set_modulate, RID, const Color &) + FUNC2(canvas_item_set_self_modulate, RID, const Color &) + + FUNC2(canvas_item_set_draw_behind_parent, RID, bool) + + FUNC6(canvas_item_add_line, RID, const Point2 &, const Point2 &, const Color &, float, bool) + FUNC3(canvas_item_add_rect, RID, const Rect2 &, const Color &) + FUNC4(canvas_item_add_circle, RID, const Point2 &, float, const Color &) + FUNC6(canvas_item_add_texture_rect, RID, const Rect2 &, RID, bool, const Color &, bool) + FUNC6(canvas_item_add_texture_rect_region, RID, const Rect2 &, RID, const Rect2 &, const Color &, bool) + FUNC10(canvas_item_add_nine_patch, RID, const Rect2 &, const Rect2 &, RID, const Vector2 &, const Vector2 &, NinePatchAxisMode, NinePatchAxisMode, bool, const Color &) + FUNC6(canvas_item_add_primitive, RID, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID, float) + FUNC5(canvas_item_add_polygon, RID, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID) + FUNC7(canvas_item_add_triangle_array, RID, const Vector<int> &, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID, int) + FUNC3(canvas_item_add_mesh, RID, const RID &, RID) + FUNC3(canvas_item_add_multimesh, RID, RID, RID) + FUNC2(canvas_item_add_set_transform, RID, const Transform2D &) + FUNC2(canvas_item_add_clip_ignore, RID, bool) + FUNC2(canvas_item_set_sort_children_by_y, RID, bool) + FUNC2(canvas_item_set_z, RID, int) + FUNC2(canvas_item_set_z_as_relative_to_parent, RID, bool) + FUNC3(canvas_item_set_copy_to_backbuffer, RID, bool, const Rect2 &) + + FUNC1(canvas_item_clear, RID) + FUNC2(canvas_item_set_draw_index, RID, int) + + FUNC2(canvas_item_set_material, RID, RID) + + FUNC2(canvas_item_set_use_parent_material, RID, bool) + + FUNC0R(RID, canvas_light_create) + FUNC2(canvas_light_attach_to_canvas, RID, RID) + FUNC2(canvas_light_set_enabled, RID, bool) + FUNC2(canvas_light_set_scale, RID, float) + FUNC2(canvas_light_set_transform, RID, const Transform2D &) + FUNC2(canvas_light_set_texture, RID, RID) + FUNC2(canvas_light_set_texture_offset, RID, const Vector2 &) + FUNC2(canvas_light_set_color, RID, const Color &) + FUNC2(canvas_light_set_height, RID, float) + FUNC2(canvas_light_set_energy, RID, float) + FUNC3(canvas_light_set_z_range, RID, int, int) + FUNC3(canvas_light_set_layer_range, RID, int, int) + FUNC2(canvas_light_set_item_cull_mask, RID, int) + FUNC2(canvas_light_set_item_shadow_cull_mask, RID, int) + + FUNC2(canvas_light_set_mode, RID, CanvasLightMode) + + FUNC2(canvas_light_set_shadow_enabled, RID, bool) + FUNC2(canvas_light_set_shadow_buffer_size, RID, int) + FUNC2(canvas_light_set_shadow_gradient_length, RID, float) + FUNC2(canvas_light_set_shadow_filter, RID, CanvasLightShadowFilter) + FUNC2(canvas_light_set_shadow_color, RID, const Color &) + + FUNC0R(RID, canvas_light_occluder_create) + FUNC2(canvas_light_occluder_attach_to_canvas, RID, RID) + FUNC2(canvas_light_occluder_set_enabled, RID, bool) + FUNC2(canvas_light_occluder_set_polygon, RID, RID) + FUNC2(canvas_light_occluder_set_transform, RID, const Transform2D &) + FUNC2(canvas_light_occluder_set_light_mask, RID, int) + + FUNC0R(RID, canvas_occluder_polygon_create) + FUNC3(canvas_occluder_polygon_set_shape, RID, const PoolVector<Vector2> &, bool) + FUNC2(canvas_occluder_polygon_set_shape_as_lines, RID, const PoolVector<Vector2> &) + + FUNC2(canvas_occluder_polygon_set_cull_mode, RID, CanvasOccluderPolygonCullMode) + + /* CURSOR */ + FUNC2(cursor_set_rotation, float, int) // radians + FUNC4(cursor_set_texture, RID, const Point2 &, int, const Rect2 &) + FUNC2(cursor_set_visible, bool, int) + FUNC2(cursor_set_pos, const Point2 &, int) + + /* BLACK BARS */ + + FUNC4(black_bars_set_margins, int, int, int, int) + FUNC4(black_bars_set_images, RID, RID, RID, RID) + + /* FREE */ + + FUNC1(free, RID) + + /* EVENT QUEUING */ + + FUNC3(request_frame_drawn_callback, Object *, const StringName &, const Variant &) + + virtual void init(); + virtual void finish(); + virtual void draw(); + virtual void sync(); + FUNC0RC(bool, has_changed) + + /* RENDER INFO */ + + FUNC1R(int, get_render_info, RenderInfo) + + FUNC3(set_boot_image, const Ref<Image> &, const Color &, bool) + FUNC1(set_default_clear_color, const Color &) + + FUNC0R(RID, get_test_cube) + + virtual bool has_feature(Features p_feature) const { return visual_server->has_feature(p_feature); } + virtual bool has_os_feature(const String &p_feature) const { return visual_server->has_os_feature(p_feature); } + + VisualServerWrapMT(VisualServer *p_contained, bool p_create_thread); + ~VisualServerWrapMT(); + +#undef ServerName +#undef ServerNameWrapMT +#undef server_name +}; + +#ifdef DEBUG_SYNC +#undef DEBUG_SYNC +#endif +#undef SYNC_DEBUG + +#endif diff --git a/servers/visual_server.h b/servers/visual_server.h index 3d5ca9d99a..c7637007b3 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -579,7 +579,16 @@ public: }; virtual void viewport_set_msaa(RID p_viewport, ViewportMSAA p_msaa) = 0; + + enum ViewportUsage { + VIEWPORT_USAGE_2D, + VIEWPORT_USAGE_2D_NO_SAMPLING, + VIEWPORT_USAGE_3D, + VIEWPORT_USAGE_3D_NO_EFFECTS, + }; + virtual void viewport_set_hdr(RID p_viewport, bool p_enabled) = 0; + virtual void viewport_set_usage(RID p_viewport, ViewportUsage p_usage) = 0; /* ENVIRONMENT API */ @@ -623,7 +632,6 @@ public: GLOW_BLEND_MODE_REPLACE, }; virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_treshold, EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_treshold, float p_hdr_bleed_scale, bool p_bicubic_upscale) = 0; - virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) = 0; enum EnvironmentToneMapper { ENV_TONE_MAPPER_LINEAR, @@ -848,6 +856,8 @@ public: virtual void free(RID p_rid) = 0; ///< free RIDs associated with the visual server + virtual void request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) = 0; + /* EVENT QUEUING */ virtual void draw() = 0; |