viewport.h 27 KB

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