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