.. Generated automatically by doc/tools/makerst.py in Godot's source tree.
.. DO NOT EDIT THIS FILE, but the Viewport.xml source instead.
.. The source is found in doc/classes or modules/<name>/doc_classes.

.. _class_Viewport:

Viewport
========

**Inherits:** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`

**Category:** Core

Brief Description
-----------------

Creates a sub-view into the screen.

Member Functions
----------------

+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`World<class_world>`                      | :ref:`find_world<class_Viewport_find_world>` **(** **)** const                                                                                                                                                    |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`World2D<class_world2d>`                  | :ref:`find_world_2d<class_Viewport_find_world_2d>` **(** **)** const                                                                                                                                              |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Camera<class_camera>`                    | :ref:`get_camera<class_Viewport_get_camera>` **(** **)** const                                                                                                                                                    |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Transform2D<class_transform2d>`          | :ref:`get_final_transform<class_Viewport_get_final_transform>` **(** **)** const                                                                                                                                  |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_vector2>`                  | :ref:`get_mouse_position<class_Viewport_get_mouse_position>` **(** **)** const                                                                                                                                    |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>`                          | :ref:`get_render_info<class_Viewport_get_render_info>` **(** :ref:`int<class_int>` info **)**                                                                                                                     |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2<class_vector2>`                  | :ref:`get_size_override<class_Viewport_get_size_override>` **(** **)** const                                                                                                                                      |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`ViewportTexture<class_viewporttexture>`  | :ref:`get_texture<class_Viewport_get_texture>` **(** **)** const                                                                                                                                                  |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`RID<class_rid>`                          | :ref:`get_viewport_rid<class_Viewport_get_viewport_rid>` **(** **)** const                                                                                                                                        |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Rect2<class_rect2>`                      | :ref:`get_visible_rect<class_Viewport_get_visible_rect>` **(** **)** const                                                                                                                                        |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Variant<class_variant>`                  | :ref:`gui_get_drag_data<class_Viewport_gui_get_drag_data>` **(** **)** const                                                                                                                                      |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>`                        | :ref:`gui_has_modal_stack<class_Viewport_gui_has_modal_stack>` **(** **)** const                                                                                                                                  |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void                                           | :ref:`input<class_Viewport_input>` **(** :ref:`InputEvent<class_inputevent>` local_event **)**                                                                                                                    |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>`                        | :ref:`is_size_override_enabled<class_Viewport_is_size_override_enabled>` **(** **)** const                                                                                                                        |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>`                        | :ref:`is_size_override_stretch_enabled<class_Viewport_is_size_override_stretch_enabled>` **(** **)** const                                                                                                        |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void                                           | :ref:`set_attach_to_screen_rect<class_Viewport_set_attach_to_screen_rect>` **(** :ref:`Rect2<class_rect2>` rect **)**                                                                                             |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void                                           | :ref:`set_size_override<class_Viewport_set_size_override>` **(** :ref:`bool<class_bool>` enable, :ref:`Vector2<class_vector2>` size=Vector2( -1, -1 ), :ref:`Vector2<class_vector2>` margin=Vector2( 0, 0 ) **)** |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void                                           | :ref:`set_size_override_stretch<class_Viewport_set_size_override_stretch>` **(** :ref:`bool<class_bool>` enabled **)**                                                                                            |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void                                           | :ref:`unhandled_input<class_Viewport_unhandled_input>` **(** :ref:`InputEvent<class_inputevent>` local_event **)**                                                                                                |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void                                           | :ref:`update_worlds<class_Viewport_update_worlds>` **(** **)**                                                                                                                                                    |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void                                           | :ref:`warp_mouse<class_Viewport_warp_mouse>` **(** :ref:`Vector2<class_vector2>` to_position **)**                                                                                                                |
+------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Signals
-------

.. _class_Viewport_size_changed:

- **size_changed** **(** **)**

Emitted when the size of the viewport is changed, whether by :ref:`set_size_override<class_Viewport_set_size_override>`, resize of window, or some other means.


Member Variables
----------------

  .. _class_Viewport_arvr:

- :ref:`bool<class_bool>` **arvr** - If ``true`` the viewport will be used in AR/VR process. Default value: ``false``.

  .. _class_Viewport_audio_listener_enable_2d:

- :ref:`bool<class_bool>` **audio_listener_enable_2d** - If ``true`` the viewport will process 2D audio streams. Default value: ``false``.

  .. _class_Viewport_audio_listener_enable_3d:

- :ref:`bool<class_bool>` **audio_listener_enable_3d** - If ``true`` the viewport will process 3D audio streams. Default value: ``false``.

  .. _class_Viewport_canvas_transform:

- :ref:`Transform2D<class_transform2d>` **canvas_transform** - The canvas transform of the viewport, useful for changing the on-screen positions of all child :ref:`CanvasItem<class_canvasitem>`\ s. This is relative to the global canvas transform of the viewport.

  .. _class_Viewport_debug_draw:

- :ref:`DebugDraw<enum_viewport_debugdraw>` **debug_draw** - The overlay mode for test rendered geometry in debug purposes. Default value: ``DEBUG_DRAW_DISABLED``.

  .. _class_Viewport_disable_3d:

- :ref:`bool<class_bool>` **disable_3d** - If ``true`` the viewport will disable 3D rendering. For actual disabling use ``usage``. Default value: ``false``.

  .. _class_Viewport_global_canvas_transform:

- :ref:`Transform2D<class_transform2d>` **global_canvas_transform** - The global canvas transform of the viewport. The canvas transform is relative to this.

  .. _class_Viewport_gui_disable_input:

- :ref:`bool<class_bool>` **gui_disable_input** - If ``true`` the viewport will not receive input event. Default value: ``false``.

  .. _class_Viewport_gui_snap_controls_to_pixels:

- :ref:`bool<class_bool>` **gui_snap_controls_to_pixels** - If ``true`` the GUI controls on the viewport will lay pixel perfectly. Default value: ``true``.

  .. _class_Viewport_hdr:

- :ref:`bool<class_bool>` **hdr** - If ``true`` the viewport rendering will receive benefits from High Dynamic Range algorithm. Default value: ``true``.

  .. _class_Viewport_msaa:

- :ref:`MSAA<enum_viewport_msaa>` **msaa** - The multisample anti-aliasing mode. Default value: ``MSAA_DISABLED``.

  .. _class_Viewport_own_world:

- :ref:`bool<class_bool>` **own_world** - If ``true`` the viewport will use :ref:`World<class_world>` defined in ``world`` property. Default value: ``false``.

  .. _class_Viewport_physics_object_picking:

- :ref:`bool<class_bool>` **physics_object_picking** - If ``true`` the objects rendered by viewport become subjects of mouse picking process. Default value: ``false``.

  .. _class_Viewport_render_target_clear_mode:

- :ref:`ClearMode<enum_viewport_clearmode>` **render_target_clear_mode** - The clear mode when viewport used as a render target. Default value: ``CLEAR_MODE_ALWAYS``.

  .. _class_Viewport_render_target_update_mode:

- :ref:`UpdateMode<enum_viewport_updatemode>` **render_target_update_mode** - The update mode when viewport used as a render target. Default value: ``UPDATE_WHEN_VISIBLE``.

  .. _class_Viewport_render_target_v_flip:

- :ref:`bool<class_bool>` **render_target_v_flip** - If ``true`` the result of rendering will be flipped vertically. Default value: ``false``.

  .. _class_Viewport_shadow_atlas_quad_0:

- :ref:`ShadowAtlasQuadrantSubdiv<enum_viewport_shadowatlasquadrantsubdiv>` **shadow_atlas_quad_0** - The subdivision amount of first quadrant on shadow atlas. Default value: ``SHADOW_ATLAS_QUADRANT_SUBDIV_4``.

  .. _class_Viewport_shadow_atlas_quad_1:

- :ref:`ShadowAtlasQuadrantSubdiv<enum_viewport_shadowatlasquadrantsubdiv>` **shadow_atlas_quad_1** - The subdivision amount of second quadrant on shadow atlas. Default value: ``SHADOW_ATLAS_QUADRANT_SUBDIV_4``.

  .. _class_Viewport_shadow_atlas_quad_2:

- :ref:`ShadowAtlasQuadrantSubdiv<enum_viewport_shadowatlasquadrantsubdiv>` **shadow_atlas_quad_2** - The subdivision amount of third quadrant on shadow atlas. Default value: ``SHADOW_ATLAS_QUADRANT_SUBDIV_16``.

  .. _class_Viewport_shadow_atlas_quad_3:

- :ref:`ShadowAtlasQuadrantSubdiv<enum_viewport_shadowatlasquadrantsubdiv>` **shadow_atlas_quad_3** - The subdivision amount of fourth quadrant on shadow atlas. Default value: ``SHADOW_ATLAS_QUADRANT_SUBDIV_64``.

  .. _class_Viewport_shadow_atlas_size:

- :ref:`int<class_int>` **shadow_atlas_size** - The resolution of shadow atlas. Both width and height is equal to one value.

  .. _class_Viewport_size:

- :ref:`Vector2<class_vector2>` **size** - The width and height of viewport.

  .. _class_Viewport_transparent_bg:

- :ref:`bool<class_bool>` **transparent_bg** - If ``true`` the viewport should render its background as transparent. Default value: ``false``.

  .. _class_Viewport_usage:

- :ref:`Usage<enum_viewport_usage>` **usage** - The rendering mode of viewport. Default value: ``USAGE_3D``.

  .. _class_Viewport_world:

- :ref:`World<class_world>` **world** - The custom :ref:`World<class_world>` which can be used as 3D environment source.

  .. _class_Viewport_world_2d:

- :ref:`World2D<class_world2d>` **world_2d** - The custom :ref:`World2D<class_world2d>` which can be used as 2D environment source.


Enums
-----

  .. _enum_Viewport_UpdateMode:

enum **UpdateMode**

- **UPDATE_DISABLED** = **0** --- Do not update the render target.
- **UPDATE_ONCE** = **1** --- Update the render target once, then switch to ``UPDATE_DISABLED``
- **UPDATE_WHEN_VISIBLE** = **2** --- Update the render target only when it is visible. This is the default value.
- **UPDATE_ALWAYS** = **3** --- Always update the render target.

  .. _enum_Viewport_RenderInfo:

enum **RenderInfo**

- **RENDER_INFO_OBJECTS_IN_FRAME** = **0** --- Amount of objects in frame.
- **RENDER_INFO_VERTICES_IN_FRAME** = **1** --- Amount of vertices in frame.
- **RENDER_INFO_MATERIAL_CHANGES_IN_FRAME** = **2** --- Amount of material changes in frame.
- **RENDER_INFO_SHADER_CHANGES_IN_FRAME** = **3** --- Amount of shader changes in frame.
- **RENDER_INFO_SURFACE_CHANGES_IN_FRAME** = **4** --- Amount of surface changes in frame.
- **RENDER_INFO_DRAW_CALLS_IN_FRAME** = **5** --- Amount of draw calls in frame.
- **RENDER_INFO_MAX** = **6** --- Enum limiter. Do not use it directly.

  .. _enum_Viewport_MSAA:

enum **MSAA**

- **MSAA_DISABLED** = **0** --- Multisample anti-aliasing mode disabled. This is the default value.
- **MSAA_2X** = **1**
- **MSAA_4X** = **2**
- **MSAA_8X** = **3**
- **MSAA_16X** = **4**

  .. _enum_Viewport_ClearMode:

enum **ClearMode**

- **CLEAR_MODE_ALWAYS** = **0**
- **CLEAR_MODE_NEVER** = **1**
- **CLEAR_MODE_ONLY_NEXT_FRAME** = **2**

  .. _enum_Viewport_Usage:

enum **Usage**

- **USAGE_2D** = **0**
- **USAGE_2D_NO_SAMPLING** = **1**
- **USAGE_3D** = **2**
- **USAGE_3D_NO_EFFECTS** = **3**

  .. _enum_Viewport_DebugDraw:

enum **DebugDraw**

- **DEBUG_DRAW_DISABLED** = **0** --- Objects are displayed normally.
- **DEBUG_DRAW_UNSHADED** = **1** --- Objects are displayed without light information.
- **DEBUG_DRAW_OVERDRAW** = **2**
- **DEBUG_DRAW_WIREFRAME** = **3** --- Objects are displayed in wireframe style.

  .. _enum_Viewport_ShadowAtlasQuadrantSubdiv:

enum **ShadowAtlasQuadrantSubdiv**

- **SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED** = **0**
- **SHADOW_ATLAS_QUADRANT_SUBDIV_1** = **1**
- **SHADOW_ATLAS_QUADRANT_SUBDIV_4** = **2**
- **SHADOW_ATLAS_QUADRANT_SUBDIV_16** = **3**
- **SHADOW_ATLAS_QUADRANT_SUBDIV_64** = **4**
- **SHADOW_ATLAS_QUADRANT_SUBDIV_256** = **5**
- **SHADOW_ATLAS_QUADRANT_SUBDIV_1024** = **6**
- **SHADOW_ATLAS_QUADRANT_SUBDIV_MAX** = **7** --- Enum limiter. Do not use it directly.


Description
-----------

A Viewport creates a different view into the screen, or a sub-view inside another viewport. Children 2D Nodes will display on it, and children Camera 3D nodes will render on it too.

Optionally, a viewport can have its own 2D or 3D world, so they don't share what they draw with other viewports.

If a viewport is a child of a :ref:`Control<class_control>`, it will automatically take up its same rect and position, otherwise they must be set manually.

Viewports can also choose to be audio listeners, so they generate positional audio depending on a 2D or 3D camera child of it.

Also, viewports can be assigned to different screens in case the devices have multiple screens.

Finally, viewports can also behave as render targets, in which case they will not be visible unless the associated texture is used to draw.

Member Function Description
---------------------------

.. _class_Viewport_find_world:

- :ref:`World<class_world>` **find_world** **(** **)** const

Return the 3D world of the viewport, or if no such present, the one of the parent viewport.

.. _class_Viewport_find_world_2d:

- :ref:`World2D<class_world2d>` **find_world_2d** **(** **)** const

Return the 2D world of the viewport.

.. _class_Viewport_get_camera:

- :ref:`Camera<class_camera>` **get_camera** **(** **)** const

Return the active 3D camera.

.. _class_Viewport_get_final_transform:

- :ref:`Transform2D<class_transform2d>` **get_final_transform** **(** **)** const

Get the total transform of the viewport.

.. _class_Viewport_get_mouse_position:

- :ref:`Vector2<class_vector2>` **get_mouse_position** **(** **)** const

Get the mouse position, relative to the viewport.

.. _class_Viewport_get_render_info:

- :ref:`int<class_int>` **get_render_info** **(** :ref:`int<class_int>` info **)**

Get the specific information about the viewport from rendering pipeline.

.. _class_Viewport_get_size_override:

- :ref:`Vector2<class_vector2>` **get_size_override** **(** **)** const

Get the size override set with :ref:`set_size_override<class_Viewport_set_size_override>`.

.. _class_Viewport_get_texture:

- :ref:`ViewportTexture<class_viewporttexture>` **get_texture** **(** **)** const

Get the viewport's texture, for use with various objects that you want to texture with the viewport.

.. _class_Viewport_get_viewport_rid:

- :ref:`RID<class_rid>` **get_viewport_rid** **(** **)** const

Get the viewport RID from the :ref:`VisualServer<class_visualserver>`.

.. _class_Viewport_get_visible_rect:

- :ref:`Rect2<class_rect2>` **get_visible_rect** **(** **)** const

Return the final, visible rect in global screen coordinates.

.. _class_Viewport_gui_get_drag_data:

- :ref:`Variant<class_variant>` **gui_get_drag_data** **(** **)** const

Returns the drag data from the GUI, that was previously returned by :ref:`Control.get_drag_data<class_Control_get_drag_data>`.

.. _class_Viewport_gui_has_modal_stack:

- :ref:`bool<class_bool>` **gui_has_modal_stack** **(** **)** const

Returns whether there are shown modals on-screen.

.. _class_Viewport_input:

- void **input** **(** :ref:`InputEvent<class_inputevent>` local_event **)**

.. _class_Viewport_is_size_override_enabled:

- :ref:`bool<class_bool>` **is_size_override_enabled** **(** **)** const

Get the enabled status of the size override set with :ref:`set_size_override<class_Viewport_set_size_override>`.

.. _class_Viewport_is_size_override_stretch_enabled:

- :ref:`bool<class_bool>` **is_size_override_stretch_enabled** **(** **)** const

Get the enabled status of the size stretch override set with :ref:`set_size_override_stretch<class_Viewport_set_size_override_stretch>`.

.. _class_Viewport_set_attach_to_screen_rect:

- void **set_attach_to_screen_rect** **(** :ref:`Rect2<class_rect2>` rect **)**

.. _class_Viewport_set_size_override:

- void **set_size_override** **(** :ref:`bool<class_bool>` enable, :ref:`Vector2<class_vector2>` size=Vector2( -1, -1 ), :ref:`Vector2<class_vector2>` margin=Vector2( 0, 0 ) **)**

Set the size override of the viewport. If the enable parameter is true, it would use the override, otherwise it would use the default size. If the size parameter is equal to ``(-1, -1)``, it won't update the size.

.. _class_Viewport_set_size_override_stretch:

- void **set_size_override_stretch** **(** :ref:`bool<class_bool>` enabled **)**

Set whether the size override affects stretch as well.

.. _class_Viewport_unhandled_input:

- void **unhandled_input** **(** :ref:`InputEvent<class_inputevent>` local_event **)**

.. _class_Viewport_update_worlds:

- void **update_worlds** **(** **)**

Force update of the 2D and 3D worlds.

.. _class_Viewport_warp_mouse:

- void **warp_mouse** **(** :ref:`Vector2<class_vector2>` to_position **)**

Warp the mouse to a position, relative to the viewport.


