Creates a sub-view into the screen.
    public class Viewport : Node

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 ViewportContainer, it will automatically take up its size, otherwise it 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.

Inheritance Chain

Constructors

    public Viewport()

Signals

    "size_changed" ()

Emitted when the size of the viewport is changed, whether by SetSizeOverride(bool, Godot.Vector2?, Godot.Vector2?), resize of window, or some other means.

Properties

    public bool Arvr { get; set; }

If true, the viewport will be used in AR/VR process.

    public bool AudioListenerEnable2d { get; set; }

If true, the viewport will process 2D audio streams.

    public bool AudioListenerEnable3d { get; set; }

If true, the viewport will process 3D audio streams.

    public Transform2D CanvasTransform { get; set; }

The canvas transform of the viewport, useful for changing the on-screen positions of all child CanvasItems. This is relative to the global canvas transform of the viewport.

    public DebugDrawEnum DebugDraw { get; set; }

The overlay mode for test rendered geometry in debug purposes.

    public bool Disable3d { get; set; }

If true, the viewport will disable 3D rendering. For actual disabling use usage.

    public Transform2D GlobalCanvasTransform { get; set; }

The global canvas transform of the viewport. The canvas transform is relative to this.

    public bool GuiDisableInput { get; set; }

If true, the viewport will not receive input event.

    public bool GuiSnapControlsToPixels { get; set; }

If true, the GUI controls on the viewport will lay pixel perfectly.

    public bool HandleInputLocally { get; set; }

    public bool Hdr { get; set; }

If true, the viewport rendering will receive benefits from High Dynamic Range algorithm.

    public bool Keep3dLinear { get; set; }

If true, the result after 3D rendering will not have a linear to sRGB color conversion applied. This is important when the viewport is used as a render target where the result is used as a texture on a 3D object rendered in another viewport. It is also important if the viewport is used to create data that is not color based (noise, heightmaps, pickmaps, etc.). Do not enable this when the viewport is used as a texture on a 2D object or if the viewport is your final output.

    public MSAA Msaa { get; set; }

The multisample anti-aliasing mode.

    public bool OwnWorld { get; set; }

If true, the viewport will use World defined in world property.

    public bool PhysicsObjectPicking { get; set; }

If true, the objects rendered by viewport become subjects of mouse picking process.

    public bool RenderDirectToScreen { get; set; }

If true, renders the Viewport directly to the screen instead of to the root viewport. Only available in GLES2. This is a low-level optimization and should not be used in most cases. If used, reading from the Viewport or from SCREEN_TEXTURE becomes unavailable. For more information see VisualServer.ViewportSetRenderDirectToScreen(Godot.RID, bool).

    public ClearMode RenderTargetClearMode { get; set; }

The clear mode when viewport used as a render target.

    public UpdateMode RenderTargetUpdateMode { get; set; }

The update mode when viewport used as a render target.

    public bool RenderTargetVFlip { get; set; }

If true, the result of rendering will be flipped vertically.

    public ShadowAtlasQuadrantSubdiv ShadowAtlasQuad0 { get; set; }

The subdivision amount of first quadrant on shadow atlas.

    public ShadowAtlasQuadrantSubdiv ShadowAtlasQuad1 { get; set; }

The subdivision amount of second quadrant on shadow atlas.

    public ShadowAtlasQuadrantSubdiv ShadowAtlasQuad2 { get; set; }

The subdivision amount of third quadrant on shadow atlas.

    public ShadowAtlasQuadrantSubdiv ShadowAtlasQuad3 { get; set; }

The subdivision amount of fourth quadrant on shadow atlas.

    public int ShadowAtlasSize { get; set; }

The shadow atlas’ resolution (used for omni and spot lights). The value will be rounded up to the nearest power of 2.

Note: If this is set to 0, shadows won’t be visible. Since user-created viewports default to a value of 0, this value must be set above 0 manually.

    public Vector2 Size { get; set; }

The width and height of viewport.

    public bool SizeOverrideStretch { get; set; }

If true, the size override affects stretch as well.

    public bool TransparentBg { get; set; }

If true, the viewport should render its background as transparent.

    public UsageEnum Usage { get; set; }

The rendering mode of viewport.

    public World World { get; set; }

The custom World which can be used as 3D environment source.

    public World2D World2d { get; set; }

The custom World2D which can be used as 2D environment source.

Methods

    public World FindWorld()

Returns the 3D world of the viewport, or if none the world of the parent viewport.

    public World2D FindWorld2d()

Returns the 2D world of the viewport.

    public Camera GetCamera()

Returns the active 3D camera.

    [Obsolete("GetCanvasTransform is deprecated. Use the CanvasTransform property instead.")]
    public Transform2D GetCanvasTransform()

Getter for CanvasTransform

    [Obsolete("GetClearMode is deprecated. Use the RenderTargetClearMode property instead.")]
    public ClearMode GetClearMode()

Getter for RenderTargetClearMode

    [Obsolete("GetDebugDraw is deprecated. Use the DebugDraw property instead.")]
    public DebugDrawEnum GetDebugDraw()

Getter for DebugDraw

    public Transform2D GetFinalTransform()

Returns the total transform of the viewport.

    [Obsolete("GetGlobalCanvasTransform is deprecated. Use the GlobalCanvasTransform property instead.")]
    public Transform2D GetGlobalCanvasTransform()

Getter for GlobalCanvasTransform

    [Obsolete("GetHdr is deprecated. Use the Hdr property instead.")]
    public bool GetHdr()

Getter for Hdr

    [Obsolete("GetKeep3dLinear is deprecated. Use the Keep3dLinear property instead.")]
    public bool GetKeep3dLinear()

Getter for Keep3dLinear

    public Control GetModalStackTop()

Returns the topmost modal in the stack.

    public Vector2 GetMousePosition()

Returns the mouse position relative to the viewport.

    [Obsolete("GetMsaa is deprecated. Use the Msaa property instead.")]
    public MSAA GetMsaa()

Getter for Msaa

    [Obsolete("GetPhysicsObjectPicking is deprecated. Use the PhysicsObjectPicking property instead.")]
    public bool GetPhysicsObjectPicking()

Getter for PhysicsObjectPicking

    public int GetRenderInfo(RenderInfo info)

Returns information about the viewport from the rendering pipeline.

    [Obsolete("GetShadowAtlasQuadrantSubdiv is deprecated. Use the ShadowAtlasQuad3 property instead.")]
    public ShadowAtlasQuadrantSubdiv GetShadowAtlasQuadrantSubdiv(int quadrant)

    [Obsolete("GetShadowAtlasSize is deprecated. Use the ShadowAtlasSize property instead.")]
    public int GetShadowAtlasSize()

Getter for ShadowAtlasSize

    [Obsolete("GetSize is deprecated. Use the Size property instead.")]
    public Vector2 GetSize()

Getter for Size

    public Vector2 GetSizeOverride()

Returns the size override set with SetSizeOverride(bool, Godot.Vector2?, Godot.Vector2?).

    public ViewportTexture GetTexture()

Returns the viewport’s texture.

Note: Due to the way OpenGL works, the resulting ViewportTexture is flipped vertically. You can use Image.FlipY() on the result of Texture.GetData() to flip it back, for example:

[codeblock]

var img = get_viewport().get_texture().get_data()

img.flip_y()

[/codeblock]

    [Obsolete("GetUpdateMode is deprecated. Use the RenderTargetUpdateMode property instead.")]
    public UpdateMode GetUpdateMode()

Getter for RenderTargetUpdateMode

    [Obsolete("GetUsage is deprecated. Use the Usage property instead.")]
    public UsageEnum GetUsage()

Getter for Usage

    [Obsolete("GetVflip is deprecated. Use the RenderTargetVFlip property instead.")]
    public bool GetVflip()

Getter for RenderTargetVFlip

    public RID GetViewportRid()

Returns the viewport’s RID from the VisualServer.

    public Rect2 GetVisibleRect()

Returns the visible rectangle in global screen coordinates.

    [Obsolete("GetWorld is deprecated. Use the World property instead.")]
    public World GetWorld()

Getter for World

    [Obsolete("GetWorld2d is deprecated. Use the World2d property instead.")]
    public World2D GetWorld2d()

Getter for World2d

    public object GuiGetDragData()

Returns the drag data from the GUI, that was previously returned by Control.GetDragData(Godot.Vector2).

    public bool GuiHasModalStack()

Returns true if there are visible modals on-screen.

    public bool GuiIsDragging()

    [Obsolete("HasTransparentBackground is deprecated. Use the TransparentBg property instead.")]
    public bool HasTransparentBackground()

Getter for TransparentBg

    public void Input(InputEvent localEvent)

    [Obsolete("Is3dDisabled is deprecated. Use the Disable3d property instead.")]
    public bool Is3dDisabled()

Getter for DebugDrawEnum.Disabled

    [Obsolete("IsAudioListener is deprecated. Use the AudioListenerEnable3d property instead.")]
    public bool IsAudioListener()

Getter for AudioListenerEnable2d

    [Obsolete("IsAudioListener2d is deprecated. Use the AudioListenerEnable2d property instead.")]
    public bool IsAudioListener2d()

Getter for AudioListenerEnable2d

    [Obsolete("IsHandlingInputLocally is deprecated. Use the HandleInputLocally property instead.")]
    public bool IsHandlingInputLocally()

Getter for HandleInputLocally

    [Obsolete("IsInputDisabled is deprecated. Use the GuiDisableInput property instead.")]
    public bool IsInputDisabled()

Getter for GuiDisableInput

    public bool IsInputHandled()

    public bool IsSizeOverrideEnabled()

Returns true if the size override is enabled. See SetSizeOverride(bool, Godot.Vector2?, Godot.Vector2?).

    [Obsolete("IsSizeOverrideStretchEnabled is deprecated. Use the SizeOverrideStretch property instead.")]
    public bool IsSizeOverrideStretchEnabled()

Getter for SizeOverrideStretch

    [Obsolete("IsSnapControlsToPixelsEnabled is deprecated. Use the GuiSnapControlsToPixels property instead.")]
    public bool IsSnapControlsToPixelsEnabled()

Getter for GuiSnapControlsToPixels

    [Obsolete("IsUsingOwnWorld is deprecated. Use the OwnWorld property instead.")]
    public bool IsUsingOwnWorld()

Getter for OwnWorld

    [Obsolete("IsUsingRenderDirectToScreen is deprecated. Use the RenderDirectToScreen property instead.")]
    public bool IsUsingRenderDirectToScreen()

Getter for RenderDirectToScreen

    [Obsolete("SetAsAudioListener is deprecated. Use the AudioListenerEnable3d property instead.")]
    public void SetAsAudioListener(bool enable)

Setter for AudioListenerEnable2d

    [Obsolete("SetAsAudioListener2d is deprecated. Use the AudioListenerEnable2d property instead.")]
    public void SetAsAudioListener2d(bool enable)

Setter for AudioListenerEnable2d

    public void SetAttachToScreenRect(Rect2 rect)

    [Obsolete("SetCanvasTransform is deprecated. Use the CanvasTransform property instead.")]
    public void SetCanvasTransform(Transform2D xform)

Setter for CanvasTransform

    [Obsolete("SetClearMode is deprecated. Use the RenderTargetClearMode property instead.")]
    public void SetClearMode(ClearMode mode)

Setter for RenderTargetClearMode

    [Obsolete("SetDebugDraw is deprecated. Use the DebugDraw property instead.")]
    public void SetDebugDraw(DebugDrawEnum debugDraw)

Setter for DebugDraw

    [Obsolete("SetDisable3d is deprecated. Use the Disable3d property instead.")]
    public void SetDisable3d(bool disable)

Setter for DebugDrawEnum.Disabled

    [Obsolete("SetDisableInput is deprecated. Use the GuiDisableInput property instead.")]
    public void SetDisableInput(bool disable)

Setter for GuiDisableInput

    [Obsolete("SetGlobalCanvasTransform is deprecated. Use the GlobalCanvasTransform property instead.")]
    public void SetGlobalCanvasTransform(Transform2D xform)

Setter for GlobalCanvasTransform

    [Obsolete("SetHandleInputLocally is deprecated. Use the HandleInputLocally property instead.")]
    public void SetHandleInputLocally(bool enable)

Setter for HandleInputLocally

    [Obsolete("SetHdr is deprecated. Use the Hdr property instead.")]
    public void SetHdr(bool enable)

Setter for Hdr

    public void SetInputAsHandled()

    [Obsolete("SetKeep3dLinear is deprecated. Use the Keep3dLinear property instead.")]
    public void SetKeep3dLinear(bool keep3dLinear)

Setter for Keep3dLinear

    [Obsolete("SetMsaa is deprecated. Use the Msaa property instead.")]
    public void SetMsaa(MSAA msaa)

Setter for Msaa

    [Obsolete("SetPhysicsObjectPicking is deprecated. Use the PhysicsObjectPicking property instead.")]
    public void SetPhysicsObjectPicking(bool enable)

Setter for PhysicsObjectPicking

    [Obsolete("SetShadowAtlasQuadrantSubdiv is deprecated. Use the ShadowAtlasQuad3 property instead.")]
    public void SetShadowAtlasQuadrantSubdiv(int quadrant, ShadowAtlasQuadrantSubdiv subdiv)

    [Obsolete("SetShadowAtlasSize is deprecated. Use the ShadowAtlasSize property instead.")]
    public void SetShadowAtlasSize(int size)

Setter for ShadowAtlasSize

    [Obsolete("SetSize is deprecated. Use the Size property instead.")]
    public void SetSize(Vector2 size)

Setter for Size

    public void SetSizeOverride(bool enable, Vector2? size = default(Vector2?), Vector2? margin = default(Vector2?))

Sets the size override of the viewport. If the enable parameter is true the override is used, otherwise it uses the default size. If the size parameter is (-1, -1), it won’t update the size.

    [Obsolete("SetSizeOverrideStretch is deprecated. Use the SizeOverrideStretch property instead.")]
    public void SetSizeOverrideStretch(bool enabled)

Setter for SizeOverrideStretch

    [Obsolete("SetSnapControlsToPixels is deprecated. Use the GuiSnapControlsToPixels property instead.")]
    public void SetSnapControlsToPixels(bool enabled)

Setter for GuiSnapControlsToPixels

    [Obsolete("SetTransparentBackground is deprecated. Use the TransparentBg property instead.")]
    public void SetTransparentBackground(bool enable)

Setter for TransparentBg

    [Obsolete("SetUpdateMode is deprecated. Use the RenderTargetUpdateMode property instead.")]
    public void SetUpdateMode(UpdateMode mode)

Setter for RenderTargetUpdateMode

    [Obsolete("SetUsage is deprecated. Use the Usage property instead.")]
    public void SetUsage(UsageEnum usage)

Setter for Usage

    [Obsolete("SetUseArvr is deprecated. Use the Arvr property instead.")]
    public void SetUseArvr(bool use)

Setter for Arvr

    [Obsolete("SetUseOwnWorld is deprecated. Use the OwnWorld property instead.")]
    public void SetUseOwnWorld(bool enable)

Setter for OwnWorld

    [Obsolete("SetUseRenderDirectToScreen is deprecated. Use the RenderDirectToScreen property instead.")]
    public void SetUseRenderDirectToScreen(bool enable)

Setter for RenderDirectToScreen

    [Obsolete("SetVflip is deprecated. Use the RenderTargetVFlip property instead.")]
    public void SetVflip(bool enable)

Setter for RenderTargetVFlip

    [Obsolete("SetWorld is deprecated. Use the World property instead.")]
    public void SetWorld(World world)

Setter for World

    [Obsolete("SetWorld2d is deprecated. Use the World2d property instead.")]
    public void SetWorld2d(World2D world2d)

Setter for World2d

    public void UnhandledInput(InputEvent localEvent)

    public void UpdateWorlds()

Forces update of the 2D and 3D worlds.

    [Obsolete("UseArvr is deprecated. Use the Arvr property instead.")]
    public bool UseArvr()

Getter for Arvr

    public void WarpMouse(Vector2 toPosition)

Warps the mouse to a position relative to the viewport.

Inner Types

ClearMode

Name Value Description
Always 0 Always clear the render target before drawing.
Never 1 Never clear the render target.
OnlyNextFrame 2 Clear the render target next frame, then switch to [constant CLEAR_MODE_NEVER].

DebugDrawEnum

Name Value Description
Disabled 0 Objects are displayed normally.
Unshaded 1 Objects are displayed without light information.
Overdraw 2 Objected are displayed semi-transparent with additive blending so you can see where they intersect.
Wireframe 3 Objects are displayed in wireframe style.

MSAA

Name Value Description
Disabled 0 Multisample anti-aliasing mode disabled. This is the default value.
Msaa2x    
Msaa4x    
Msaa8x    
Msaa16x    

RenderInfo

Name Value Description
ObjectsInFrame 0 Amount of objects in frame.
VerticesInFrame 1 Amount of vertices in frame.
MaterialChangesInFrame 2 Amount of material changes in frame.
ShaderChangesInFrame 3 Amount of shader changes in frame.
SurfaceChangesInFrame 4 Amount of surface changes in frame.
DrawCallsInFrame 5 Amount of draw calls in frame.
Max 6 Represents the size of the [enum RenderInfo] enum.

ShadowAtlasQuadrantSubdiv

Name Value Description
Disabled 0  
Subdiv1    
Subdiv4    
Subdiv16    
Subdiv64    
Subdiv256    
Subdiv1024    
Max 7 Represents the size of the [enum ShadowAtlasQuadrantSubdiv] enum.

UpdateMode

Name Value Description
Disabled 0 Do not update the render target.
Once 1 Update the render target once, then switch to [constant UPDATE_DISABLED].
WhenVisible 2 Update the render target only when it is visible. This is the default value.
Always 3 Always update the render target.

UsageEnum

Name Value Description
Usage2d    
Usage2dNoSampling    
Usage3d    
Usage3dNoEffects    
Tags: