UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FCanvas Class Reference

#include <CanvasTypes.h>

Classes

class  FCanvasSortElement
 
class  FTransformEntry
 

Public Types

enum  EElementType { ET_Line , ET_Triangle , ET_MAX }
 
enum  ECanvasAllowModes { Allow_Flush = 1 << 0 , Allow_DeleteOnRender = 1 << 1 }
 
enum  ECanvasDrawMode { CDM_DeferDrawing , CDM_ImmediateDrawing }
 

Public Member Functions

ENGINE_API FCanvas (FRenderTarget *InRenderTarget, FHitProxyConsumer *InHitProxyConsumer, UWorld *InWorld, ERHIFeatureLevel::Type InFeatureLevel, ECanvasDrawMode DrawMode=CDM_DeferDrawing, float InDPIScale=1.0f)
 
ENGINE_API FCanvas (FRenderTarget *InRenderTarget, FHitProxyConsumer *InHitProxyConsumer, const FGameTime &Time, ERHIFeatureLevel::Type InFeatureLevel, float InDPIScale=1.0f)
 
ENGINE_API ~FCanvas ()
 
ENGINE_API FBatchedElementsGetBatchedElements (EElementType InElementType, FBatchedElementParameters *InBatchedElementParameters=NULL, const FTexture *Texture=NULL, ESimpleElementBlendMode BlendMode=SE_BLEND_MAX, const FDepthFieldGlowInfo &GlowInfo=FDepthFieldGlowInfo(), bool bApplyDPIScale=true)
 
ENGINE_API void AddTileRenderItem (float X, float Y, float SizeX, float SizeY, float U, float V, float SizeU, float SizeV, const FMaterialRenderProxy *MaterialRenderProxy, FHitProxyId HitProxyId, bool bFreezeTime, FColor InColor)
 
ENGINE_API void AddTriangleRenderItem (const FCanvasUVTri &Tri, const FMaterialRenderProxy *MaterialRenderProxy, FHitProxyId HitProxyId, bool bFreezeTime)
 
ENGINE_API void Flush_RenderThread (FRHICommandListImmediate &RHICmdList, bool bForce=false)
 
ENGINE_API void Flush_RenderThread (FRDGBuilder &GraphBuilder, bool bForce=false)
 
ENGINE_API void Flush_GameThread (bool bForce=false)
 
ENGINE_API void PushRelativeTransform (const FMatrix &Transform)
 
ENGINE_API void PushAbsoluteTransform (const FMatrix &Transform)
 
ENGINE_API void PopTransform ()
 
ENGINE_API void SetBaseTransform (const FMatrix &Transform)
 
FMatrix GetTransform () const
 
const FMatrixGetBottomTransform () const
 
const FMatrixGetFullTransform () const
 
ENGINE_API void CopyTransformStack (const FCanvas &Copy)
 
ENGINE_API void SetRenderTarget_GameThread (FRenderTarget *NewRenderTarget)
 
FRenderTargetGetRenderTarget () const
 
ENGINE_API void SetRenderTargetRect (const FIntRect &ViewRect)
 
ENGINE_API void SetRenderTargetScissorRect (const FIntRect &ScissorRect)
 
void SetRenderTargetDirty (bool bDirty)
 
ENGINE_API void SetHitProxy (HHitProxy *HitProxy)
 
FHitProxyId GetHitProxyId () const
 
FHitProxyConsumerGetHitProxyConsumer () const
 
bool IsHitTesting () const
 
FSceneInterfaceGetScene () const
 
void PushDepthSortKey (int32 InSortKey)
 
int32 PopDepthSortKey ()
 
int32 TopDepthSortKey ()
 
void SetAllowedModes (uint32 InAllowedModes)
 
uint32 GetAllowedModes () const
 
bool HasBatchesToRender () const
 
void ClearBatchesToRender ()
 
ERHIFeatureLevel::Type GetFeatureLevel () const
 
ENGINE_API EShaderPlatform GetShaderPlatform () const
 
const TArray< FTransformEntry > & GetTransformStack () const
 
const FIntRectGetViewRect () const
 
void SetScaledToRenderTarget (bool bScale=true)
 
bool IsScaledToRenderTarget () const
 
void SetStereoRendering (bool bStereo=true)
 
bool IsStereoRendering () const
 
void SetUseInternalTexture (const bool bInUseInternalTexture)
 
bool IsUsingInternalTexture () const
 
void SetWriteDestinationAlpha (const bool bInForceWriteAlpha)
 
bool IsWriteDestinationAlphaSet () const
 
void SetParentCanvasSize (FIntPoint InParentSize)
 
FIntPoint GetParentCanvasSize () const
 
float GetDPIScale () const
 
const FGameTimeGetTime () const
 
ENGINE_API void DrawItem (FCanvasItem &Item)
 
ENGINE_API void DrawItem (FCanvasItem &Item, const FVector2D &InPosition)
 
ENGINE_API void DrawItem (FCanvasItem &Item, float X, float Y)
 
ENGINE_API void Clear (const FLinearColor &Color)
 
ENGINE_API void DrawTile (double X, double Y, double SizeX, double SizeY, float U, float V, float SizeU, float SizeV, const FLinearColor &Color, const FTexture *Texture=NULL, bool AlphaBlend=true)
 
ENGINE_API void DrawTile (double X, double Y, double SizeX, double SizeY, float U, float V, float SizeU, float SizeV, const FLinearColor &Color, const FTexture *Texture, ESimpleElementBlendMode BlendMode)
 
ENGINE_API int32 DrawShadowedString (double StartX, double StartY, FStringView Text, const UFont *Font, const FLinearColor &Color, const FLinearColor &ShadowColor=FLinearColor::Black)
 
ENGINE_API int32 DrawShadowedText (double StartX, double StartY, const FText &Text, const UFont *Font, const FLinearColor &Color, const FLinearColor &ShadowColor=FLinearColor::Black)
 
ENGINE_API void WrapString (FTextSizingParameters &Parameters, const float InCurX, FStringView Text, TArray< FWrappedStringElement > &out_Lines, FCanvasWordWrapper::FWrappedLineData *const OutWrappedLineData=nullptr)
 
ENGINE_API void DrawNGon (const FVector2D &Center, const FColor &Color, int32 NumSides, float Radius)
 
ENGINE_API FCanvasSortElementGetSortElement (int32 DepthSortKey)
 

Static Public Member Functions

static ENGINE_API FCanvasCreate (FRDGBuilder &GraphBuilder, FRDGTextureRef InRenderTarget, FHitProxyConsumer *InHitProxyConsumer, const FGameTime &Time, ERHIFeatureLevel::Type InFeatureLevel, float InDPIScale=1.0f)
 
static ENGINE_API ESimpleElementBlendMode BlendToSimpleElementBlend (EBlendMode BlendMode)
 
static ENGINE_API FMatrix CalcBaseTransform2D (uint32 ViewSizeX, uint32 ViewSizeY)
 
static ENGINE_API FMatrix CalcBaseTransform3D (uint32 ViewSizeX, uint32 ViewSizeY, float fFOV, float NearPlane)
 
static ENGINE_API FMatrix CalcViewMatrix (uint32 ViewSizeX, uint32 ViewSizeY, float fFOV)
 
static ENGINE_API FMatrix CalcProjectionMatrix (uint32 ViewSizeX, uint32 ViewSizeY, float fFOV, float NearPlane)
 

Public Attributes

float AlphaModulate
 
TSharedPtr< FCanvasWordWrapperWordWrapper
 
TArray< FCanvasSortElementSortedElements
 
TMap< int32, int32SortedElementLookupMap
 
int32 LastElementIndex
 

Friends

class FCanvasRenderContext
 
class FCanvasRenderThreadScope
 

Detailed Description

Encapsulates the canvas state.

Member Enumeration Documentation

◆ ECanvasAllowModes

Enum for canvas features that are allowed

Enumerator
Allow_Flush 
Allow_DeleteOnRender 

◆ ECanvasDrawMode

Enumerator
CDM_DeferDrawing 
CDM_ImmediateDrawing 

◆ EElementType

Enum that describes what type of element we are currently batching.

Enumerator
ET_Line 
ET_Triangle 
ET_MAX 

Constructor & Destructor Documentation

◆ FCanvas() [1/2]

FCanvas::FCanvas ( FRenderTarget InRenderTarget,
FHitProxyConsumer InHitProxyConsumer,
UWorld InWorld,
ERHIFeatureLevel::Type  InFeatureLevel,
ECanvasDrawMode  DrawMode = CDM_DeferDrawing,
float  InDPIScale = 1.0f 
)

Constructor.

◆ FCanvas() [2/2]

FCanvas::FCanvas ( FRenderTarget InRenderTarget,
FHitProxyConsumer InHitProxyConsumer,
const FGameTime Time,
ERHIFeatureLevel::Type  InFeatureLevel,
float  InDPIScale = 1.0f 
)

Constructor. For situations where a world is not available, but time information is

◆ ~FCanvas()

FCanvas::~FCanvas ( )

Destructor.

Member Function Documentation

◆ AddTileRenderItem()

void FCanvas::AddTileRenderItem ( float  X,
float  Y,
float  SizeX,
float  SizeY,
float  U,
float  V,
float  SizeU,
float  SizeV,
const FMaterialRenderProxy MaterialRenderProxy,
FHitProxyId  HitProxyId,
bool  bFreezeTime,
FColor  InColor 
)

Generates a new FCanvasTileRendererItem for the current sortkey and adds it to the sortelement list of items to render

◆ AddTriangleRenderItem()

void FCanvas::AddTriangleRenderItem ( const FCanvasUVTri Tri,
const FMaterialRenderProxy MaterialRenderProxy,
FHitProxyId  HitProxyId,
bool  bFreezeTime 
)

Generates a new FCanvasTriangleRendererItem for the current sortkey and adds it to the sortelement list of items to render

◆ BlendToSimpleElementBlend()

ESimpleElementBlendMode FCanvas::BlendToSimpleElementBlend ( EBlendMode  BlendMode)
static

Translate EBlendMode into ESimpleElementBlendMode used by tiles

Parameters
BlendModeNormal Unreal blend mode enum
Returns
simple element rendering blend mode enum

◆ CalcBaseTransform2D()

FMatrix FCanvas::CalcBaseTransform2D ( uint32  ViewSizeX,
uint32  ViewSizeY 
)
static

Generate a 2D projection for the canvas. Use this if you only want to transform in 2D on the XY plane

Parameters
ViewSizeX- Viewport width
ViewSizeY- Viewport height
Returns
Matrix for canvas projection

◆ CalcBaseTransform3D()

FMatrix FCanvas::CalcBaseTransform3D ( uint32  ViewSizeX,
uint32  ViewSizeY,
float  fFOV,
float  NearPlane 
)
static

Generate a 3D projection for the canvas. Use this if you want to transform in 3D

Parameters
ViewSizeX- Viewport width
ViewSizeY- Viewport height
fFOV- Field of view for the projection
NearPlane- Distance to the near clip plane
Returns
Matrix for canvas projection

◆ CalcProjectionMatrix()

FMatrix FCanvas::CalcProjectionMatrix ( uint32  ViewSizeX,
uint32  ViewSizeY,
float  fFOV,
float  NearPlane 
)
static

Generate a projection matrix for the canvas. Used for CalcBaseTransform3D

Parameters
ViewSizeX- Viewport width
ViewSizeY- Viewport height
fFOV- Field of view for the projection
NearPlane- Distance to the near clip plane
Returns
Matrix for canvas projection

◆ CalcViewMatrix()

FMatrix FCanvas::CalcViewMatrix ( uint32  ViewSizeX,
uint32  ViewSizeY,
float  fFOV 
)
static

Generate a view matrix for the canvas. Used for CalcBaseTransform3D

Parameters
ViewSizeX- Viewport width
ViewSizeY- Viewport height
fFOV- Field of view for the projection
Returns
Matrix for canvas view orientation

◆ Clear()

void FCanvas::Clear ( const FLinearColor Color)

Clear the canvas

Parameters
ColorColor to clear with.

◆ ClearBatchesToRender()

void FCanvas::ClearBatchesToRender ( )

Clear the list of dirty batches that need to be rendered by the canvas

◆ CopyTransformStack()

void FCanvas::CopyTransformStack ( const FCanvas Copy)

Copy the conents of the TransformStack from an existing canvas

Parameters
Copycanvas to copy from

◆ Create()

FCanvas * FCanvas::Create ( FRDGBuilder GraphBuilder,
FRDGTextureRef  InRenderTarget,
FHitProxyConsumer InHitProxyConsumer,
const FGameTime Time,
ERHIFeatureLevel::Type  InFeatureLevel,
float  InDPIScale = 1.0f 
)
static

◆ DrawItem() [1/3]

void FCanvas::DrawItem ( FCanvasItem Item)

Draw a CanvasItem

Parameters
ItemItem to draw

◆ DrawItem() [2/3]

void FCanvas::DrawItem ( FCanvasItem Item,
const FVector2D InPosition 
)

Draw a CanvasItem at the given coordinates

Parameters
ItemItem to draw
InPositionPosition to draw item

◆ DrawItem() [3/3]

void FCanvas::DrawItem ( FCanvasItem Item,
float  X,
float  Y 
)

Draw a CanvasItem at the given coordinates

Parameters
ItemItem to draw
XX Position to draw item
YY Position to draw item

◆ DrawNGon()

void FCanvas::DrawNGon ( const FVector2D Center,
const FColor Color,
int32  NumSides,
float  Radius 
)

◆ DrawShadowedString()

int32 FCanvas::DrawShadowedString ( double  StartX,
double  StartY,
FStringView  Text,
const UFont Font,
const FLinearColor Color,
const FLinearColor ShadowColor = FLinearColor::Black 
)

Draw an string centered on given location. This function is being deprecated. a FCanvasTextItem should be used instead.

Parameters
StartX- X point
StartY- Y point
Text- Text to draw
Font- Font to use
Color- Color of the text
ShadowColor- Shadow color to draw underneath the text (ignored for distance field fonts)
Returns
total size in pixels of text drawn

◆ DrawShadowedText()

int32 FCanvas::DrawShadowedText ( double  StartX,
double  StartY,
const FText Text,
const UFont Font,
const FLinearColor Color,
const FLinearColor ShadowColor = FLinearColor::Black 
)

◆ DrawTile() [1/2]

void FCanvas::DrawTile ( double  X,
double  Y,
double  SizeX,
double  SizeY,
float  U,
float  V,
float  SizeU,
float  SizeV,
const FLinearColor Color,
const FTexture Texture,
ESimpleElementBlendMode  BlendMode 
)

◆ DrawTile() [2/2]

void FCanvas::DrawTile ( double  X,
double  Y,
double  SizeX,
double  SizeY,
float  U,
float  V,
float  SizeU,
float  SizeV,
const FLinearColor Color,
const FTexture Texture = NULL,
bool  AlphaBlend = true 
)

Draw arbitrary aligned rectangle.

Parameters
X- X position to draw tile at
Y- Y position to draw tile at
SizeX- Width of tile
SizeY- Height of tile
U- Horizontal position of the upper left corner of the portion of the texture to be shown(texels)
V- Vertical position of the upper left corner of the portion of the texture to be shown(texels)
SizeU- The width of the portion of the texture to be drawn. This value is in texels.
SizeV- The height of the portion of the texture to be drawn. This value is in texels.
Color- tint applied to tile
Texture- Texture to draw
AlphaBlend- true to alphablend

◆ Flush_GameThread()

void FCanvas::Flush_GameThread ( bool  bForce = false)

Sends a message to the rendering thread to draw the batched elements.

Parameters
bForce- force the flush even if Allow_Flush is not enabled

◆ Flush_RenderThread() [1/2]

void FCanvas::Flush_RenderThread ( FRDGBuilder GraphBuilder,
bool  bForce = false 
)

◆ Flush_RenderThread() [2/2]

void FCanvas::Flush_RenderThread ( FRHICommandListImmediate RHICmdList,
bool  bForce = false 
)

Sends a message to the rendering thread to draw the batched elements.

Parameters
RHICmdList- command list to use
bForce- force the flush even if Allow_Flush is not enabled
bInsideRenderPass- Set to true if flushing inside a render pass (e.g. Render Graph pass). This will skip creating a render pass internally, and assert if the command list is not in a render pass.

◆ GetAllowedModes()

uint32 FCanvas::GetAllowedModes ( ) const
inline

Accessor for allowed canvas modes

Returns
current allowed modes

◆ GetBatchedElements()

FBatchedElements * FCanvas::GetBatchedElements ( EElementType  InElementType,
FBatchedElementParameters InBatchedElementParameters = NULL,
const FTexture Texture = NULL,
ESimpleElementBlendMode  BlendMode = SE_BLEND_MAX,
const FDepthFieldGlowInfo GlowInfo = FDepthFieldGlowInfo(),
bool  bApplyDPIScale = true 
)

Returns a FBatchedElements pointer to be used for adding vertices and primitives for rendering. Adds a new render item to the sort element entry based on the current sort key.

Parameters
InElementType- Type of element we are going to draw.
InBatchedElementParameters- Parameters for this element
InTexture- New texture that will be set.
InBlendMode- New blendmode that will be set.
GlowInfo- info for optional glow effect when using depth field rendering
Returns
Returns a pointer to a FBatchedElements object.

◆ GetBottomTransform()

const FMatrix & FCanvas::GetBottomTransform ( ) const
inline

Get the bottom-most element of the transform stack.

Returns
matrix from transform stack.

◆ GetDPIScale()

float FCanvas::GetDPIScale ( ) const
inline

◆ GetFeatureLevel()

ERHIFeatureLevel::Type FCanvas::GetFeatureLevel ( ) const
inline

Access current feature level

Returns
feature level that this canvas is rendering at

◆ GetFullTransform()

const FMatrix & FCanvas::GetFullTransform ( ) const
inline

Get the current top-most transform entry

Returns
matrix from transform stack.

◆ GetHitProxyConsumer()

FHitProxyConsumer * FCanvas::GetHitProxyConsumer ( ) const
inline

◆ GetHitProxyId()

FHitProxyId FCanvas::GetHitProxyId ( ) const
inline

◆ GetParentCanvasSize()

FIntPoint FCanvas::GetParentCanvasSize ( ) const
inline

◆ GetRenderTarget()

FRenderTarget * FCanvas::GetRenderTarget ( ) const
inline

Get the current render target for the canvas

◆ GetScene()

FSceneInterface * FCanvas::GetScene ( ) const
inline

◆ GetShaderPlatform()

EShaderPlatform FCanvas::GetShaderPlatform ( ) const

Access current shader platform

Returns
shader platform that this canvas is rendering at

◆ GetSortElement()

FCanvas::FCanvasSortElement & FCanvas::GetSortElement ( int32  DepthSortKey)

Get the sort element for the given sort key. Allocates a new entry if one does not exist

Parameters
DepthSortKey- the key used to find the sort element entry
Returns
sort element entry

◆ GetTime()

const FGameTime & FCanvas::GetTime ( ) const
inline

Access gameplay time

◆ GetTransform()

FMatrix FCanvas::GetTransform ( ) const
inline

Get the current top-most transform entry without the canvas projection

Returns
matrix from transform stack.

◆ GetTransformStack()

const TArray< FTransformEntry > & FCanvas::GetTransformStack ( ) const
inline

returns the transform stack

◆ GetViewRect()

const FIntRect & FCanvas::GetViewRect ( ) const
inline

◆ HasBatchesToRender()

bool FCanvas::HasBatchesToRender ( ) const

Determine if the canvas has dirty batches that need to be rendered

Returns
true if the canvas has any element to render

◆ IsHitTesting()

bool FCanvas::IsHitTesting ( ) const
inline

◆ IsScaledToRenderTarget()

bool FCanvas::IsScaledToRenderTarget ( ) const
inline

◆ IsStereoRendering()

bool FCanvas::IsStereoRendering ( ) const
inline

◆ IsUsingInternalTexture()

bool FCanvas::IsUsingInternalTexture ( ) const
inline

◆ IsWriteDestinationAlphaSet()

bool FCanvas::IsWriteDestinationAlphaSet ( ) const
inline

◆ PopDepthSortKey()

int32 FCanvas::PopDepthSortKey ( )
inline

Pop sort key off of the stack.

Returns
top entry of the sort key stack

◆ PopTransform()

void FCanvas::PopTransform ( )

Removes the top transform from the canvas's transform stack.

◆ PushAbsoluteTransform()

void FCanvas::PushAbsoluteTransform ( const FMatrix Transform)

Pushes a transform onto the canvas's transform stack.

Parameters
Transform- The transform to push onto the stack.

◆ PushDepthSortKey()

void FCanvas::PushDepthSortKey ( int32  InSortKey)
inline

Push sort key onto the stack. Rendering is done with the current sort key stack entry.

Parameters
InSortKey- key value to push onto the stack

◆ PushRelativeTransform()

void FCanvas::PushRelativeTransform ( const FMatrix Transform)

Pushes a transform onto the canvas's transform stack, multiplying it with the current top of the stack.

Parameters
Transform- The transform to push onto the stack.

◆ SetAllowedModes()

void FCanvas::SetAllowedModes ( uint32  InAllowedModes)
inline

Toggle allowed canvas modes

Parameters
InAllowedModesNew modes to set

◆ SetBaseTransform()

void FCanvas::SetBaseTransform ( const FMatrix Transform)

Replace the base (ie. TransformStack(0)) transform for the canvas with the given matrix

Parameters
Transform- The transform to use for the base

◆ SetHitProxy()

void FCanvas::SetHitProxy ( HHitProxy HitProxy)

Sets the hit proxy which will be used for subsequent canvas primitives.

◆ SetParentCanvasSize()

void FCanvas::SetParentCanvasSize ( FIntPoint  InParentSize)
inline

◆ SetRenderTarget_GameThread()

void FCanvas::SetRenderTarget_GameThread ( FRenderTarget NewRenderTarget)

Sets the render target which will be used for subsequent canvas primitives.

◆ SetRenderTargetDirty()

void FCanvas::SetRenderTargetDirty ( bool  bDirty)
inline

Marks render target as dirty so that it will be resolved to texture

◆ SetRenderTargetRect()

void FCanvas::SetRenderTargetRect ( const FIntRect ViewRect)

Sets a rect that should be used to offset rendering into the viewport render target If not set the canvas will render to the full target

Parameters
ViewRectThe rect to use

◆ SetRenderTargetScissorRect()

void FCanvas::SetRenderTargetScissorRect ( const FIntRect ScissorRect)

The clipping rectangle used when rendering this canvas

Parameters
ScissorRectThe rect to use

◆ SetScaledToRenderTarget()

void FCanvas::SetScaledToRenderTarget ( bool  bScale = true)
inline

◆ SetStereoRendering()

void FCanvas::SetStereoRendering ( bool  bStereo = true)
inline

◆ SetUseInternalTexture()

void FCanvas::SetUseInternalTexture ( const bool  bInUseInternalTexture)
inline

◆ SetWriteDestinationAlpha()

void FCanvas::SetWriteDestinationAlpha ( const bool  bInForceWriteAlpha)
inline

◆ TopDepthSortKey()

int32 FCanvas::TopDepthSortKey ( )
inline

Return top sort key of the stack.

Returns
top entry of the sort key stack

◆ WrapString()

void FCanvas::WrapString ( FTextSizingParameters Parameters,
const float  InCurX,
FStringView  Text,
TArray< FWrappedStringElement > &  out_Lines,
FCanvasWordWrapper::FWrappedLineData *const  OutWrappedLineData = nullptr 
)

Friends And Related Symbol Documentation

◆ FCanvasRenderContext

◆ FCanvasRenderThreadScope

Member Data Documentation

◆ AlphaModulate

float FCanvas::AlphaModulate

◆ LastElementIndex

int32 FCanvas::LastElementIndex

Store index of last Element off to avoid semi expensive Find()

◆ SortedElementLookupMap

TMap<int32,int32> FCanvas::SortedElementLookupMap

Map from sortkey to array index of SortedElements for faster lookup of existing entries

◆ SortedElements

TArray<FCanvasSortElement> FCanvas::SortedElements

Batched canvas elements to be sorted for rendering. Sort order is back-to-front

◆ WordWrapper

TSharedPtr<FCanvasWordWrapper> FCanvas::WordWrapper

Private class for handling word wrapping behavior.


The documentation for this class was generated from the following files: