viewport.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. /**************************************************************************/
  2. /* viewport.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "scene/main/node.h"
  32. #include "scene/resources/texture.h"
  33. #ifndef _3D_DISABLED
  34. class Camera3D;
  35. class CollisionObject3D;
  36. class AudioListener3D;
  37. class World3D;
  38. #endif // _3D_DISABLED
  39. class AudioListener2D;
  40. class Camera2D;
  41. class CanvasItem;
  42. class CanvasLayer;
  43. class Control;
  44. class Label;
  45. class SceneTreeTimer;
  46. class Viewport;
  47. class Window;
  48. class World2D;
  49. class ViewportTexture : public Texture2D {
  50. GDCLASS(ViewportTexture, Texture2D);
  51. NodePath path;
  52. friend class Viewport;
  53. Viewport *vp = nullptr;
  54. bool vp_pending = false;
  55. bool vp_changed = false;
  56. void _setup_local_to_scene(const Node *p_loc_scene);
  57. void _err_print_viewport_not_set() const;
  58. mutable RID proxy_ph;
  59. mutable RID proxy;
  60. protected:
  61. static void _bind_methods();
  62. virtual void reset_local_to_scene() override;
  63. public:
  64. void set_viewport_path_in_scene(const NodePath &p_path);
  65. NodePath get_viewport_path_in_scene() const;
  66. virtual void setup_local_to_scene() override;
  67. virtual int get_width() const override;
  68. virtual int get_height() const override;
  69. virtual Size2 get_size() const override;
  70. virtual RID get_rid() const override;
  71. virtual bool has_alpha() const override;
  72. virtual Ref<Image> get_image() const override;
  73. ViewportTexture();
  74. ~ViewportTexture();
  75. };
  76. class Viewport : public Node {
  77. GDCLASS(Viewport, Node);
  78. public:
  79. enum Scaling3DMode {
  80. SCALING_3D_MODE_BILINEAR,
  81. SCALING_3D_MODE_FSR,
  82. SCALING_3D_MODE_FSR2,
  83. SCALING_3D_MODE_METALFX_SPATIAL,
  84. SCALING_3D_MODE_METALFX_TEMPORAL,
  85. SCALING_3D_MODE_MAX
  86. };
  87. enum PositionalShadowAtlasQuadrantSubdiv {
  88. SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED,
  89. SHADOW_ATLAS_QUADRANT_SUBDIV_1,
  90. SHADOW_ATLAS_QUADRANT_SUBDIV_4,
  91. SHADOW_ATLAS_QUADRANT_SUBDIV_16,
  92. SHADOW_ATLAS_QUADRANT_SUBDIV_64,
  93. SHADOW_ATLAS_QUADRANT_SUBDIV_256,
  94. SHADOW_ATLAS_QUADRANT_SUBDIV_1024,
  95. SHADOW_ATLAS_QUADRANT_SUBDIV_MAX,
  96. };
  97. enum MSAA {
  98. MSAA_DISABLED,
  99. MSAA_2X,
  100. MSAA_4X,
  101. MSAA_8X,
  102. // 16x MSAA is not supported due to its high cost and driver bugs.
  103. MSAA_MAX
  104. };
  105. enum AnisotropicFiltering {
  106. ANISOTROPY_DISABLED,
  107. ANISOTROPY_2X,
  108. ANISOTROPY_4X,
  109. ANISOTROPY_8X,
  110. ANISOTROPY_16X,
  111. ANISOTROPY_MAX
  112. };
  113. enum ScreenSpaceAA {
  114. SCREEN_SPACE_AA_DISABLED,
  115. SCREEN_SPACE_AA_FXAA,
  116. SCREEN_SPACE_AA_MAX
  117. };
  118. enum RenderInfo {
  119. RENDER_INFO_OBJECTS_IN_FRAME,
  120. RENDER_INFO_PRIMITIVES_IN_FRAME,
  121. RENDER_INFO_DRAW_CALLS_IN_FRAME,
  122. RENDER_INFO_MAX
  123. };
  124. enum RenderInfoType {
  125. RENDER_INFO_TYPE_VISIBLE,
  126. RENDER_INFO_TYPE_SHADOW,
  127. RENDER_INFO_TYPE_CANVAS,
  128. RENDER_INFO_TYPE_MAX
  129. };
  130. enum DebugDraw {
  131. DEBUG_DRAW_DISABLED,
  132. DEBUG_DRAW_UNSHADED,
  133. DEBUG_DRAW_LIGHTING,
  134. DEBUG_DRAW_OVERDRAW,
  135. DEBUG_DRAW_WIREFRAME,
  136. DEBUG_DRAW_NORMAL_BUFFER,
  137. DEBUG_DRAW_VOXEL_GI_ALBEDO,
  138. DEBUG_DRAW_VOXEL_GI_LIGHTING,
  139. DEBUG_DRAW_VOXEL_GI_EMISSION,
  140. DEBUG_DRAW_SHADOW_ATLAS,
  141. DEBUG_DRAW_DIRECTIONAL_SHADOW_ATLAS,
  142. DEBUG_DRAW_SCENE_LUMINANCE,
  143. DEBUG_DRAW_SSAO,
  144. DEBUG_DRAW_SSIL,
  145. DEBUG_DRAW_PSSM_SPLITS,
  146. DEBUG_DRAW_DECAL_ATLAS,
  147. DEBUG_DRAW_SDFGI,
  148. DEBUG_DRAW_SDFGI_PROBES,
  149. DEBUG_DRAW_GI_BUFFER,
  150. DEBUG_DRAW_DISABLE_LOD,
  151. DEBUG_DRAW_CLUSTER_OMNI_LIGHTS,
  152. DEBUG_DRAW_CLUSTER_SPOT_LIGHTS,
  153. DEBUG_DRAW_CLUSTER_DECALS,
  154. DEBUG_DRAW_CLUSTER_REFLECTION_PROBES,
  155. DEBUG_DRAW_OCCLUDERS,
  156. DEBUG_DRAW_MOTION_VECTORS,
  157. DEBUG_DRAW_INTERNAL_BUFFER,
  158. };
  159. enum DefaultCanvasItemTextureFilter {
  160. DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST,
  161. DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR,
  162. DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR_WITH_MIPMAPS,
  163. DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_NEAREST_WITH_MIPMAPS,
  164. DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_MAX
  165. };
  166. enum DefaultCanvasItemTextureRepeat {
  167. DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED,
  168. DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_ENABLED,
  169. DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MIRROR,
  170. DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_MAX,
  171. };
  172. enum SDFOversize {
  173. SDF_OVERSIZE_100_PERCENT,
  174. SDF_OVERSIZE_120_PERCENT,
  175. SDF_OVERSIZE_150_PERCENT,
  176. SDF_OVERSIZE_200_PERCENT,
  177. SDF_OVERSIZE_MAX
  178. };
  179. enum SDFScale {
  180. SDF_SCALE_100_PERCENT,
  181. SDF_SCALE_50_PERCENT,
  182. SDF_SCALE_25_PERCENT,
  183. SDF_SCALE_MAX
  184. };
  185. enum {
  186. SUBWINDOW_CANVAS_LAYER = 1024
  187. };
  188. enum VRSMode {
  189. VRS_DISABLED,
  190. VRS_TEXTURE,
  191. VRS_XR,
  192. VRS_MAX
  193. };
  194. enum VRSUpdateMode {
  195. VRS_UPDATE_DISABLED,
  196. VRS_UPDATE_ONCE,
  197. VRS_UPDATE_ALWAYS,
  198. VRS_UPDATE_MAX
  199. };
  200. private:
  201. friend class ViewportTexture;
  202. Viewport *parent = nullptr;
  203. Viewport *gui_parent = nullptr; // Whose gui.tooltip_popup it is.
  204. HashSet<CanvasLayer *> canvas_layers;
  205. RID viewport;
  206. RID current_canvas;
  207. RID subwindow_canvas;
  208. bool override_canvas_transform = false;
  209. Transform2D canvas_transform_override;
  210. Transform2D canvas_transform;
  211. Transform2D global_canvas_transform;
  212. Transform2D stretch_transform;
  213. Size2i size = Size2i(512, 512);
  214. Size2 size_2d_override;
  215. bool size_allocated = false;
  216. RID contact_2d_debug;
  217. RID contact_3d_debug_multimesh;
  218. RID contact_3d_debug_instance;
  219. Rect2 last_vp_rect;
  220. bool transparent_bg = false;
  221. bool use_hdr_2d = false;
  222. bool gen_mipmaps = false;
  223. bool snap_controls_to_pixels = true;
  224. bool snap_2d_transforms_to_pixel = false;
  225. bool snap_2d_vertices_to_pixel = false;
  226. #if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
  227. bool physics_object_picking = false;
  228. bool physics_object_picking_sort = false;
  229. bool physics_object_picking_first_only = false;
  230. List<Ref<InputEvent>> physics_picking_events;
  231. ObjectID physics_object_capture;
  232. ObjectID physics_object_over;
  233. Transform3D physics_last_object_transform;
  234. Transform3D physics_last_camera_transform;
  235. ObjectID physics_last_id;
  236. #endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
  237. bool handle_input_locally = true;
  238. bool local_input_handled = false;
  239. Ref<World2D> world_2d;
  240. StringName input_group;
  241. StringName shortcut_input_group;
  242. StringName unhandled_input_group;
  243. StringName unhandled_key_input_group;
  244. void _update_audio_listener_2d();
  245. bool disable_3d = false;
  246. static void _propagate_drag_notification(Node *p_node, int p_what);
  247. void _update_global_transform();
  248. RID texture_rid;
  249. DebugDraw debug_draw = DEBUG_DRAW_DISABLED;
  250. int positional_shadow_atlas_size = 2048;
  251. bool positional_shadow_atlas_16_bits = true;
  252. PositionalShadowAtlasQuadrantSubdiv positional_shadow_atlas_quadrant_subdiv[4];
  253. MSAA msaa_2d = MSAA_DISABLED;
  254. MSAA msaa_3d = MSAA_DISABLED;
  255. ScreenSpaceAA screen_space_aa = SCREEN_SPACE_AA_DISABLED;
  256. bool use_taa = false;
  257. Scaling3DMode scaling_3d_mode = SCALING_3D_MODE_BILINEAR;
  258. float scaling_3d_scale = 1.0;
  259. float fsr_sharpness = 0.2f;
  260. float texture_mipmap_bias = 0.0f;
  261. AnisotropicFiltering anisotropic_filtering_level = ANISOTROPY_4X;
  262. bool use_debanding = false;
  263. float mesh_lod_threshold = 1.0;
  264. bool use_occlusion_culling = false;
  265. Ref<ViewportTexture> default_texture;
  266. HashSet<ViewportTexture *> viewport_textures;
  267. void _update_viewport_path();
  268. SDFOversize sdf_oversize = SDF_OVERSIZE_120_PERCENT;
  269. SDFScale sdf_scale = SDF_SCALE_50_PERCENT;
  270. uint32_t canvas_cull_mask = 0xffffffff; // by default show everything
  271. enum SubWindowDrag {
  272. SUB_WINDOW_DRAG_DISABLED,
  273. SUB_WINDOW_DRAG_MOVE,
  274. SUB_WINDOW_DRAG_CLOSE,
  275. SUB_WINDOW_DRAG_RESIZE,
  276. };
  277. enum SubWindowResize {
  278. SUB_WINDOW_RESIZE_DISABLED,
  279. SUB_WINDOW_RESIZE_TOP_LEFT,
  280. SUB_WINDOW_RESIZE_TOP,
  281. SUB_WINDOW_RESIZE_TOP_RIGHT,
  282. SUB_WINDOW_RESIZE_LEFT,
  283. SUB_WINDOW_RESIZE_RIGHT,
  284. SUB_WINDOW_RESIZE_BOTTOM_LEFT,
  285. SUB_WINDOW_RESIZE_BOTTOM,
  286. SUB_WINDOW_RESIZE_BOTTOM_RIGHT,
  287. SUB_WINDOW_RESIZE_MAX
  288. };
  289. struct SubWindow {
  290. Window *window = nullptr;
  291. RID canvas_item;
  292. Rect2i parent_safe_rect;
  293. bool pending_window_update = false;
  294. };
  295. // VRS
  296. VRSMode vrs_mode = VRS_DISABLED;
  297. VRSUpdateMode vrs_update_mode = VRS_UPDATE_ONCE;
  298. Ref<Texture2D> vrs_texture;
  299. struct GUI {
  300. bool mouse_in_viewport = false;
  301. HashMap<int, ObjectID> touch_focus;
  302. Control *mouse_focus = nullptr;
  303. Control *mouse_click_grabber = nullptr;
  304. BitField<MouseButtonMask> mouse_focus_mask;
  305. Control *key_focus = nullptr;
  306. Control *mouse_over = nullptr;
  307. LocalVector<Control *> mouse_over_hierarchy;
  308. bool sending_mouse_enter_exit_notifications = false;
  309. Window *subwindow_over = nullptr; // mouse_over and subwindow_over are mutually exclusive. At all times at least one of them is nullptr.
  310. Window *windowmanager_window_over = nullptr; // Only used in root Viewport.
  311. Control *drag_mouse_over = nullptr;
  312. Control *tooltip_control = nullptr;
  313. Window *tooltip_popup = nullptr;
  314. Label *tooltip_label = nullptr;
  315. String tooltip_text;
  316. Point2 tooltip_pos;
  317. Point2 last_mouse_pos;
  318. Point2 drag_accum;
  319. bool drag_attempted = false;
  320. Variant drag_data; // Only used in root-Viewport and SubViewports, that are not children of a SubViewportContainer.
  321. ObjectID drag_preview_id;
  322. Ref<SceneTreeTimer> tooltip_timer;
  323. double tooltip_delay = 0.0;
  324. bool roots_order_dirty = false;
  325. List<Control *> roots;
  326. HashSet<ObjectID> canvas_parents_with_dirty_order;
  327. int canvas_sort_index = 0; //for sorting items with canvas as root
  328. bool dragging = false; // Is true in the viewport in which dragging started while dragging is active.
  329. bool global_dragging = false; // Is true while dragging is active. Only used in root-Viewport and SubViewports that are not children of a SubViewportContainer.
  330. bool drag_successful = false;
  331. Control *target_control = nullptr; // Control that the mouse is over in the innermost nested Viewport. Only used in root-Viewport and SubViewports, that are not children of a SubViewportContainer.
  332. bool embed_subwindows_hint = false;
  333. Window *subwindow_focused = nullptr;
  334. Window *currently_dragged_subwindow = nullptr;
  335. SubWindowDrag subwindow_drag = SUB_WINDOW_DRAG_DISABLED;
  336. Vector2 subwindow_drag_from;
  337. Vector2 subwindow_drag_pos;
  338. Rect2i subwindow_drag_close_rect;
  339. bool subwindow_drag_close_inside = false;
  340. SubWindowResize subwindow_resize_mode;
  341. Rect2i subwindow_resize_from_rect;
  342. Vector<SubWindow> sub_windows; // Don't obtain references or pointers to the elements, as their location can change.
  343. } gui;
  344. DefaultCanvasItemTextureFilter default_canvas_item_texture_filter = DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
  345. DefaultCanvasItemTextureRepeat default_canvas_item_texture_repeat = DEFAULT_CANVAS_ITEM_TEXTURE_REPEAT_DISABLED;
  346. bool disable_input = false;
  347. bool disable_input_override = false;
  348. void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input);
  349. void _gui_call_notification(Control *p_control, int p_what);
  350. void _gui_sort_roots();
  351. Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform);
  352. void _gui_input_event(Ref<InputEvent> p_event);
  353. void _perform_drop(Control *p_control = nullptr);
  354. void _gui_cleanup_internal_state(Ref<InputEvent> p_event);
  355. void _push_unhandled_input_internal(const Ref<InputEvent> &p_event);
  356. Ref<InputEvent> _make_input_local(const Ref<InputEvent> &ev);
  357. friend class Control;
  358. List<Control *>::Element *_gui_add_root_control(Control *p_control);
  359. void _gui_remove_root_control(List<Control *>::Element *RI);
  360. String _gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Control **r_tooltip_owner = nullptr);
  361. void _gui_cancel_tooltip();
  362. void _gui_show_tooltip();
  363. void _gui_remove_control(Control *p_control);
  364. void _gui_hide_control(Control *p_control);
  365. void _gui_update_mouse_over();
  366. void _gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control);
  367. void _gui_set_drag_preview(Control *p_base, Control *p_control);
  368. Control *_gui_get_drag_preview();
  369. void _gui_remove_focus_for_window(Node *p_window);
  370. void _gui_unfocus_control(Control *p_control);
  371. bool _gui_control_has_focus(const Control *p_control);
  372. void _gui_control_grab_focus(Control *p_control);
  373. void _gui_grab_click_focus(Control *p_control);
  374. void _post_gui_grab_click_focus();
  375. void _gui_accept_event();
  376. bool _gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check);
  377. friend class CanvasLayer;
  378. void _canvas_layer_add(CanvasLayer *p_canvas_layer);
  379. void _canvas_layer_remove(CanvasLayer *p_canvas_layer);
  380. void _drop_mouse_over(Control *p_until_control = nullptr);
  381. void _drop_mouse_focus();
  382. void _drop_physics_mouseover(bool p_paused_only = false);
  383. void _update_canvas_items(Node *p_node);
  384. friend class Window;
  385. void _sub_window_update_order();
  386. void _sub_window_register(Window *p_window);
  387. void _sub_window_update(Window *p_window);
  388. void _sub_window_grab_focus(Window *p_window);
  389. void _sub_window_remove(Window *p_window);
  390. int _sub_window_find(Window *p_window) const;
  391. bool _sub_windows_forward_input(const Ref<InputEvent> &p_event);
  392. SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point);
  393. void _update_mouse_over();
  394. virtual void _update_mouse_over(Vector2 p_pos);
  395. virtual void _mouse_leave_viewport();
  396. virtual bool _can_consume_input_events() const { return true; }
  397. uint64_t event_count = 0;
  398. void _process_dirty_canvas_parent_orders();
  399. void _propagate_world_2d_changed(Node *p_node);
  400. void _window_start_drag(Window *p_window);
  401. void _window_start_resize(SubWindowResize p_edge, Window *p_window);
  402. protected:
  403. bool _set_size(const Size2i &p_size, const Size2 &p_size_2d_override, bool p_allocated);
  404. Size2i _get_size() const;
  405. Size2 _get_size_2d_override() const;
  406. bool _is_size_allocated() const;
  407. void _notification(int p_what);
  408. #if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
  409. void _process_picking();
  410. #endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
  411. static void _bind_methods();
  412. void _validate_property(PropertyInfo &p_property) const;
  413. public:
  414. void canvas_parent_mark_dirty(Node *p_node);
  415. void canvas_item_top_level_changed();
  416. uint64_t get_processed_events_count() const { return event_count; }
  417. void update_canvas_items();
  418. Rect2 get_visible_rect() const;
  419. RID get_viewport_rid() const;
  420. void set_world_2d(const Ref<World2D> &p_world_2d);
  421. Ref<World2D> get_world_2d() const;
  422. Ref<World2D> find_world_2d() const;
  423. void enable_canvas_transform_override(bool p_enable);
  424. bool is_canvas_transform_override_enabled() const;
  425. void set_canvas_transform_override(const Transform2D &p_transform);
  426. Transform2D get_canvas_transform_override() const;
  427. void set_canvas_transform(const Transform2D &p_transform);
  428. Transform2D get_canvas_transform() const;
  429. void set_global_canvas_transform(const Transform2D &p_transform);
  430. Transform2D get_global_canvas_transform() const;
  431. Transform2D get_stretch_transform() const;
  432. virtual Transform2D get_final_transform() const;
  433. void gui_set_root_order_dirty();
  434. void set_transparent_background(bool p_enable);
  435. bool has_transparent_background() const;
  436. void set_use_hdr_2d(bool p_enable);
  437. bool is_using_hdr_2d() const;
  438. Ref<ViewportTexture> get_texture() const;
  439. void set_positional_shadow_atlas_size(int p_size);
  440. int get_positional_shadow_atlas_size() const;
  441. void set_positional_shadow_atlas_16_bits(bool p_16_bits);
  442. bool get_positional_shadow_atlas_16_bits() const;
  443. void set_positional_shadow_atlas_quadrant_subdiv(int p_quadrant, PositionalShadowAtlasQuadrantSubdiv p_subdiv);
  444. PositionalShadowAtlasQuadrantSubdiv get_positional_shadow_atlas_quadrant_subdiv(int p_quadrant) const;
  445. void set_msaa_2d(MSAA p_msaa);
  446. MSAA get_msaa_2d() const;
  447. void set_msaa_3d(MSAA p_msaa);
  448. MSAA get_msaa_3d() const;
  449. void set_screen_space_aa(ScreenSpaceAA p_screen_space_aa);
  450. ScreenSpaceAA get_screen_space_aa() const;
  451. void set_use_taa(bool p_use_taa);
  452. bool is_using_taa() const;
  453. void set_scaling_3d_mode(Scaling3DMode p_scaling_3d_mode);
  454. Scaling3DMode get_scaling_3d_mode() const;
  455. void set_scaling_3d_scale(float p_scaling_3d_scale);
  456. float get_scaling_3d_scale() const;
  457. void set_fsr_sharpness(float p_fsr_sharpness);
  458. float get_fsr_sharpness() const;
  459. void set_texture_mipmap_bias(float p_texture_mipmap_bias);
  460. float get_texture_mipmap_bias() const;
  461. void set_anisotropic_filtering_level(AnisotropicFiltering p_anisotropic_filtering_level);
  462. AnisotropicFiltering get_anisotropic_filtering_level() const;
  463. void set_use_debanding(bool p_use_debanding);
  464. bool is_using_debanding() const;
  465. void set_mesh_lod_threshold(float p_pixels);
  466. float get_mesh_lod_threshold() const;
  467. void set_use_occlusion_culling(bool p_us_occlusion_culling);
  468. bool is_using_occlusion_culling() const;
  469. Vector2 get_camera_coords(const Vector2 &p_viewport_coords) const;
  470. Vector2 get_camera_rect_size() const;
  471. void push_text_input(const String &p_text);
  472. void push_input(const Ref<InputEvent> &p_event, bool p_local_coords = false);
  473. #ifndef DISABLE_DEPRECATED
  474. void push_unhandled_input(const Ref<InputEvent> &p_event, bool p_local_coords = false);
  475. #endif // DISABLE_DEPRECATED
  476. void notify_mouse_entered();
  477. void notify_mouse_exited();
  478. void set_disable_input(bool p_disable);
  479. bool is_input_disabled() const;
  480. void set_disable_input_override(bool p_disable);
  481. Vector2 get_mouse_position() const;
  482. void warp_mouse(const Vector2 &p_position);
  483. Point2 wrap_mouse_in_rect(const Vector2 &p_relative, const Rect2 &p_rect);
  484. virtual void update_mouse_cursor_state();
  485. #if !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
  486. void set_physics_object_picking(bool p_enable);
  487. bool get_physics_object_picking();
  488. void set_physics_object_picking_sort(bool p_enable);
  489. bool get_physics_object_picking_sort();
  490. void set_physics_object_picking_first_only(bool p_enable);
  491. bool get_physics_object_picking_first_only();
  492. #endif // !defined(PHYSICS_2D_DISABLED) || !defined(PHYSICS_3D_DISABLED)
  493. Variant gui_get_drag_data() const;
  494. void gui_reset_canvas_sort_index();
  495. int gui_get_canvas_sort_index();
  496. void gui_release_focus();
  497. Control *gui_get_focus_owner() const;
  498. Control *gui_get_hovered_control() const;
  499. PackedStringArray get_configuration_warnings() const override;
  500. void set_debug_draw(DebugDraw p_debug_draw);
  501. DebugDraw get_debug_draw() const;
  502. int get_render_info(RenderInfoType p_type, RenderInfo p_info);
  503. void set_snap_controls_to_pixels(bool p_enable);
  504. bool is_snap_controls_to_pixels_enabled() const;
  505. void set_snap_2d_transforms_to_pixel(bool p_enable);
  506. bool is_snap_2d_transforms_to_pixel_enabled() const;
  507. void set_snap_2d_vertices_to_pixel(bool p_enable);
  508. bool is_snap_2d_vertices_to_pixel_enabled() const;
  509. void set_input_as_handled();
  510. bool is_input_handled() const;
  511. void set_handle_input_locally(bool p_enable);
  512. bool is_handling_input_locally() const;
  513. bool gui_is_dragging() const;
  514. bool gui_is_drag_successful() const;
  515. void gui_cancel_drag();
  516. Control *gui_find_control(const Point2 &p_global);
  517. void set_sdf_oversize(SDFOversize p_sdf_oversize);
  518. SDFOversize get_sdf_oversize() const;
  519. void set_sdf_scale(SDFScale p_sdf_scale);
  520. SDFScale get_sdf_scale() const;
  521. void set_default_canvas_item_texture_filter(DefaultCanvasItemTextureFilter p_filter);
  522. DefaultCanvasItemTextureFilter get_default_canvas_item_texture_filter() const;
  523. void set_default_canvas_item_texture_repeat(DefaultCanvasItemTextureRepeat p_repeat);
  524. DefaultCanvasItemTextureRepeat get_default_canvas_item_texture_repeat() const;
  525. // VRS
  526. void set_vrs_mode(VRSMode p_vrs_mode);
  527. VRSMode get_vrs_mode() const;
  528. void set_vrs_update_mode(VRSUpdateMode p_vrs_update_mode);
  529. VRSUpdateMode get_vrs_update_mode() const;
  530. void set_vrs_texture(Ref<Texture2D> p_texture);
  531. Ref<Texture2D> get_vrs_texture() const;
  532. virtual DisplayServer::WindowID get_window_id() const = 0;
  533. void set_embedding_subwindows(bool p_embed);
  534. bool is_embedding_subwindows() const;
  535. TypedArray<Window> get_embedded_subwindows() const;
  536. void subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect);
  537. Rect2i subwindow_get_popup_safe_rect(Window *p_window) const;
  538. Viewport *get_parent_viewport() const;
  539. Window *get_base_window();
  540. void set_canvas_cull_mask(uint32_t p_layers);
  541. uint32_t get_canvas_cull_mask() const;
  542. void set_canvas_cull_mask_bit(uint32_t p_layer, bool p_enable);
  543. bool get_canvas_cull_mask_bit(uint32_t p_layer) const;
  544. #ifdef TOOLS_ENABLED
  545. bool is_visible_subviewport() const;
  546. #endif // TOOLS_ENABLED
  547. virtual bool is_size_2d_override_stretch_enabled() const { return true; }
  548. Transform2D get_screen_transform() const;
  549. virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const;
  550. virtual Transform2D get_popup_base_transform() const { return Transform2D(); }
  551. virtual Viewport *get_section_root_viewport() const { return nullptr; }
  552. virtual bool is_attached_in_viewport() const { return false; }
  553. virtual bool is_sub_viewport() const { return false; }
  554. private:
  555. // 2D audio, camera, and physics. (don't put World2D here because World2D is needed for Control nodes).
  556. friend class AudioListener2D; // Needs _audio_listener_2d_set and _audio_listener_2d_remove
  557. AudioListener2D *audio_listener_2d = nullptr;
  558. void _audio_listener_2d_set(AudioListener2D *p_audio_listener);
  559. void _audio_listener_2d_remove(AudioListener2D *p_audio_listener);
  560. bool is_audio_listener_2d_enabled = false;
  561. RID internal_audio_listener_2d;
  562. friend class Camera2D; // Needs _camera_2d_set
  563. Camera2D *camera_2d = nullptr;
  564. void _camera_2d_set(Camera2D *p_camera_2d);
  565. #ifndef PHYSICS_2D_DISABLED
  566. // Collider to frame
  567. HashMap<ObjectID, uint64_t> physics_2d_mouseover;
  568. // Collider & shape to frame
  569. HashMap<Pair<ObjectID, int>, uint64_t, PairHash<ObjectID, int>> physics_2d_shape_mouseover;
  570. // Cleans up colliders corresponding to old frames or all of them.
  571. void _cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference = 0);
  572. #endif // PHYSICS_2D_DISABLED
  573. public:
  574. AudioListener2D *get_audio_listener_2d() const;
  575. void set_as_audio_listener_2d(bool p_enable);
  576. bool is_audio_listener_2d() const;
  577. Camera2D *get_camera_2d() const;
  578. void assign_next_enabled_camera_2d(const StringName &p_camera_group);
  579. #ifndef _3D_DISABLED
  580. private:
  581. // 3D audio, camera, physics, and world.
  582. bool use_xr = false;
  583. friend class AudioListener3D;
  584. AudioListener3D *audio_listener_3d = nullptr;
  585. HashSet<AudioListener3D *> audio_listener_3d_set;
  586. bool is_audio_listener_3d_enabled = false;
  587. RID internal_audio_listener_3d;
  588. void _update_audio_listener_3d();
  589. void _listener_transform_3d_changed_notify();
  590. void _audio_listener_3d_set(AudioListener3D *p_listener);
  591. bool _audio_listener_3d_add(AudioListener3D *p_listener); //true if first
  592. void _audio_listener_3d_remove(AudioListener3D *p_listener);
  593. void _audio_listener_3d_make_next_current(AudioListener3D *p_exclude);
  594. #ifndef PHYSICS_3D_DISABLED
  595. void _collision_object_3d_input_event(CollisionObject3D *p_object, Camera3D *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape);
  596. #endif // PHYSICS_3D_DISABLED
  597. struct Camera3DOverrideData {
  598. Transform3D transform;
  599. enum Projection {
  600. PROJECTION_PERSPECTIVE,
  601. PROJECTION_ORTHOGONAL
  602. };
  603. Projection projection = Projection::PROJECTION_PERSPECTIVE;
  604. real_t fov = 0.0;
  605. real_t size = 0.0;
  606. real_t z_near = 0.0;
  607. real_t z_far = 0.0;
  608. RID rid;
  609. operator bool() const {
  610. return rid != RID();
  611. }
  612. } camera_3d_override;
  613. friend class Camera3D;
  614. Camera3D *camera_3d = nullptr;
  615. HashSet<Camera3D *> camera_3d_set;
  616. void _camera_3d_transform_changed_notify();
  617. void _camera_3d_set(Camera3D *p_camera);
  618. bool _camera_3d_add(Camera3D *p_camera); //true if first
  619. void _camera_3d_remove(Camera3D *p_camera);
  620. void _camera_3d_make_next_current(Camera3D *p_exclude);
  621. Ref<World3D> world_3d;
  622. Ref<World3D> own_world_3d;
  623. void _own_world_3d_changed();
  624. void _propagate_enter_world_3d(Node *p_node);
  625. void _propagate_exit_world_3d(Node *p_node);
  626. public:
  627. AudioListener3D *get_audio_listener_3d() const;
  628. void set_as_audio_listener_3d(bool p_enable);
  629. bool is_audio_listener_3d() const;
  630. Camera3D *get_camera_3d() const;
  631. void enable_camera_3d_override(bool p_enable);
  632. bool is_camera_3d_override_enabled() const;
  633. void set_camera_3d_override_transform(const Transform3D &p_transform);
  634. Transform3D get_camera_3d_override_transform() const;
  635. void set_camera_3d_override_perspective(real_t p_fovy_degrees, real_t p_z_near, real_t p_z_far);
  636. void set_camera_3d_override_orthogonal(real_t p_size, real_t p_z_near, real_t p_z_far);
  637. HashMap<StringName, real_t> get_camera_3d_override_properties() const;
  638. Vector3 camera_3d_override_project_ray_normal(const Point2 &p_pos) const;
  639. Vector3 camera_3d_override_project_ray_origin(const Point2 &p_pos) const;
  640. Vector3 camera_3d_override_project_local_ray_normal(const Point2 &p_pos) const;
  641. void set_disable_3d(bool p_disable);
  642. bool is_3d_disabled() const;
  643. void set_world_3d(const Ref<World3D> &p_world_3d);
  644. Ref<World3D> get_world_3d() const;
  645. Ref<World3D> find_world_3d() const;
  646. void set_use_own_world_3d(bool p_use_own_world_3d);
  647. bool is_using_own_world_3d() const;
  648. void set_use_xr(bool p_use_xr);
  649. bool is_using_xr();
  650. #endif // _3D_DISABLED
  651. Viewport();
  652. ~Viewport();
  653. };
  654. class SubViewport : public Viewport {
  655. GDCLASS(SubViewport, Viewport);
  656. public:
  657. enum ClearMode {
  658. CLEAR_MODE_ALWAYS,
  659. CLEAR_MODE_NEVER,
  660. CLEAR_MODE_ONCE
  661. };
  662. enum UpdateMode {
  663. UPDATE_DISABLED,
  664. UPDATE_ONCE, //then goes to disabled
  665. UPDATE_WHEN_VISIBLE, // default
  666. UPDATE_WHEN_PARENT_VISIBLE,
  667. UPDATE_ALWAYS
  668. };
  669. private:
  670. UpdateMode update_mode = UPDATE_WHEN_VISIBLE;
  671. ClearMode clear_mode = CLEAR_MODE_ALWAYS;
  672. bool size_2d_override_stretch = false;
  673. void _internal_set_size(const Size2i &p_size, bool p_force = false);
  674. protected:
  675. static void _bind_methods();
  676. virtual DisplayServer::WindowID get_window_id() const override;
  677. void _notification(int p_what);
  678. public:
  679. void set_size(const Size2i &p_size);
  680. Size2i get_size() const;
  681. void set_size_force(const Size2i &p_size);
  682. void set_size_2d_override(const Size2i &p_size);
  683. Size2i get_size_2d_override() const;
  684. void set_size_2d_override_stretch(bool p_enable);
  685. bool is_size_2d_override_stretch_enabled() const override;
  686. void set_update_mode(UpdateMode p_mode);
  687. UpdateMode get_update_mode() const;
  688. void set_clear_mode(ClearMode p_mode);
  689. ClearMode get_clear_mode() const;
  690. virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const override;
  691. virtual Transform2D get_popup_base_transform() const override;
  692. virtual Viewport *get_section_root_viewport() const override;
  693. virtual bool is_attached_in_viewport() const override;
  694. virtual bool is_sub_viewport() const override { return true; }
  695. void _validate_property(PropertyInfo &p_property) const;
  696. SubViewport();
  697. ~SubViewport();
  698. };
  699. VARIANT_ENUM_CAST(Viewport::Scaling3DMode);
  700. VARIANT_ENUM_CAST(SubViewport::UpdateMode);
  701. VARIANT_ENUM_CAST(Viewport::PositionalShadowAtlasQuadrantSubdiv);
  702. VARIANT_ENUM_CAST(Viewport::MSAA);
  703. VARIANT_ENUM_CAST(Viewport::AnisotropicFiltering);
  704. VARIANT_ENUM_CAST(Viewport::ScreenSpaceAA);
  705. VARIANT_ENUM_CAST(Viewport::DebugDraw);
  706. VARIANT_ENUM_CAST(Viewport::SDFScale);
  707. VARIANT_ENUM_CAST(Viewport::SDFOversize);
  708. VARIANT_ENUM_CAST(Viewport::VRSMode);
  709. VARIANT_ENUM_CAST(Viewport::VRSUpdateMode);
  710. VARIANT_ENUM_CAST(SubViewport::ClearMode);
  711. VARIANT_ENUM_CAST(Viewport::RenderInfo);
  712. VARIANT_ENUM_CAST(Viewport::RenderInfoType);
  713. VARIANT_ENUM_CAST(Viewport::DefaultCanvasItemTextureFilter);
  714. VARIANT_ENUM_CAST(Viewport::DefaultCanvasItemTextureRepeat);