diff options
author | reduz <reduzio@gmail.com> | 2021-06-29 13:36:32 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-06-29 17:40:45 -0300 |
commit | d07f7c8d2516a338547dc4bbd73e17d3b357c8d7 (patch) | |
tree | dd46a26b78e4fb92f78b4cdac3a3acb9ca95607c | |
parent | 916c37de09871be0f5578f2f23f700ecaa08f836 (diff) |
Fixes to 2D viewport
* Editor 2D viewport now uses embedded subwindows (windows no longer pop up)
* Restored the ability to disable 3D on the 2D viewport (makes 3D not display on 2D when there is a camera on the scene)
-rw-r--r-- | doc/classes/Viewport.xml | 3 | ||||
-rw-r--r-- | editor/editor_node.cpp | 3 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 13 | ||||
-rw-r--r-- | scene/main/viewport.h | 5 | ||||
-rw-r--r-- | servers/rendering/renderer_viewport.cpp | 9 | ||||
-rw-r--r-- | servers/rendering/renderer_viewport.h | 2 | ||||
-rw-r--r-- | servers/rendering/rendering_server_default.h | 1 | ||||
-rw-r--r-- | servers/rendering_server.h | 1 |
8 files changed, 35 insertions, 2 deletions
diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 292be34a0d..bc0c3c5516 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -208,6 +208,9 @@ <member name="debug_draw" type="int" setter="set_debug_draw" getter="get_debug_draw" enum="Viewport.DebugDraw" default="0"> The overlay mode for test rendered geometry in debug purposes. </member> + <member name="disable_3d" type="bool" setter="set_disable_3d" getter="is_3d_disabled" default="false"> + Disable 3D rendering (but keep 2D rendering). + </member> <member name="global_canvas_transform" type="Transform2D" setter="set_global_canvas_transform" getter="get_global_canvas_transform"> The global canvas transform of the viewport. The canvas transform is relative to this. </member> diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 1bc04676b7..31f84d2508 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6116,7 +6116,8 @@ EditorNode::EditorNode() { scene_root_parent->set_v_size_flags(Control::SIZE_EXPAND_FILL); scene_root = memnew(SubViewport); - //scene_root->set_usage(Viewport::USAGE_2D); canvas BG mode prevents usage of this as 2D + scene_root->set_embed_subwindows_hint(true); + scene_root->set_disable_3d(true); RenderingServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport_rid(), true); scene_root->set_disable_input(true); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index cc56d6a49e..319e589036 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -929,6 +929,15 @@ bool Viewport::is_audio_listener_2d() const { return audio_listener_2d; } +void Viewport::set_disable_3d(bool p_disable) { + disable_3d = p_disable; + RenderingServer::get_singleton()->viewport_set_disable_3d(viewport, disable_3d); +} + +bool Viewport::is_3d_disabled() const { + return disable_3d; +} + void Viewport::enable_canvas_transform_override(bool p_enable) { if (override_canvas_transform == p_enable) { return; @@ -3516,6 +3525,9 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d); ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d); + ClassDB::bind_method(D_METHOD("set_disable_3d", "disable"), &Viewport::set_disable_3d); + ClassDB::bind_method(D_METHOD("is_3d_disabled"), &Viewport::is_3d_disabled); + ClassDB::bind_method(D_METHOD("get_mouse_position"), &Viewport::get_mouse_position); ClassDB::bind_method(D_METHOD("warp_mouse", "to_position"), &Viewport::warp_mouse); @@ -3582,6 +3594,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_transforms_to_pixel"), "set_snap_2d_transforms_to_pixel", "is_snap_2d_transforms_to_pixel_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_vertices_to_pixel"), "set_snap_2d_vertices_to_pixel", "is_snap_2d_vertices_to_pixel_enabled"); ADD_GROUP("Rendering", ""); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled (Fastest),2x (Fast),4x (Average),8x (Slow),16x (Slower)"), "set_msaa", "get_msaa"); ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_space_aa", PROPERTY_HINT_ENUM, "Disabled (Fastest),FXAA (Fast)"), "set_screen_space_aa", "get_screen_space_aa"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_debanding"), "set_use_debanding", "is_using_debanding"); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index d905e44a82..29491a1178 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -288,6 +288,8 @@ private: void _update_listener(); void _update_listener_2d(); + bool disable_3d = false; + void _propagate_enter_world(Node *p_node); void _propagate_exit_world(Node *p_node); void _propagate_viewport_notification(Node *p_node, int p_what); @@ -503,6 +505,9 @@ public: void set_as_audio_listener_2d(bool p_enable); bool is_audio_listener_2d() const; + void set_disable_3d(bool p_disable); + bool is_3d_disabled() const; + void update_canvas_items(); Rect2 get_visible_rect() const; diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index e34d36bfff..2cf4c035a9 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -122,7 +122,7 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport, uint32_t p_view_coun } } - bool can_draw_3d = RSG::scene->is_camera(p_viewport->camera); + bool can_draw_3d = RSG::scene->is_camera(p_viewport->camera) && !p_viewport->disable_3d; if (p_viewport->clear_mode != RS::VIEWPORT_CLEAR_NEVER) { if (p_viewport->transparent_bg) { @@ -812,6 +812,13 @@ void RendererViewport::viewport_set_disable_environment(RID p_viewport, bool p_d viewport->disable_environment = p_disable; } +void RendererViewport::viewport_set_disable_3d(RID p_viewport, bool p_disable) { + Viewport *viewport = viewport_owner.getornull(p_viewport); + ERR_FAIL_COND(!viewport); + + viewport->disable_3d = p_disable; +} + void RendererViewport::viewport_attach_camera(RID p_viewport, RID p_camera) { Viewport *viewport = viewport_owner.getornull(p_viewport); ERR_FAIL_COND(!viewport); diff --git a/servers/rendering/renderer_viewport.h b/servers/rendering/renderer_viewport.h index 8fedf32c04..ca40829648 100644 --- a/servers/rendering/renderer_viewport.h +++ b/servers/rendering/renderer_viewport.h @@ -71,6 +71,7 @@ public: bool hide_scenario; bool hide_canvas; bool disable_environment; + bool disable_3d = false; bool measure_render_time; bool snap_2d_transforms_to_pixel; @@ -220,6 +221,7 @@ public: void viewport_set_hide_scenario(RID p_viewport, bool p_hide); void viewport_set_hide_canvas(RID p_viewport, bool p_hide); void viewport_set_disable_environment(RID p_viewport, bool p_disable); + void viewport_set_disable_3d(RID p_viewport, bool p_disable); void viewport_attach_camera(RID p_viewport, RID p_camera); void viewport_set_scenario(RID p_viewport, RID p_scenario); diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index 16e9f1fc77..b9afeafbab 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -585,6 +585,7 @@ public: 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) diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 594e2d885c..0a568eeb13 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -799,6 +799,7 @@ public: virtual void viewport_set_hide_scenario(RID p_viewport, bool p_hide) = 0; virtual void viewport_set_hide_canvas(RID p_viewport, bool p_hide) = 0; virtual void viewport_set_disable_environment(RID p_viewport, bool p_disable) = 0; + virtual void viewport_set_disable_3d(RID p_viewport, bool p_disable) = 0; virtual void viewport_attach_camera(RID p_viewport, RID p_camera) = 0; virtual void viewport_set_scenario(RID p_viewport, RID p_scenario) = 0; |