Viewport

Creates a sub-view into the screen.

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.

@GodotBaseClass
struct Viewport {}

Members

Aliases

BaseClasses
alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses)
Undocumented in source.

Enums

ClearMode
enum ClearMode
Constants
enum Constants
DebugDraw
enum DebugDraw
MSAA
enum MSAA
RenderInfo
enum RenderInfo
ShadowAtlasQuadrantSubdiv
enum ShadowAtlasQuadrantSubdiv
UpdateMode
enum UpdateMode
Usage
enum Usage

Functions

_guiRemoveFocus
void _guiRemoveFocus()
_guiShowTooltip
void _guiShowTooltip()
_ownWorldChanged
void _ownWorldChanged()
_postGuiGrabClickFocus
void _postGuiGrabClickFocus()
_processPicking
void _processPicking(bool ignore_paused)
_subwindowVisibilityChanged
void _subwindowVisibilityChanged()
_vpInput
void _vpInput(InputEvent arg0)
_vpInputText
void _vpInputText(String text)
_vpUnhandledInput
void _vpUnhandledInput(InputEvent arg0)
findWorld
Ref!World findWorld()

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

findWorld2d
Ref!World2D findWorld2d()

Returns the 2D world of the viewport.

getCamera
Camera getCamera()

Returns the active 3D camera.

getCanvasTransform
Transform2D getCanvasTransform()
getClearMode
Viewport.ClearMode getClearMode()
getDebugDraw
Viewport.DebugDraw getDebugDraw()
getFinalTransform
Transform2D getFinalTransform()

Returns the total transform of the viewport.

getGlobalCanvasTransform
Transform2D getGlobalCanvasTransform()
getHdr
bool getHdr()
getKeep3dLinear
bool getKeep3dLinear()
getModalStackTop
Control getModalStackTop()

Returns the topmost modal in the stack.

getMousePosition
Vector2 getMousePosition()

Returns the mouse position relative to the viewport.

getMsaa
Viewport.MSAA getMsaa()
getPhysicsObjectPicking
bool getPhysicsObjectPicking()
getRenderInfo
long getRenderInfo(long info)

Returns information about the viewport from the rendering pipeline.

getShadowAtlasQuadrantSubdiv
Viewport.ShadowAtlasQuadrantSubdiv getShadowAtlasQuadrantSubdiv(long quadrant)

Returns the shadowatlasquadrantsubdiv of the specified quadrant.

getShadowAtlasSize
long getShadowAtlasSize()
getSize
Vector2 getSize()
getSizeOverride
Vector2 getSizeOverride()

Returns the size override set with setSizeOverride.

getTexture
Ref!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:

getUpdateMode
Viewport.UpdateMode getUpdateMode()
getUsage
Viewport.Usage getUsage()
getUseDebanding
bool getUseDebanding()
getUseFxaa
bool getUseFxaa()
getVflip
bool getVflip()
getViewportRid
RID getViewportRid()

Returns the viewport's RID from the VisualServer.

getVisibleRect
Rect2 getVisibleRect()

Returns the visible rectangle in global screen coordinates.

getWorld
Ref!World getWorld()
getWorld2d
Ref!World2D getWorld2d()
guiGetDragData
Variant guiGetDragData()

Returns the drag data from the GUI, that was previously returned by Control.getDragData.

guiHasModalStack
bool guiHasModalStack()

Returns true if there are visible modals on-screen.

guiIsDragging
bool guiIsDragging()

Returns true if the viewport is currently performing a drag operation.

hasTransparentBackground
bool hasTransparentBackground()
input
void input(InputEvent local_event)
is3dDisabled
bool is3dDisabled()
isAudioListener
bool isAudioListener()
isAudioListener2d
bool isAudioListener2d()
isHandlingInputLocally
bool isHandlingInputLocally()
isInputDisabled
bool isInputDisabled()
isInputHandled
bool isInputHandled()
isSizeOverrideEnabled
bool isSizeOverrideEnabled()

Returns true if the size override is enabled. See setSizeOverride.

isSizeOverrideStretchEnabled
bool isSizeOverrideStretchEnabled()
isSnapControlsToPixelsEnabled
bool isSnapControlsToPixelsEnabled()
isUsingOwnWorld
bool isUsingOwnWorld()
isUsingRenderDirectToScreen
bool isUsingRenderDirectToScreen()
opAssign
typeof(null) opAssign(typeof(null) n)
opEquals
bool opEquals(Viewport other)
opEquals
bool opEquals(typeof(null) n)
setAsAudioListener
void setAsAudioListener(bool enable)
setAsAudioListener2d
void setAsAudioListener2d(bool enable)
setAttachToScreenRect
void setAttachToScreenRect(Rect2 rect)

Attaches this Viewport to the root Viewport with the specified rectangle. This bypasses the need for another node to display this Viewport but makes you responsible for updating the position of this Viewport manually.

setCanvasTransform
void setCanvasTransform(Transform2D xform)
setClearMode
void setClearMode(long mode)
setDebugDraw
void setDebugDraw(long debug_draw)
setDisable3d
void setDisable3d(bool disable)
setDisableInput
void setDisableInput(bool disable)
setGlobalCanvasTransform
void setGlobalCanvasTransform(Transform2D xform)
setHandleInputLocally
void setHandleInputLocally(bool enable)
setHdr
void setHdr(bool enable)
setInputAsHandled
void setInputAsHandled()

Stops the input from propagating further down the SceneTree.

setKeep3dLinear
void setKeep3dLinear(bool keep_3d_linear)
setMsaa
void setMsaa(long msaa)
setPhysicsObjectPicking
void setPhysicsObjectPicking(bool enable)
setShadowAtlasQuadrantSubdiv
void setShadowAtlasQuadrantSubdiv(long quadrant, long subdiv)

Sets the number of subdivisions to use in the specified quadrant. A higher number of subdivisions allows you to have more shadows in the scene at once, but reduces the quality of the shadows. A good practice is to have quadrants with a varying number of subdivisions and to have as few subdivisions as possible.

setShadowAtlasSize
void setShadowAtlasSize(long size)
setSize
void setSize(Vector2 size)
setSizeOverride
void setSizeOverride(bool enable, Vector2 size, Vector2 margin)

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.

setSizeOverrideStretch
void setSizeOverrideStretch(bool enabled)
setSnapControlsToPixels
void setSnapControlsToPixels(bool enabled)
setTransparentBackground
void setTransparentBackground(bool enable)
setUpdateMode
void setUpdateMode(long mode)
setUsage
void setUsage(long usage)
setUseArvr
void setUseArvr(bool use)
setUseDebanding
void setUseDebanding(bool enable)
setUseFxaa
void setUseFxaa(bool enable)
setUseOwnWorld
void setUseOwnWorld(bool enable)
setUseRenderDirectToScreen
void setUseRenderDirectToScreen(bool enable)
setVflip
void setVflip(bool enable)
setWorld
void setWorld(World world)
setWorld2d
void setWorld2d(World2D world_2d)
toHash
size_t toHash()
unhandledInput
void unhandledInput(InputEvent local_event)
updateWorlds
void updateWorlds()

Forces update of the 2D and 3D worlds.

useArvr
bool useArvr()
warpMouse
void warpMouse(Vector2 to_position)

Warps the mouse to a position relative to the viewport.

Mixins

__anonymous
mixin baseCasts
Undocumented in source.

Properties

arvr
bool arvr [@property getter]
bool arvr [@property setter]

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

audioListenerEnable2d
bool audioListenerEnable2d [@property getter]
bool audioListenerEnable2d [@property setter]

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

audioListenerEnable3d
bool audioListenerEnable3d [@property getter]
bool audioListenerEnable3d [@property setter]

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

canvasTransform
Transform2D canvasTransform [@property getter]
Transform2D canvasTransform [@property setter]

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.

debanding
bool debanding [@property getter]
bool debanding [@property setter]

If true, uses a fast post-processing filter to make banding significantly less visible. In some cases, debanding may introduce a slightly noticeable dithering pattern. It's recommended to enable debanding only when actually needed since the dithering pattern will make lossless-compressed screenshots larger. Note: Only available on the GLES3 backend. hdr must also be true for debanding to be effective.

debugDraw
Viewport.DebugDraw debugDraw [@property getter]
long debugDraw [@property setter]

The overlay mode for test rendered geometry in debug purposes.

disable3d
bool disable3d [@property getter]
bool disable3d [@property setter]

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

fxaa
bool fxaa [@property getter]
bool fxaa [@property setter]

Enables fast approximate antialiasing. FXAA is a popular screen-space antialiasing method, which is fast but will make the image look blurry, especially at lower resolutions. It can still work relatively well at large resolutions such as 1440p and 4K.

globalCanvasTransform
Transform2D globalCanvasTransform [@property getter]
Transform2D globalCanvasTransform [@property setter]

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

guiDisableInput
bool guiDisableInput [@property getter]
bool guiDisableInput [@property setter]

If true, the viewport will not receive input events.

guiSnapControlsToPixels
bool guiSnapControlsToPixels [@property getter]
bool guiSnapControlsToPixels [@property setter]

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

handleInputLocally
bool handleInputLocally [@property getter]
bool handleInputLocally [@property setter]
hdr
bool hdr [@property getter]
bool hdr [@property setter]

If true, the viewport rendering will receive benefits from High Dynamic Range algorithm. High Dynamic Range allows the viewport to receive values that are outside the 0-1 range. In Godot HDR uses 16 bits, meaning it does not store the full range of a floating point number. Note: Requires usage to be set to constant USAGE_3D or constant USAGE_3D_NO_EFFECTS, since HDR is not supported for 2D.

keep3dLinear
bool keep3dLinear [@property getter]
bool keep3dLinear [@property setter]

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.

msaa
Viewport.MSAA msaa [@property getter]
long msaa [@property setter]

The multisample anti-aliasing mode. A higher number results in smoother edges at the cost of significantly worse performance. A value of 4 is best unless targeting very high-end systems.

ownWorld
bool ownWorld [@property getter]
bool ownWorld [@property setter]

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

physicsObjectPicking
bool physicsObjectPicking [@property getter]
bool physicsObjectPicking [@property setter]

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

renderDirectToScreen
bool renderDirectToScreen [@property getter]
bool renderDirectToScreen [@property setter]

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.

renderTargetClearMode
Viewport.ClearMode renderTargetClearMode [@property getter]
long renderTargetClearMode [@property setter]

The clear mode when viewport used as a render target. Note: This property is intended for 2D usage.

renderTargetUpdateMode
Viewport.UpdateMode renderTargetUpdateMode [@property getter]
long renderTargetUpdateMode [@property setter]

The update mode when viewport used as a render target.

renderTargetVFlip
bool renderTargetVFlip [@property getter]
bool renderTargetVFlip [@property setter]

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

shadowAtlasQuad0
Viewport.ShadowAtlasQuadrantSubdiv shadowAtlasQuad0 [@property getter]
long shadowAtlasQuad0 [@property setter]

The subdivision amount of the first quadrant on the shadow atlas.

shadowAtlasQuad1
Viewport.ShadowAtlasQuadrantSubdiv shadowAtlasQuad1 [@property getter]
long shadowAtlasQuad1 [@property setter]

The subdivision amount of the second quadrant on the shadow atlas.

shadowAtlasQuad2
Viewport.ShadowAtlasQuadrantSubdiv shadowAtlasQuad2 [@property getter]
long shadowAtlasQuad2 [@property setter]

The subdivision amount of the third quadrant on the shadow atlas.

shadowAtlasQuad3
Viewport.ShadowAtlasQuadrantSubdiv shadowAtlasQuad3 [@property getter]
long shadowAtlasQuad3 [@property setter]

The subdivision amount of the fourth quadrant on the shadow atlas.

shadowAtlasSize
long shadowAtlasSize [@property getter]
long shadowAtlasSize [@property setter]

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.

size
Vector2 size [@property getter]
Vector2 size [@property setter]

The width and height of viewport.

sizeOverrideStretch
bool sizeOverrideStretch [@property getter]
bool sizeOverrideStretch [@property setter]

If true, the size override affects stretch as well.

transparentBg
bool transparentBg [@property setter]

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

transparentBg
bool transparentBg [@property getter]

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

usage
Viewport.Usage usage [@property getter]
long usage [@property setter]

The rendering mode of viewport.

world
World world [@property getter]
World world [@property setter]

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

world2d
World2D world2d [@property getter]
World2D world2d [@property setter]

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

Static functions

_new
Viewport _new()

Construct a new instance of Viewport. Note: use memnew!Viewport instead.

Static variables

_classBindingInitialized
bool _classBindingInitialized;
Undocumented in source.

Structs

GDNativeClassBinding
struct GDNativeClassBinding
Undocumented in source.

Unions

__anonymous
union __anonymous
Undocumented in source.

Variables

_GODOT_internal_name
enum string _GODOT_internal_name;
Undocumented in source.

Mixed In Members

From mixin baseCasts

as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(To) as()
Undocumented in source. Be warned that the author may not have intended to support it.
as
inout(ToRef) as()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(To)
Undocumented in source.
opCast
template opCast(ToRef)
Undocumented in source.
opCast
void* opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
godot_object opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.

Meta