Viewport
Abstract base class for viewports. Encapsulates drawing and interaction with a game world.
Viewport.swift:26class Viewport
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 Camera3D 3D nodes will render on it too.
Optionally, a viewport can have its own 2D or 3D world, so it doesn’t share what it draws with other viewports.
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.
This object emits the following signals:
Superclasses
class Node
Base class for all scene objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
enum DebugDraw
enum DefaultCanvasItemTextureFilter
enum DefaultCanvasItemTextureRepeat
enum MSAA
enum PositionalShadowAtlasQuadrantSubdiv
enum RenderInfo
enum RenderInfoType
enum SDFOversize
enum SDFScale
enum Scaling3DMode
enum ScreenSpaceAA
class Signal1
Signal support.
enum VRSMode
Type members
Instance members
var audioListenerEnable2d: Bool
If
true
, the viewport will process 2D audio streams.var audioListenerEnable3d: Bool
If
true
, the viewport will process 3D audio streams.var canvasCullMask: UInt32
The rendering layers in which this
Viewport
rendersCanvasItem
nodes.var canvasItemDefaultTextureFilter: Viewport.DefaultCanvasItemTextureFilter
Sets the default filter mode used by
CanvasItem
s in this Viewport. SeeDefaultCanvasItemTextureFilter
for options.var canvasItemDefaultTextureRepeat: Viewport.DefaultCanvasItemTextureRepeat
Sets the default repeat mode used by
CanvasItem
s in this Viewport. SeeDefaultCanvasItemTextureRepeat
for options.var canvasTransform: Transform2D
The canvas transform of the viewport, useful for changing the on-screen positions of all child
CanvasItem
s. This is relative to the global canvas transform of the viewport.var debugDraw: Viewport.DebugDraw
The overlay mode for test rendered geometry in debug purposes.
var disable3d: Bool
Disable 3D rendering (but keep 2D rendering).
var fsrSharpness: Double
Determines how sharp the upscaled image will be when using the FSR upscaling mode. Sharpness halves with every whole number. Values go from 0.0 (sharpest) to 2.0. Values above 2.0 won’t make a visible difference.
var globalCanvasTransform: Transform2D
The global canvas transform of the viewport. The canvas transform is relative to this.
var guiDisableInput: Bool
If
true
, the viewport will not receive input events.var guiEmbedSubwindows: Bool
If
true
, sub-windows (popups and dialogs) will be embedded inside application window as control-like nodes. Iffalse
, they will appear as separate windows handled by the operating system.var guiFocusChanged: Signal1
Emitted when a Control node grabs keyboard focus.
var guiSnapControlsToPixels: Bool
If
true
, the GUI controls on the viewport will lay pixel perfectly.var handleInputLocally: Bool
If
true
, this viewport will mark incoming input events as handled by itself. Iffalse
, this is instead done by the first parent viewport that is set to handle input locally.var meshLodThreshold: Double
The automatic LOD bias to use for meshes rendered within the
Viewport
(this is analogous tomeshLodThreshold
). Higher values will use less detailed versions of meshes that have LOD variations generated. If set to0.0
, automatic LOD is disabled. IncreasemeshLodThreshold
to improve performance at the cost of geometry detail.var msaa2d: Viewport.MSAA
The multisample anti-aliasing mode for 2D/Canvas rendering. A higher number results in smoother edges at the cost of significantly worse performance. A value of 2 or 4 is best unless targeting very high-end systems. This has no effect on shader-induced aliasing or texture aliasing.
var msaa3d: Viewport.MSAA
The multisample anti-aliasing mode for 3D rendering. A higher number results in smoother edges at the cost of significantly worse performance. A value of 2 or 4 is best unless targeting very high-end systems. See also bilinear scaling 3d
scaling3dMode
for supersampling, which provides higher quality but is much more expensive. This has no effect on shader-induced aliasing or texture aliasing.var ownWorld3d: Bool
If
true
, the viewport will use a unique copy of theWorld3D
defined inworld3d
.var physicsObjectPicking: Bool
If
true
, the objects rendered by viewport become subjects of mouse picking process.var physicsObjectPickingSort: Bool
If
true
, objects receive mouse picking events sorted primarily by theirzIndex
and secondarily by their position in the scene tree. Iffalse
, the order is undetermined.var positionalShadowAtlas16Bits: Bool
Use 16 bits for the omni/spot shadow depth map. Enabling this results in shadows having less precision and may result in shadow acne, but can lead to performance improvements on some devices.
var positionalShadowAtlasQuad0: Viewport.PositionalShadowAtlasQuadrantSubdiv
The subdivision amount of the first quadrant on the shadow atlas.
var positionalShadowAtlasQuad1: Viewport.PositionalShadowAtlasQuadrantSubdiv
The subdivision amount of the second quadrant on the shadow atlas.
var positionalShadowAtlasQuad2: Viewport.PositionalShadowAtlasQuadrantSubdiv
The subdivision amount of the third quadrant on the shadow atlas.
var positionalShadowAtlasQuad3: Viewport.PositionalShadowAtlasQuadrantSubdiv
The subdivision amount of the fourth quadrant on the shadow atlas.
var positionalShadowAtlasSize: Int32
The shadow atlas’ resolution (used for omni and spot lights). The value is rounded up to the nearest power of 2.
var scaling3dMode: Viewport.Scaling3DMode
Sets scaling 3d mode. Bilinear scaling renders at different resolution to either undersample or supersample the viewport. FidelityFX Super Resolution 1.0, abbreviated to FSR, is an upscaling technology that produces high quality images at fast framerates by using a spatially aware upscaling algorithm. FSR is slightly more expensive than bilinear, but it produces significantly higher image quality. FSR should be used where possible.
var scaling3dScale: Double
Scales the 3D render buffer based on the viewport size uses an image filter specified in
ProjectSettings/rendering/scaling3d/mode
to scale the output image to the full viewport size. Values lower than1.0
can be used to speed up 3D rendering at the cost of quality (undersampling). Values greater than1.0
are only valid for bilinear mode and can be used to improve 3D rendering quality at a high performance cost (supersampling). See alsoProjectSettings/rendering/antiAliasing/quality/msaa3d
for multi-sample antialiasing, which is significantly cheaper but only smooths the edges of polygons.var screenSpaceAa: Viewport.ScreenSpaceAA
Sets the screen-space antialiasing method used. Screen-space antialiasing works by selectively blurring edges in a post-process shader. It differs from MSAA which takes multiple coverage samples while rendering objects. Screen-space AA methods are typically faster than MSAA and will smooth out specular aliasing, but tend to make scenes appear blurry.
var sdfOversize: Viewport.SDFOversize
var sdfScale: Viewport.SDFScale
var sizeChanged: SimpleSignal
Emitted when the size of the viewport is changed, whether by resizing of window, or some other means.
var snap2dTransformsToPixel: Bool
var snap2dVerticesToPixel: Bool
var textureMipmapBias: Double
Affects the final texture sharpness by reading from a lower or higher mipmap (also called “texture LOD bias”). Negative values make mipmapped textures sharper but grainier when viewed at a distance, while positive values make mipmapped textures blurrier (even when up close).
var transparentBg: Bool
If
true
, the viewport should render its background as transparent.var useDebanding: Bool
If
true
, uses a fast post-processing filter to make banding significantly less visible in 3D. 2D rendering is not affected by debanding unless thebackgroundMode
isEnvironment/BGMode/bgCanvas
. See alsoProjectSettings/rendering/antiAliasing/quality/useDebanding
.var useHdr2d: Bool
If
true
, 2D rendering will use an high dynamic range (HDR) format framebuffer matching the bit depth of the 3D framebuffer. When using the Forward+ renderer this will be aRGBA16
framebuffer, while when using the Mobile renderer it will be aRGB10_A2
framebuffer. Additionally, 2D rendering will take place in linear color space and will be converted to sRGB space immediately before blitting to the screen (if the Viewport is attached to the screen). Practically speaking, this means that the end result of the Viewport will not be clamped into the0-1
range and can be used in 3D rendering without color space adjustments. This allows 2D rendering to take advantage of effects requiring high dynamic range (e.g. 2D glow) as well as substantially improves the appearance of effects requiring highly detailed gradients.var useOcclusionCulling: Bool
If
true
,OccluderInstance3D
nodes will be usable for occlusion culling in 3D for this viewport. For the root viewport,ProjectSettings/rendering/occlusionCulling/useOcclusionCulling
must be set totrue
instead.var useTaa: Bool
Enables Temporal Anti-Aliasing for this viewport. TAA works by jittering the camera and accumulating the images of the last rendered frames, motion vector rendering is used to account for camera and object motion.
var useXr: Bool
If
true
, the viewport will use the primary XR interface to render XR output. When applicable this can result in a stereoscopic image and the resulting render being output to a headset.var vrsMode: Viewport.VRSMode
The Variable Rate Shading (VRS) mode that is used for this viewport. Note, if hardware does not support VRS this property is ignored.
var vrsTexture: Texture2D?
Texture to use when
vrsMode
is set toViewport/VRSMode/vrsTexture
.var world2d: World2D?
The custom
World2D
which can be used as 2D environment source.var world3d: World3D?
The custom
World3D
which can be used as 3D environment source.func findWorld2d(
) -> World2D? Returns the first valid
World2D
for this viewport, searching theworld2d
property of itself and any Viewport ancestor.func findWorld3d(
) -> World3D? Returns the first valid
World3D
for this viewport, searching theworld3d
property of itself and any Viewport ancestor.func getCamera2d(
) -> Camera2D? Returns the currently active 2D camera. Returns null if there are no active cameras.
func getCamera3d(
) -> Camera3D? Returns the currently active 3D camera.
func getCanvasCullMaskBit(layer: UInt32
) -> Bool Returns an individual bit on the rendering layer mask.
func getEmbeddedSubwindows(
) -> ObjectCollection<Window> Returns a list of the visible embedded
Window
s inside the viewport.func getFinalTransform(
) -> Transform2D Returns the transform from the viewport’s coordinate system to the embedder’s coordinate system.
func getMousePosition(
) -> Vector2 Returns the mouse’s position in this
Viewport
using the coordinate system of thisViewport
.func getRenderInfo(type: Viewport.RenderInfoType, info: Viewport.RenderInfo
) -> Int32 Returns rendering statistics of the given type. See
RenderInfoType
andRenderInfo
for options.func getScreenTransform(
) -> Transform2D Returns the transform from the Viewport’s coordinates to the screen coordinates of the containing window manager window.
func getTexture(
) -> ViewportTexture? Returns the viewport’s texture.
func getViewportRid(
) -> RID Returns the viewport’s RID from the
RenderingServer
.func getVisibleRect(
) -> Rect2 Returns the visible rectangle in global screen coordinates.
func guiGetDragData(
) -> Variant Returns the drag data from the GUI, that was previously returned by
_getDragData(atPosition:)
.func guiGetFocusOwner(
) -> Control? Returns the
Control
having the focus within this viewport. If noControl
has the focus, returns null.func guiIsDragSuccessful(
) -> Bool Returns
true
if the drag operation is successful.func guiIsDragging(
) -> Bool Returns
true
if the viewport is currently performing a drag operation.func guiReleaseFocus(
) Removes the focus from the currently focused
Control
within this viewport. If noControl
has the focus, does nothing.func isInputHandled(
) -> Bool Returns whether the current
InputEvent
has been handled. Input events are not handled untilsetInputAsHandled
has been called during the lifetime of anInputEvent
.func pushInput(event: InputEvent?, inLocalCoords: Bool
) Triggers the given
event
in thisViewport
. This can be used to pass anInputEvent
between viewports, or to locally apply inputs that were sent over the network or saved to a file.func pushTextInput(text: String
) Helper method which calls the
set_text()
method on the currently focusedControl
, provided that it is defined (e.g. if the focused Control isButton
orLineEdit
).func pushUnhandledInput(event: InputEvent?, inLocalCoords: Bool
) Triggers the given
InputEvent
in thisViewport
. This can be used to pass input events between viewports, or to locally apply inputs that were sent over the network or saved to a file.func setCanvasCullMaskBit(layer: UInt32, enable: Bool
) Set/clear individual bits on the rendering layer mask. This simplifies editing this
Viewport
’s layers.func setInputAsHandled(
) Stops the input from propagating further down the
SceneTree
.func updateMouseCursorState(
) Force instantly updating the display based on the current mouse cursor position. This includes updating the mouse cursor shape and sending necessary [signal Control.mouse_entered], [signal CollisionObject2D.mouse_entered], [signal CollisionObject3D.mouse_entered] and [signal Window.mouse_entered] signals and their respective
mouse_exited
counterparts.func warpMouse(position: Vector2
) Moves the mouse pointer to the specified position in this
Viewport
using the coordinate system of thisViewport
.
Subclasses
class SubViewport
An interface to a game world that doesn’t create a window or draw to the screen directly.
class Window
Base class for all windows, dialogs, and popups.