viewport.h 27 KB

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