Open 3D Engine LyShine Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
CDraw2d Class Reference

Implementation of IDraw2d interface for 2D drawing in screen space. More...

#include <Draw2d.h>

Inherits IDraw2d, and AZ::Render::Bootstrap::NotificationBus::Handler.

Classes

class  DeferredLine
 
class  DeferredPrimitive
 
class  DeferredQuad
 
class  DeferredRectOutline
 
class  DeferredText
 
struct  Draw2dShaderData
 

Public Member Functions

 CDraw2d (AZ::RPI::ViewportContextPtr viewportContext=nullptr)
 Constructor, constructed by the LyShine class.
 
void DrawImage (AZ::Data::Instance< AZ::RPI::Image > image, AZ::Vector2 position, AZ::Vector2 size, float opacity=1.0f, float rotation=0.0f, const AZ::Vector2 *pivotPoint=nullptr, const AZ::Vector2 *minMaxTexCoords=nullptr, ImageOptions *imageOptions=nullptr) override
 Draw a textured quad with the top left corner at the given position.
 
void DrawImageAligned (AZ::Data::Instance< AZ::RPI::Image > image, AZ::Vector2 position, AZ::Vector2 size, HAlign horizontalAlignment, VAlign verticalAlignment, float opacity=1.0f, float rotation=0.0f, const AZ::Vector2 *minMaxTexCoords=nullptr, ImageOptions *imageOptions=nullptr) override
 Draw a textured quad where the position specifies the point specified by the alignment.
 
void DrawQuad (AZ::Data::Instance< AZ::RPI::Image > image, VertexPosColUV *verts, Rounding pixelRounding=Rounding::Nearest, bool clamp=false, const RenderState &renderState=RenderState{}) override
 Draw a textured quad where the position, color and uv of each point is specified explicitly.
 
void DrawLine (AZ::Vector2 start, AZ::Vector2 end, AZ::Color color, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, const RenderState &renderState=RenderState{}) override
 Draw a line.
 
void DrawLineTextured (AZ::Data::Instance< AZ::RPI::Image > image, VertexPosColUV *verts, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, const RenderState &renderState=RenderState{}) override
 Draw a line with a texture so it can be dotted or dashed.
 
void DrawText (const char *textString, AZ::Vector2 position, float pointSize, float opacity=1.0f, TextOptions *textOptions=nullptr) override
 Draw a text string. Only supports ASCII text.
 
void DrawRectOutlineTextured (AZ::Data::Instance< AZ::RPI::Image > image, UiTransformInterface::RectPoints points, AZ::Vector2 rightVec, AZ::Vector2 downVec, AZ::Color color, uint32_t lineThickness=0) override
 Draw a rectangular outline with a texture.
 
AZ::Vector2 GetTextSize (const char *textString, float pointSize, TextOptions *textOptions=nullptr) override
 Get the width and height (in pixels) that would be used to draw the given text string.
 
float GetViewportWidth () const override
 Get the width of the rendering viewport (in pixels).
 
float GetViewportHeight () const override
 Get the height of the rendering viewport (in pixels).
 
float GetViewportDpiScalingFactor () const override
 Get dpi scale factor.
 
const ImageOptionsGetDefaultImageOptions () const override
 Get the default values that would be used if no image options were passed in.
 
const TextOptionsGetDefaultTextOptions () const override
 Get the default values that would be used if no text options were passed in.
 
void RenderDeferredPrimitives () override
 Render the primitives that have been deferred.
 
void SetDeferPrimitives (bool deferPrimitives) override
 Specify whether to defer future primitives or render them right away.
 
bool GetDeferPrimitives () override
 Return whether future primitives will be deferred or rendered right away.
 
void SetSortKey (int64_t key) override
 Set sort key offset for following draws.
 
- Public Member Functions inherited from IDraw2d
virtual ~IDraw2d ()
 Implement virtual destructor just for safety.
 
virtual void DrawImage (AZ::Data::Instance< AZ::RPI::Image > image, AZ::Vector2 position, AZ::Vector2 size, float opacity=1.0f, float rotation=0.0f, const AZ::Vector2 *pivotPoint=nullptr, const AZ::Vector2 *minMaxTexCoords=nullptr, ImageOptions *imageOptions=nullptr)=0
 Draw a textured quad with the top left corner at the given position.
 
virtual void DrawImageAligned (AZ::Data::Instance< AZ::RPI::Image > image, AZ::Vector2 position, AZ::Vector2 size, HAlign horizontalAlignment, VAlign verticalAlignment, float opacity=1.0f, float rotation=0.0f, const AZ::Vector2 *minMaxTexCoords=nullptr, ImageOptions *imageOptions=nullptr)=0
 Draw a textured quad where the position specifies the point specified by the alignment.
 
virtual void DrawQuad (AZ::Data::Instance< AZ::RPI::Image > image, VertexPosColUV *verts, Rounding pixelRounding=Rounding::Nearest, bool clamp=false, const RenderState &renderState=RenderState{})=0
 Draw a textured quad where the position, color and uv of each point is specified explicitly.
 
virtual void DrawLine (AZ::Vector2 start, AZ::Vector2 end, AZ::Color color, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, const RenderState &renderState=RenderState{})=0
 Draw a line.
 
virtual void DrawLineTextured (AZ::Data::Instance< AZ::RPI::Image > image, VertexPosColUV *verts, IDraw2d::Rounding pixelRounding=IDraw2d::Rounding::Nearest, const RenderState &renderState=RenderState{})=0
 Draw a line with a texture so it can be dotted or dashed.
 
virtual void DrawText (const char *textString, AZ::Vector2 position, float pointSize, float opacity=1.0f, TextOptions *textOptions=nullptr)=0
 Draw a text string. Only supports ASCII text.
 
virtual void DrawRectOutlineTextured (AZ::Data::Instance< AZ::RPI::Image > image, UiTransformInterface::RectPoints points, AZ::Vector2 rightVec, AZ::Vector2 downVec, AZ::Color color, uint32_t lineThickness=0)=0
 Draw a rectangular outline with a texture.
 
virtual AZ::Vector2 GetTextSize (const char *textString, float pointSize, TextOptions *textOptions=nullptr)=0
 Get the width and height (in pixels) that would be used to draw the given text string.
 
virtual float GetViewportWidth () const =0
 Get the width of the rendering viewport (in pixels).
 
virtual float GetViewportHeight () const =0
 Get the height of the rendering viewport (in pixels).
 
virtual float GetViewportDpiScalingFactor () const =0
 Get dpi scale factor.
 
virtual const ImageOptionsGetDefaultImageOptions () const =0
 Get the default values that would be used if no image options were passed in.
 
virtual const TextOptionsGetDefaultTextOptions () const =0
 Get the default values that would be used if no text options were passed in.
 
virtual void RenderDeferredPrimitives ()=0
 Render the primitives that have been deferred.
 
virtual void SetDeferPrimitives (bool deferPrimitives)=0
 Specify whether to defer future primitives or render them right away.
 
virtual bool GetDeferPrimitives ()=0
 Return whether future primitives will be deferred or rendered right away.
 
virtual void SetSortKey (int64_t key)=0
 Set sort key offset for following draws.
 

Static Public Member Functions

static AZ::Data::Instance< AZ::RPI::Image > LoadTexture (const AZStd::string &pathName)
 Helper to load a texture.
 

Protected Types

enum  { MAX_VERTICES_IN_PRIM = 6 }
 

Protected Member Functions

void RotatePointsAboutPivot (AZ::Vector2 *points, int numPoints, AZ::Vector2 pivot, float angle) const
 Rotate an array of points around the z-axis at the pivot point.
 
void DrawOrDeferQuad (const DeferredQuad *quad)
 Draw or defer a quad.
 
void DrawOrDeferLine (const DeferredLine *line)
 Draw or defer a line.
 
void DrawOrDeferTextString (const DeferredText *text)
 Draw or defer a text string.
 
void DrawOrDeferRectOutline (const DeferredRectOutline *outlineRect)
 Draw or defer a rect outline.
 
AZ::RPI::ViewportContextPtr GetViewportContext () const
 Get specified viewport context or default viewport context if not specified.
 

Protected Attributes

ImageOptions m_defaultImageOptions
 The default image options used if nullptr is passed.
 
TextOptions m_defaultTextOptions
 The default text options used if nullptr is passed.
 
bool m_deferCalls
 True if the actual render of the primitives should be deferred to a RenderDeferredPrimitives call.
 
std::vector< DeferredPrimitive * > m_deferredPrimitives
 
AZ::RPI::ViewportContextPtr m_viewportContext
 
AZ::RHI::Ptr< AZ::RPI::DynamicDrawContext > m_dynamicDraw
 
Draw2dShaderData m_shaderData
 

Additional Inherited Members

- Public Types inherited from IDraw2d
enum class  HAlign { Left , Center , Right }
 Horizontal alignment can be used for both text and image drawing.
 
enum class  VAlign { Top , Center , Bottom }
 Vertical alignment can be used for both text and image drawing.
 
enum class  Rounding { None , Nearest , Down , Up }
 Used for specifying how to round positions to an exact pixel position for pixel-perfect rendering.
 
enum  { MAX_TEXT_STRING_LENGTH = 1024 }
 

Detailed Description

Implementation of IDraw2d interface for 2D drawing in screen space.

The CDraw2d class implements the IDraw2d interface for drawing 2D images, shapes and text. Positions and sizes are specified in pixels in the associated 2D viewport.

Member Function Documentation

◆ DrawImage()

void CDraw2d::DrawImage ( AZ::Data::Instance< AZ::RPI::Image >  image,
AZ::Vector2  position,
AZ::Vector2  size,
float  opacity = 1.0f,
float  rotation = 0.0f,
const AZ::Vector2 *  pivotPoint = nullptr,
const AZ::Vector2 *  minMaxTexCoords = nullptr,
ImageOptions imageOptions = nullptr 
)
overridevirtual

Draw a textured quad with the top left corner at the given position.

The image is drawn with the color specified by SetShapeColor and the opacity passed as an argument. If rotation is non-zero then the quad is rotated. If the pivot point is provided then the points of the quad are rotated about that point, otherwise they are rotated about the top left corner of the quad.

Parameters
texIdThe texture ID returned by ITexture::GetTextureID()
positionPosition of the top left corner of the quad (before rotation) in pixels
sizeThe width and height of the quad. Use texture width and height to avoid minification, magnification or stretching (assuming the minMaxTexCoords are left to the default)
opacityThe alpha value used when blending
rotationAngle of rotation in degrees counter-clockwise
pivotPointThe point about which the quad is rotated
minMaxTexCoordsAn optional two component array. The first component is the UV coord for the top left point of the quad and the second is the UV coord of the bottom right point of the quad
imageOptionsOptional struct specifying options that tend to be the same from call to call

Implements IDraw2d.

◆ DrawImageAligned()

void CDraw2d::DrawImageAligned ( AZ::Data::Instance< AZ::RPI::Image >  image,
AZ::Vector2  position,
AZ::Vector2  size,
HAlign  horizontalAlignment,
VAlign  verticalAlignment,
float  opacity = 1.0f,
float  rotation = 0.0f,
const AZ::Vector2 *  minMaxTexCoords = nullptr,
ImageOptions imageOptions = nullptr 
)
overridevirtual

Draw a textured quad where the position specifies the point specified by the alignment.

Rotation is always around the position.

Parameters
texIdThe texture ID returned by ITexture::GetTextureID()
positionPosition align point of the quad (before rotation) in pixels
sizeThe width and height of the quad. Use texture width and height to avoid minification, magnification or stretching (assuming the minMaxTexCoords are left to the default)
horizontalAlignmentSpecifies how the quad is horizontally aligned to the given position
verticalAlignmentSpecifies how the quad is vertically aligned to the given position
opacityThe alpha value used when blending
rotationAngle of rotation in degrees counter-clockwise
minMaxTexCoordsAn optional two component array. The first component is the UV coord for the top left point of the quad and the second is the UV coord of the bottom right point of the quad
imageOptionsOptional struct specifying options that tend to be the same from call to call

Implements IDraw2d.

◆ DrawLine()

void CDraw2d::DrawLine ( AZ::Vector2  start,
AZ::Vector2  end,
AZ::Color  color,
IDraw2d::Rounding  pixelRounding = IDraw2d::Rounding::Nearest,
const RenderState renderState = RenderState{} 
)
overridevirtual

Draw a line.

Parameters
startThe start position
endThe end position
colorThe color of the line
pixelRoundingWhether and how to round pixel coordinates
renderStateBlend mode and depth state

Implements IDraw2d.

◆ DrawLineTextured()

void CDraw2d::DrawLineTextured ( AZ::Data::Instance< AZ::RPI::Image >  image,
VertexPosColUV verts,
IDraw2d::Rounding  pixelRounding = IDraw2d::Rounding::Nearest,
const RenderState renderState = RenderState{} 
)
overridevirtual

Draw a line with a texture so it can be dotted or dashed.

Parameters
texIdThe texture ID returned by ITexture::GetTextureID()
vertsAn array of 2 vertices for the start and end points of the line
pixelRoundingWhether and how to round pixel coordinates
renderStateBlend mode and depth state

Implements IDraw2d.

◆ DrawQuad()

void CDraw2d::DrawQuad ( AZ::Data::Instance< AZ::RPI::Image >  image,
VertexPosColUV verts,
Rounding  pixelRounding = Rounding::Nearest,
bool  clamp = false,
const RenderState renderState = RenderState{} 
)
overridevirtual

Draw a textured quad where the position, color and uv of each point is specified explicitly.

Parameters
texIdThe texture ID returned by ITexture::GetTextureID()
vertsAn array of 4 vertices, in clockwise order (e.g. top left, top right, bottom right, bottom left)
pixelRoundingWhether and how to round pixel coordinates
renderStateBlend mode and depth state

Implements IDraw2d.

◆ DrawRectOutlineTextured()

void CDraw2d::DrawRectOutlineTextured ( AZ::Data::Instance< AZ::RPI::Image >  image,
UiTransformInterface::RectPoints  points,
AZ::Vector2  rightVec,
AZ::Vector2  downVec,
AZ::Color  color,
uint32_t  lineThickness = 0 
)
overridevirtual

Draw a rectangular outline with a texture.

Parameters
imageThe texture to be used for drawing the outline
pointsThe rect's vertices (top left, top right, bottom right, bottom left)
rightVecRight vector. Specified because the rect's width/height could be 0
downVecDown vector. Specified because the rect's width/height could be 0
colorThe color of the outline
lineThicknessThe thickness in pixels of the outline. If 0, it will be based on image height

Implements IDraw2d.

◆ DrawText()

void CDraw2d::DrawText ( const char *  textString,
AZ::Vector2  position,
float  pointSize,
float  opacity = 1.0f,
TextOptions textOptions = nullptr 
)
overridevirtual

Draw a text string. Only supports ASCII text.

The font and effect used to render the text are specified in the textOptions structure

Parameters
textStringA null terminated ASCII text string. May contain
characters
positionPosition of the text in pixels. Alignment values in textOptions affect actual position
pointSizeThe size of the font to use
opacityThe opacity (alpha value) to use to draw the text
textOptionsPointer to an options struct. If null the default options are used

Implements IDraw2d.

◆ GetDefaultImageOptions()

const ImageOptions & CDraw2d::GetDefaultImageOptions ( ) const
overridevirtual

Get the default values that would be used if no image options were passed in.

This is a convenient way to initialize the imageOptions struct

Implements IDraw2d.

◆ GetDefaultTextOptions()

const TextOptions & CDraw2d::GetDefaultTextOptions ( ) const
overridevirtual

Get the default values that would be used if no text options were passed in.

This is a convenient way to initialize the textOptions struct

Implements IDraw2d.

◆ GetDeferPrimitives()

bool CDraw2d::GetDeferPrimitives ( )
overridevirtual

Return whether future primitives will be deferred or rendered right away.

Implements IDraw2d.

◆ GetTextSize()

AZ::Vector2 CDraw2d::GetTextSize ( const char *  textString,
float  pointSize,
TextOptions textOptions = nullptr 
)
overridevirtual

Get the width and height (in pixels) that would be used to draw the given text string.

Pass the same parameter values that would be used to draw the string

Implements IDraw2d.

◆ GetViewportDpiScalingFactor()

float CDraw2d::GetViewportDpiScalingFactor ( ) const
overridevirtual

Get dpi scale factor.

Implements IDraw2d.

◆ GetViewportHeight()

float CDraw2d::GetViewportHeight ( ) const
overridevirtual

Get the height of the rendering viewport (in pixels).

Implements IDraw2d.

◆ GetViewportWidth()

float CDraw2d::GetViewportWidth ( ) const
overridevirtual

Get the width of the rendering viewport (in pixels).

Implements IDraw2d.

◆ RenderDeferredPrimitives()

void CDraw2d::RenderDeferredPrimitives ( )
overridevirtual

Render the primitives that have been deferred.

Implements IDraw2d.

◆ RotatePointsAboutPivot()

void CDraw2d::RotatePointsAboutPivot ( AZ::Vector2 *  points,
int  numPoints,
AZ::Vector2  pivot,
float  angle 
) const
protected

Rotate an array of points around the z-axis at the pivot point.

Angle is in degrees counter-clockwise

◆ SetDeferPrimitives()

void CDraw2d::SetDeferPrimitives ( bool  deferPrimitives)
overridevirtual

Specify whether to defer future primitives or render them right away.

Implements IDraw2d.

◆ SetSortKey()

void CDraw2d::SetSortKey ( int64_t  key)
overridevirtual

Set sort key offset for following draws.

Implements IDraw2d.


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