Reenable blend mode and depth state options in Draw2d (#2254)

* Reenable blend mode and depth state options in Draw2d
* Add back compile warning fix from last merge

Signed-off-by: abrmich <abrmich@amazon.com>
This commit is contained in:
michabr
2021-09-01 15:42:16 -07:00
committed by GitHub
parent f58b51b8ad
commit 413e82428c
11 changed files with 160 additions and 174 deletions
-52
View File
@@ -12,9 +12,6 @@
#include <AzCore/Math/Color.h>
#include <AzCore/std/string/string.h>
// Forward declarations
struct IFFont;
////////////////////////////////////////////////////////////////////////////////////////////////////
//! Class for 2D drawing in screen space
//
@@ -58,55 +55,6 @@ public: // types
MAX_TEXT_STRING_LENGTH = 1024,
};
enum : int
{
//! Constant that indicates the built-in default value should be used
UseDefault = -1
};
//! Struct used to pass additional image options.
//
//! If this is not passed then the defaults below are used
struct ImageOptions
{
int blendMode; //!< default is GS_BLSRC_SRCALPHA|GS_BLDST_ONEMINUSSRCALPHA
AZ::Vector3 color; //!< default is (1,1,1)
Rounding pixelRounding; //!< default is Rounding::Nearest
int baseState; //!< Additional flags for SetState. Default is GS_NODEPTHTEST
};
//! Struct used to pass additional text options - mostly ones that do not change from call to call.
//
//! If this is not passed then the defaults below are used
struct TextOptions
{
AZStd::string fontName; //!< default is "default"
unsigned int effectIndex; //!< default is 0
AZ::Vector3 color; //!< default is (1,1,1)
HAlign horizontalAlignment; //!< default is HAlign::Left
VAlign verticalAlignment; //!< default is VAlign::Top
AZ::Vector2 dropShadowOffset; //!< default is (0,0), zero offset means no drop shadow is drawn
AZ::Color dropShadowColor; //!< default is (0,0,0,0), zero alpha means no drop shadow is drawn
float rotation; //!< default is 0
int baseState; //!< Additional flags for SetState. Default is GS_NODEPTHTEST
};
//! Used to pass in arrays of vertices (e.g. to DrawQuad)
struct VertexPosColUV
{
VertexPosColUV(){}
VertexPosColUV(const AZ::Vector2& inPos, const AZ::Color& inColor, const AZ::Vector2& inUV)
{
position = inPos;
color = inColor;
uv = inUV;
}
AZ::Vector2 position; //!< 2D position of vertex
AZ::Color color; //!< Float color
AZ::Vector2 uv; //!< Texture coordinate
};
public: // member functions
//! Implement virtual destructor just for safety.
-1
View File
@@ -9,7 +9,6 @@
#include <Cry_Geo.h>
#include <Include/IPlugin.h>
#include <IRenderer.h>
#include <QtWidgets/QMainWindow>
#include <LyShine/IDraw2d.h>
#include <LyShine/ILyShine.h>
+6 -3
View File
@@ -172,20 +172,23 @@ namespace GuideHelpers
// the line is drawn as the inverse of the background color
AZ::Color guideColor(1.0f, 1.0f, 1.0f, 1.0f);
int blendMode = GS_BLSRC_ONEMINUSDSTCOL|GS_BLDST_ZERO;
CDraw2d::RenderState renderState;
renderState.m_blendState.m_blendSource = AZ::RHI::BlendFactor::ColorDestInverse;
renderState.m_blendState.m_blendDest = AZ::RHI::BlendFactor::Zero;
// Draw the guide line
if (guideIsVertical)
{
AZ::Vector2 start(viewportPoint.GetX(), 0);
AZ::Vector2 end(viewportPoint.GetX(), viewportSize.GetY());
draw2d.DrawLine(start, end, guideColor, blendMode);
draw2d.DrawLine(start, end, guideColor, IDraw2d::Rounding::Nearest, renderState);
}
else
{
AZ::Vector2 start(0, viewportPoint.GetY());
AZ::Vector2 end(viewportSize.GetX(), viewportPoint.GetY());
draw2d.DrawLine(start, end, guideColor, blendMode);
draw2d.DrawLine(start, end, guideColor, IDraw2d::Rounding::Nearest, renderState);
}
}
@@ -50,7 +50,7 @@ void ViewportCanvasBackground::Draw(Draw2dHelper& draw2d, const AZ::Vector2& can
// now draw the same as Stretched but with UV's adjusted
const AZ::Vector2 uvs[4] = { AZ::Vector2(0, 0), AZ::Vector2(uvScale.GetX(), 0), AZ::Vector2(uvScale.GetX(), uvScale.GetY()), AZ::Vector2(0, uvScale.GetY()) };
AZ::Color colorWhite(1.0f, 1.0f, 1.0f, 1.0f);
IDraw2d::VertexPosColUV verts[4];
CDraw2d::VertexPosColUV verts[4];
for (int i = 0; i < 4; ++i)
{
verts[i].position = positions[i];
@@ -58,5 +58,5 @@ void ViewportCanvasBackground::Draw(Draw2dHelper& draw2d, const AZ::Vector2& can
verts[i].uv = uvs[i];
}
m_canvasBackground->DrawImageTiled(draw2d, verts, 1.0f);
m_canvasBackground->DrawImageTiled(draw2d, verts);
}
+5 -6
View File
@@ -48,12 +48,11 @@ void ViewportIcon::DrawImageAligned(Draw2dHelper& draw2d, AZ::Vector2& pivot, fl
opacity);
}
void ViewportIcon::DrawImageTiled(Draw2dHelper& draw2d, IDraw2d::VertexPosColUV* verts, [[maybe_unused]] float opacity)
void ViewportIcon::DrawImageTiled(Draw2dHelper& draw2d, CDraw2d::VertexPosColUV* verts)
{
// Use default blending and rounding modes
int blendMode = GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA;
IDraw2d::Rounding rounding = IDraw2d::Rounding::Nearest;
draw2d.DrawQuad(m_image, verts, blendMode, rounding);
draw2d.DrawQuad(m_image, verts, rounding);
}
void ViewportIcon::DrawAxisAlignedBoundingBox(Draw2dHelper& draw2d, AZ::Vector2 bound0, AZ::Vector2 bound1)
@@ -64,7 +63,7 @@ void ViewportIcon::DrawAxisAlignedBoundingBox(Draw2dHelper& draw2d, AZ::Vector2
float endTexCoordU = fabsf((bound1.GetX() - bound0.GetX()) * pixelLengthForDottedLineTexture);
float endTexCoordV = fabsf((bound1.GetY() - bound0.GetY()) * pixelLengthForDottedLineTexture);
IDraw2d::VertexPosColUV verts[2];
CDraw2d::VertexPosColUV verts[2];
{
verts[0].color = dottedColor;
verts[1].color = dottedColor;
@@ -159,7 +158,7 @@ void ViewportIcon::Draw(Draw2dHelper& draw2d, AZ::Vector2 anchorPos, const AZ::M
AZ::Matrix4x4 moveFromPivotSpaceMat = AZ::Matrix4x4::CreateTranslation(pivot3);
AZ::Matrix4x4 newTransform = transform * moveFromPivotSpaceMat * rotMat * moveToPivotSpaceMat;
IDraw2d::VertexPosColUV verts[4];
CDraw2d::VertexPosColUV verts[4];
// points are a clockwise quad
static const AZ::Vector2 uvs[4] = {
AZ::Vector2(0.0f, 0.0f), AZ::Vector2(1.0f, 0.0f), AZ::Vector2(1.0f, 1.0f), AZ::Vector2(0.0f, 1.0f)
@@ -252,7 +251,7 @@ void ViewportIcon::DrawDistanceLine(Draw2dHelper& draw2d, AZ::Vector2 start, AZ:
const float pixelLengthForDottedLineTexture = 8.0f;
float endTexCoordU = length / pixelLengthForDottedLineTexture;
IDraw2d::VertexPosColUV verts[2];
CDraw2d::VertexPosColUV verts[2];
verts[0].position = start;
verts[0].color = dottedColor;
+1 -1
View File
@@ -20,7 +20,7 @@ public:
void DrawImageAligned(Draw2dHelper& draw2d, AZ::Vector2& pivot, float opacity);
void DrawImageTiled(Draw2dHelper& draw2d, IDraw2d::VertexPosColUV* verts, float opacity);
void DrawImageTiled(Draw2dHelper& draw2d, CDraw2d::VertexPosColUV* verts);
void Draw(Draw2dHelper& draw2d, AZ::Vector2 anchorPos, const AZ::Matrix4x4& transform, float iconRot = 0.0f, AZ::Color color = AZ::Color(1.0f, 1.0f, 1.0f, 1.0f)) const;
+86 -30
View File
@@ -26,6 +26,65 @@ class CDraw2d
: public IDraw2d // LYSHINE_ATOM_TODO - keep around until gEnv->pLyShine is replaced by bus interface
, public AZ::Render::Bootstrap::NotificationBus::Handler
{
public: // types
struct RenderState
{
RenderState()
{
m_blendState.m_enable = true;
m_blendState.m_blendSource = AZ::RHI::BlendFactor::AlphaSource;
m_blendState.m_blendDest = AZ::RHI::BlendFactor::AlphaSourceInverse;
m_depthState.m_enable = false;
}
AZ::RHI::TargetBlendState m_blendState;
AZ::RHI::DepthState m_depthState;
};
//! Struct used to pass additional image options.
//
//! If this is not passed then the defaults are used
struct ImageOptions
{
AZ::Vector3 color = AZ::Vector3(1.0f, 1.0f, 1.0f);
Rounding pixelRounding = Rounding::Nearest;
RenderState m_renderState;
};
//! Struct used to pass additional text options - mostly ones that do not change from call to call.
//
//! If this is not passed then the defaults below are used
struct TextOptions
{
AZStd::string fontName; //!< default is "default"
unsigned int effectIndex; //!< default is 0
AZ::Vector3 color; //!< default is (1,1,1)
HAlign horizontalAlignment; //!< default is HAlign::Left
VAlign verticalAlignment; //!< default is VAlign::Top
AZ::Vector2 dropShadowOffset; //!< default is (0,0), zero offset means no drop shadow is drawn
AZ::Color dropShadowColor; //!< default is (0,0,0,0), zero alpha means no drop shadow is drawn
float rotation; //!< default is 0
bool depthTestEnabled; //!< default is false
};
//! Used to pass in arrays of vertices (e.g. to DrawQuad)
struct VertexPosColUV
{
VertexPosColUV() {}
VertexPosColUV(const AZ::Vector2& inPos, const AZ::Color& inColor, const AZ::Vector2& inUV)
{
position = inPos;
color = inColor;
uv = inUV;
}
AZ::Vector2 position; //!< 2D position of vertex
AZ::Color color; //!< Float color
AZ::Vector2 uv; //!< Texture coordinate
};
public: // member functions
//! Constructor, constructed by the LyShine class
@@ -81,40 +140,34 @@ public: // member functions
//
//! \param texId The texture ID returned by ITexture::GetTextureID()
//! \param verts An array of 4 vertices, in clockwise order (e.g. top left, top right, bottom right, bottom left)
//! \param blendMode UseDefault means default blend mode (currently GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA)
//! \param pixelRounding Whether and how to round pixel coordinates
//! \param baseState Additional render state to pass to or into value passed to renderer SetState
//! \param renderState Blend mode and depth state
virtual void DrawQuad(AZ::Data::Instance<AZ::RPI::Image> image,
VertexPosColUV* verts,
int blendMode = UseDefault,
Rounding pixelRounding = Rounding::Nearest,
int baseState = UseDefault);
const RenderState& renderState = RenderState{});
//! Draw a line
//
//! \param start The start position
//! \param end The end position
//! \param color The color of the line
//! \param blendMode UseDefault means default blend mode (currently GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA)
//! \param pixelRounding Whether and how to round pixel coordinates
//! \param baseState Additional render state to pass to or into value passed to renderer SetState
//! \param renderState Blend mode and depth state
virtual void DrawLine(AZ::Vector2 start, AZ::Vector2 end, AZ::Color color,
int blendMode = UseDefault,
IDraw2d::Rounding pixelRounding = IDraw2d::Rounding::Nearest,
int baseState = UseDefault);
const RenderState& renderState = RenderState{});
//! Draw a line with a texture so it can be dotted or dashed
//
//! \param texId The texture ID returned by ITexture::GetTextureID()
//! \param verts An array of 2 vertices for the start and end points of the line
//! \param blendMode UseDefault means default blend mode (currently GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA)
//! \param pixelRounding Whether and how to round pixel coordinates
//! \param baseState Additional render state to pass to or into value passed to renderer SetState
//! \param renderState Blend mode and depth state
virtual void DrawLineTextured(AZ::Data::Instance<AZ::RPI::Image> image,
VertexPosColUV* verts,
int blendMode = UseDefault,
IDraw2d::Rounding pixelRounding = IDraw2d::Rounding::Nearest,
int baseState = UseDefault);
const RenderState& renderState = RenderState{});
//! Draw a text string. Only supports ASCII text.
//
//! The font and effect used to render the text are specified in the textOptions structure
@@ -225,7 +278,7 @@ protected: // types and constants
AZ::Vector2 m_texCoords[4];
uint32 m_packedColors[4];
AZ::Data::Instance<AZ::RPI::Image> m_image;
int m_state;
RenderState m_renderState;
};
class DeferredLine
@@ -241,7 +294,7 @@ protected: // types and constants
AZ::Vector2 m_points[2];
AZ::Vector2 m_texCoords[2];
uint32 m_packedColors[2];
int m_state;
RenderState m_renderState;
};
class DeferredText
@@ -286,7 +339,7 @@ protected: // member functions
//! Helper function to render a text string
void DrawTextInternal(const char* textString, AzFramework::FontId fontId, unsigned int effectIndex,
AZ::Vector2 position, float pointSize, AZ::Color color, float rotation,
HAlign horizontalAlignment, VAlign verticalAlignment, int baseState);
HAlign horizontalAlignment, VAlign verticalAlignment, bool depthTestEnabled);
//! Draw or defer a quad
void DrawOrDeferQuad(const DeferredQuad* quad);
@@ -397,39 +450,39 @@ public: // member functions
//! Draw a textured quad where the position, color and uv of each point is specified explicitly
//
//! See IDraw2d:DrawQuad for parameter descriptions
void DrawQuad(AZ::Data::Instance<AZ::RPI::Image> image, IDraw2d::VertexPosColUV* verts, int blendMode = IDraw2d::UseDefault,
void DrawQuad(AZ::Data::Instance<AZ::RPI::Image> image, CDraw2d::VertexPosColUV* verts,
IDraw2d::Rounding pixelRounding = IDraw2d::Rounding::Nearest,
int baseState = IDraw2d::UseDefault)
const CDraw2d::RenderState& renderState = CDraw2d::RenderState{})
{
if (m_draw2d)
{
m_draw2d->DrawQuad(image, verts, blendMode, pixelRounding, baseState);
m_draw2d->DrawQuad(image, verts, pixelRounding, renderState);
}
}
//! Draw a line
//
//! See IDraw2d:DrawLine for parameter descriptions
void DrawLine(AZ::Vector2 start, AZ::Vector2 end, AZ::Color color, int blendMode = IDraw2d::UseDefault,
void DrawLine(AZ::Vector2 start, AZ::Vector2 end, AZ::Color color,
IDraw2d::Rounding pixelRounding = IDraw2d::Rounding::Nearest,
int baseState = IDraw2d::UseDefault)
const CDraw2d::RenderState& renderState = CDraw2d::RenderState{})
{
if (m_draw2d)
{
m_draw2d->DrawLine(start, end, color, blendMode, pixelRounding, baseState);
m_draw2d->DrawLine(start, end, color, pixelRounding, renderState);
}
}
//! Draw a line with a texture so it can be dotted or dashed
//
//! See IDraw2d:DrawLineTextured for parameter descriptions
void DrawLineTextured(AZ::Data::Instance<AZ::RPI::Image> image, IDraw2d::VertexPosColUV* verts, int blendMode = IDraw2d::UseDefault,
void DrawLineTextured(AZ::Data::Instance<AZ::RPI::Image> image, CDraw2d::VertexPosColUV* verts,
IDraw2d::Rounding pixelRounding = IDraw2d::Rounding::Nearest,
int baseState = IDraw2d::UseDefault)
const CDraw2d::RenderState& renderState = CDraw2d::RenderState{})
{
if (m_draw2d)
{
m_draw2d->DrawLineTextured(image, verts, blendMode, pixelRounding, baseState);
m_draw2d->DrawLineTextured(image, verts, pixelRounding, renderState);
}
}
@@ -478,7 +531,7 @@ public: // member functions
// State management
//! Set the blend mode used for images, default is GS_BLSRC_SRCALPHA|GS_BLDST_ONEMINUSSRCALPHA.
void SetImageBlendMode(int mode) { m_imageOptions.blendMode = mode; }
void SetImageBlendMode(const AZ::RHI::TargetBlendState& blendState) { m_imageOptions.m_renderState.m_blendState = blendState; }
//! Set the color used for DrawImage and other image drawing.
void SetImageColor(AZ::Vector3 color) { m_imageOptions.color = color; }
@@ -487,7 +540,7 @@ public: // member functions
void SetImagePixelRounding(IDraw2d::Rounding round) { m_imageOptions.pixelRounding = round; }
//! Set the base state (that blend mode etc is combined with) used for images, default is GS_NODEPTHTEST.
void SetImageBaseState(int state) { m_imageOptions.baseState = state; }
void SetImageDepthState(const AZ::RHI::DepthState& depthState) { m_imageOptions.m_renderState.m_depthState = depthState; }
//! Set the text font.
void SetTextFont(AZStd::string_view fontName) { m_textOptions.fontName = fontName; }
@@ -518,8 +571,11 @@ public: // member functions
m_textOptions.rotation = rotation;
}
//! Set the base state (that blend mode etc is combined with) used for text, default is GS_NODEPTHTEST.
void SetTextBaseState(int state) { m_textOptions.baseState = state; }
//! Set wheter to enable depth test for the text
void SetTextDepthTestEnabled(bool enabled)
{
m_textOptions.depthTestEnabled = enabled;
}
public: // static member functions
@@ -565,8 +621,8 @@ public: // static member functions
protected: // attributes
IDraw2d::ImageOptions m_imageOptions; //!< image options are stored locally and updated by member functions
IDraw2d::TextOptions m_textOptions; //!< text options are stored locally and updated by member functions
CDraw2d::ImageOptions m_imageOptions; //!< image options are stored locally and updated by member functions
CDraw2d::TextOptions m_textOptions; //!< text options are stored locally and updated by member functions
CDraw2d* m_draw2d;
bool m_previousDeferCalls;
};
+21 -41
View File
@@ -5,7 +5,6 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "IFont.h"
#include <IRenderer.h> // for SVF_P3F_C4B_T2F which will be removed in a coming PR
#include <LyShine/Draw2d.h>
@@ -23,9 +22,6 @@
#include <Atom/RPI.Public/RPIUtils.h>
#include <Atom/RPI.Public/ViewportContextBus.h>
static const int g_defaultBlendState = GS_BLSRC_SRCALPHA | GS_BLDST_ONEMINUSSRCALPHA;
static const int g_defaultBaseState = GS_NODEPTHTEST;
////////////////////////////////////////////////////////////////////////////////////////////////////
// LOCAL STATIC FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,10 +44,6 @@ CDraw2d::CDraw2d(AZ::RPI::ViewportContextPtr viewportContext)
{
// These default options are set here and never change. They are stored so that if a null options
// structure is passed into the draw functions then this default one can be used instead
m_defaultImageOptions.blendMode = g_defaultBlendState;
m_defaultImageOptions.color.Set(1.0f, 1.0f, 1.0f);
m_defaultImageOptions.pixelRounding = Rounding::Nearest;
m_defaultImageOptions.baseState = g_defaultBaseState;
m_defaultTextOptions.fontName = "default";
m_defaultTextOptions.effectIndex = 0;
@@ -61,7 +53,7 @@ CDraw2d::CDraw2d(AZ::RPI::ViewportContextPtr viewportContext)
m_defaultTextOptions.dropShadowOffset.Set(0.0f, 0.0f);
m_defaultTextOptions.dropShadowColor.Set(0.0f, 0.0f, 0.0f, 0.0f);
m_defaultTextOptions.rotation = 0.0f;
m_defaultTextOptions.baseState = g_defaultBaseState;
m_defaultTextOptions.depthTestEnabled = false;
AZ::Render::Bootstrap::NotificationBus::Handler::BusConnect();
}
@@ -112,7 +104,8 @@ void CDraw2d::OnBootstrapSceneReady([[maybe_unused]] AZ::RPI::Scene* bootstrapSc
{"COLOR", AZ::RHI::Format::B8G8R8A8_UNORM},
{"TEXCOORD0", AZ::RHI::Format::R32G32_FLOAT} });
m_dynamicDraw->AddDrawStateOptions(AZ::RPI::DynamicDrawContext::DrawStateOptions::PrimitiveType
| AZ::RPI::DynamicDrawContext::DrawStateOptions::BlendMode);
| AZ::RPI::DynamicDrawContext::DrawStateOptions::BlendMode
| AZ::RPI::DynamicDrawContext::DrawStateOptions::DepthState);
if (uiCanvasPass)
{
m_dynamicDraw->SetOutputScope(uiCanvasPass);
@@ -124,12 +117,6 @@ void CDraw2d::OnBootstrapSceneReady([[maybe_unused]] AZ::RPI::Scene* bootstrapSc
}
m_dynamicDraw->EndInit();
AZ::RHI::TargetBlendState targetBlendState;
targetBlendState.m_enable = true;
targetBlendState.m_blendSource = AZ::RHI::BlendFactor::AlphaSource;
targetBlendState.m_blendDest = AZ::RHI::BlendFactor::AlphaSourceInverse;
m_dynamicDraw->SetTarget0BlendState(targetBlendState);
// Cache draw srg input indices for later use
static const char textureIndexName[] = "m_texture";
static const char worldToProjIndexName[] = "m_worldToProj";
@@ -154,8 +141,6 @@ void CDraw2d::DrawImage(AZ::Data::Instance<AZ::RPI::Image> image, AZ::Vector2 po
AZ::Color color = AZ::Color::CreateFromVector3AndFloat(actualImageOptions->color, opacity);
AZ::u32 packedColor = PackARGB8888(color);
int blendMode = actualImageOptions->blendMode;
// Depending on the requested pixel rounding setting we may round position to an exact pixel
AZ::Vector2 pos = Draw2dHelper::RoundXY(position, actualImageOptions->pixelRounding);
@@ -189,7 +174,7 @@ void CDraw2d::DrawImage(AZ::Data::Instance<AZ::RPI::Image> image, AZ::Vector2 po
quad.m_image = image;
// add the blendMode flags to the base state
quad.m_state = blendMode | actualImageOptions->baseState;
quad.m_renderState = actualImageOptions->m_renderState;
// apply rotation if requested
if (rotation != 0.0f)
@@ -212,11 +197,9 @@ void CDraw2d::DrawImageAligned(AZ::Data::Instance<AZ::RPI::Image> image, AZ::Vec
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void CDraw2d::DrawQuad(AZ::Data::Instance<AZ::RPI::Image> image, VertexPosColUV* verts, int blendMode, Rounding pixelRounding, int baseState)
void CDraw2d::DrawQuad(AZ::Data::Instance<AZ::RPI::Image> image, VertexPosColUV* verts, Rounding pixelRounding,
const CDraw2d::RenderState& renderState)
{
int actualBlendMode = (blendMode == -1) ? g_defaultBlendState : blendMode;
int actualBaseState = (baseState == -1) ? g_defaultBaseState : baseState;
// define quad
DeferredQuad quad;
for (int i = 0; i < 4; ++i)
@@ -228,20 +211,17 @@ void CDraw2d::DrawQuad(AZ::Data::Instance<AZ::RPI::Image> image, VertexPosColUV*
quad.m_image = image;
// add the blendMode flags to the base state
quad.m_state = actualBlendMode | actualBaseState;
quad.m_renderState = renderState;
DrawOrDeferQuad(&quad);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void CDraw2d::DrawLine(AZ::Vector2 start, AZ::Vector2 end, AZ::Color color, int blendMode, Rounding pixelRounding, int baseState)
void CDraw2d::DrawLine(AZ::Vector2 start, AZ::Vector2 end, AZ::Color color, Rounding pixelRounding,
const CDraw2d::RenderState& renderState)
{
int actualBaseState = (baseState == -1) ? g_defaultBaseState : baseState;
auto image = AZ::RPI::ImageSystemInterface::Get()->GetSystemImage(AZ::RPI::SystemImage::White);
int actualBlendMode = (blendMode == -1) ? g_defaultBlendState : blendMode;
// define line
uint32 packedColor = PackARGB8888(color);
@@ -258,19 +238,16 @@ void CDraw2d::DrawLine(AZ::Vector2 start, AZ::Vector2 end, AZ::Color color, int
line.m_packedColors[1] = packedColor;
// add the blendMode flags to the base state
line.m_state = actualBlendMode | actualBaseState;
line.m_renderState = renderState;
DrawOrDeferLine(&line);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
void CDraw2d::DrawLineTextured(AZ::Data::Instance<AZ::RPI::Image> image, VertexPosColUV* verts, int blendMode, Rounding pixelRounding, int baseState)
void CDraw2d::DrawLineTextured(AZ::Data::Instance<AZ::RPI::Image> image, VertexPosColUV* verts, Rounding pixelRounding,
const CDraw2d::RenderState& renderState)
{
int actualBaseState = (baseState == -1) ? g_defaultBaseState : baseState;
int actualBlendMode = (blendMode == -1) ? g_defaultBlendState : blendMode;
// define line
DeferredLine line;
line.m_image = image;
@@ -283,7 +260,7 @@ void CDraw2d::DrawLineTextured(AZ::Data::Instance<AZ::RPI::Image> image, VertexP
}
// add the blendMode flags to the base state
line.m_state = actualBlendMode | actualBaseState;
line.m_renderState = renderState;
DrawOrDeferLine(&line);
}
@@ -313,7 +290,7 @@ void CDraw2d::DrawText(const char* textString, AZ::Vector2 position, float point
dropShadowPosition, pointSize, actualTextOptions->dropShadowColor,
actualTextOptions->rotation,
actualTextOptions->horizontalAlignment, actualTextOptions->verticalAlignment,
actualTextOptions->baseState);
actualTextOptions->depthTestEnabled);
}
// draw the text string
@@ -322,7 +299,7 @@ void CDraw2d::DrawText(const char* textString, AZ::Vector2 position, float point
position, pointSize, textColor,
actualTextOptions->rotation,
actualTextOptions->horizontalAlignment, actualTextOptions->verticalAlignment,
actualTextOptions->baseState);
actualTextOptions->depthTestEnabled);
}
void CDraw2d::DrawRectOutlineTextured(AZ::Data::Instance<AZ::RPI::Image> image,
@@ -594,7 +571,7 @@ void CDraw2d::RotatePointsAboutPivot(AZ::Vector2* points, [[maybe_unused]] int n
////////////////////////////////////////////////////////////////////////////////////////////////////
void CDraw2d::DrawTextInternal(const char* textString, AzFramework::FontId fontId, unsigned int effectIndex,
AZ::Vector2 position, float pointSize, AZ::Color color, float rotation,
HAlign horizontalAlignment, VAlign verticalAlignment, [[maybe_unused]] int baseState)
HAlign horizontalAlignment, VAlign verticalAlignment, bool depthTestEnabled)
{
// FFont.cpp uses the alpha value of the color to decide whether to use the color, if the alpha value is zero
// (in a ColorB format) then the color set via SetColor is ignored and it usually ends up drawing with an alpha of 1.
@@ -651,7 +628,7 @@ void CDraw2d::DrawTextInternal(const char* textString, AzFramework::FontId fontI
drawParams.m_hAlign = hAlignment;
drawParams.m_vAlign = vAlignment;
drawParams.m_monospace = false;
drawParams.m_depthTest = false;
drawParams.m_depthTest = depthTestEnabled;
drawParams.m_virtual800x600ScreenSize = false;
drawParams.m_scaleWithWindow = false;
drawParams.m_multiline = true;
@@ -809,6 +786,8 @@ void CDraw2d::DeferredQuad::Draw(AZ::RHI::Ptr<AZ::RPI::DynamicDrawContext> dynam
// Add the primitive to the dynamic draw context for drawing
dynamicDraw->SetPrimitiveType(AZ::RHI::PrimitiveTopology::TriangleList);
dynamicDraw->SetDepthState(m_renderState.m_depthState);
dynamicDraw->SetTarget0BlendState(m_renderState.m_blendState);
dynamicDraw->DrawLinear(vertices, NUM_VERTS, drawSrg);
}
@@ -868,6 +847,8 @@ void CDraw2d::DeferredLine::Draw(AZ::RHI::Ptr<AZ::RPI::DynamicDrawContext> dynam
// Add the primitive to the dynamic draw context for drawing
dynamicDraw->SetPrimitiveType(AZ::RHI::PrimitiveTopology::LineList);
dynamicDraw->SetDepthState(m_renderState.m_depthState);
dynamicDraw->SetTarget0BlendState(m_renderState.m_blendState);
dynamicDraw->DrawLinear(vertices, NUM_VERTS, drawSrg);
}
@@ -966,4 +947,3 @@ void CDraw2d::DeferredText::Draw([[maybe_unused]] AZ::RHI::Ptr<AZ::RPI::DynamicD
}
}
}
+36 -35
View File
@@ -7,7 +7,6 @@
*/
#include "LyShineDebug.h"
#include "IConsole.h"
#include "IRenderer.h"
#include <LyShine/Draw2d.h>
#include <Atom/RPI.Public/Image/ImageSystemInterface.h>
@@ -51,7 +50,7 @@ static const int g_numColors = 8;
"black"
};
static AZ::Vector3 g_colorVec3[g_numColors] =
[[maybe_unused]] static AZ::Vector3 g_colorVec3[g_numColors] =
{
AZ::Vector3(1.0f, 1.0f, 1.0f),
AZ::Vector3(1.0f, 0.0f, 0.0f),
@@ -64,34 +63,34 @@ static AZ::Vector3 g_colorVec3[g_numColors] =
};
static const int g_numSrcBlendModes = 11;
[[maybe_unused]] static int g_srcBlendModes[g_numSrcBlendModes] =
[[maybe_unused]] static AZ::RHI::BlendFactor g_srcBlendModes[g_numSrcBlendModes] =
{
GS_BLSRC_ZERO,
GS_BLSRC_ONE,
GS_BLSRC_DSTCOL,
GS_BLSRC_ONEMINUSDSTCOL,
GS_BLSRC_SRCALPHA,
GS_BLSRC_ONEMINUSSRCALPHA,
GS_BLSRC_DSTALPHA,
GS_BLSRC_ONEMINUSDSTALPHA,
GS_BLSRC_ALPHASATURATE,
GS_BLSRC_SRCALPHA_A_ZERO, // separate alpha blend state
GS_BLSRC_SRC1ALPHA, // dual source blending
AZ::RHI::BlendFactor::Zero,
AZ::RHI::BlendFactor::One,
AZ::RHI::BlendFactor::ColorDest,
AZ::RHI::BlendFactor::ColorDestInverse,
AZ::RHI::BlendFactor::AlphaSource,
AZ::RHI::BlendFactor::AlphaSourceInverse,
AZ::RHI::BlendFactor::AlphaDest,
AZ::RHI::BlendFactor::AlphaDestInverse,
AZ::RHI::BlendFactor::AlphaSourceSaturate,
AZ::RHI::BlendFactor::Factor,
AZ::RHI::BlendFactor::AlphaSource1
};
static const int g_numDstBlendModes = 10;
[[maybe_unused]] static int g_dstBlendModes[g_numDstBlendModes] =
[[maybe_unused]] static AZ::RHI::BlendFactor g_dstBlendModes[g_numDstBlendModes] =
{
GS_BLDST_ZERO,
GS_BLDST_ONE,
GS_BLDST_SRCCOL,
GS_BLDST_ONEMINUSSRCCOL,
GS_BLDST_SRCALPHA,
GS_BLDST_ONEMINUSSRCALPHA,
GS_BLDST_DSTALPHA,
GS_BLDST_ONEMINUSDSTALPHA,
GS_BLDST_ONE_A_ZERO, // separate alpha blend state
GS_BLDST_ONEMINUSSRC1ALPHA, // dual source blending
AZ::RHI::BlendFactor::Zero,
AZ::RHI::BlendFactor::One,
AZ::RHI::BlendFactor::ColorSource,
AZ::RHI::BlendFactor::ColorSourceInverse,
AZ::RHI::BlendFactor::AlphaSource,
AZ::RHI::BlendFactor::AlphaSourceInverse,
AZ::RHI::BlendFactor::AlphaDest,
AZ::RHI::BlendFactor::AlphaDestInverse,
AZ::RHI::BlendFactor::FactorInverse,
AZ::RHI::BlendFactor::AlphaSource1Inverse
};
[[maybe_unused]] static bool g_deferDrawsToEndOfFrame = false;
@@ -378,7 +377,7 @@ static void DebugDrawColoredBox(AZ::Vector2 pos, AZ::Vector2 size, AZ::Color col
{
CDraw2d* draw2d = Draw2dHelper::GetDefaultDraw2d();
IDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
CDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
imageOptions.color = color.GetAsVector3();
auto whiteTexture = AZ::RPI::ImageSystemInterface::Get()->GetSystemImage(AZ::RPI::SystemImage::White);
draw2d->DrawImageAligned(whiteTexture, pos, size, horizontalAlignment, verticalAlignment,
@@ -393,7 +392,7 @@ static void DebugDrawStringWithSizeBox(AZStd::string_view font, unsigned int eff
{
CDraw2d* draw2d = Draw2dHelper::GetDefaultDraw2d();
IDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
CDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
if (!font.empty())
{
textOptions.fontName = font;
@@ -619,7 +618,7 @@ static AZ::Vector2 DebugDrawFontColorTestBox(AZ::Vector2 pos, const char* string
float pointSize = 32.0f;
const float spacing = 6.0f;
IDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
CDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
textOptions.effectIndex = 1; // no drop shadow baked in
textOptions.color = color;
@@ -743,7 +742,7 @@ static void DebugDraw2dImageColor()
AZ::Data::Instance<AZ::RPI::Image> texture = GetMonoAlphaTestTexture();
IDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
CDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
draw2d->DrawText(
"Testing image colors, image is black and white, top row is opacity=1, bottom row is opacity = 0.5",
@@ -781,7 +780,7 @@ static void DebugDraw2dImageBlendMode()
AZ::Data::Instance<AZ::RPI::Image> texture = GetColorAlphaTestTexture();
IDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
CDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
draw2d->DrawText("Testing blend modes, src blend changes across x-axis, dst blend changes across y axis",
AZ::Vector2(20, 20), 16);
@@ -802,7 +801,7 @@ static void DebugDraw2dImageBlendMode()
AZ::Vector2 pos(xStart + xSpacing * srcIndex, yStart + ySpacing * dstIndex);
// first draw a background with varying color and alpha
IDraw2d::VertexPosColUV verts[4] =
CDraw2d::VertexPosColUV verts[4] =
{
{ // top left
AZ::Vector2(pos.GetX(), pos.GetY()),
@@ -829,7 +828,9 @@ static void DebugDraw2dImageBlendMode()
// Draw the image with this color
imageOptions.blendMode = g_srcBlendModes[srcIndex] | g_dstBlendModes[dstIndex];
CDraw2d::RenderState renderState;
renderState.m_blendState.m_blendSource = g_srcBlendModes[srcIndex];
renderState.m_blendState.m_blendDest = g_dstBlendModes[dstIndex];
draw2d->DrawImage(texture, pos, size, 1.0f, 0.0f, 0, 0, &imageOptions);
}
}
@@ -844,7 +845,7 @@ static void DebugDraw2dImageUVs()
AZ::Data::Instance<AZ::RPI::Image> texture = GetColorTestTexture();
IDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
CDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
draw2d->DrawText(
"Testing DrawImage with minMaxTexCoords. Full image, top left quadrant, middle section, full flipped",
@@ -893,7 +894,7 @@ static void DebugDraw2dImagePixelRounding()
AZ::Data::Instance<AZ::RPI::Image> texture = GetColorTestTexture();
IDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
CDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
draw2d->DrawText("Testing DrawImage pixel rounding options", AZ::Vector2(20, 20), 16);
@@ -932,7 +933,7 @@ static void DebugDraw2dLineBasic()
{
CDraw2d* draw2d = Draw2dHelper::GetDefaultDraw2d();
IDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
CDraw2d::ImageOptions imageOptions = draw2d->GetDefaultImageOptions();
draw2d->DrawText("Testing DrawLine", AZ::Vector2(20, 20), 16);
+2 -2
View File
@@ -1031,7 +1031,7 @@ void UiCanvasManager::DebugDisplayCanvasData(int setting) const
// local function to write a line of text (with a background rect) and increment Y offset
AZStd::function<void(const char*, const AZ::Vector3&)> WriteLine = [&](const char* buffer, const AZ::Vector3& color)
{
IDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
CDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
textOptions.color = color;
AZ::Vector2 textSize = draw2d->GetTextSize(buffer, fontSize, &textOptions);
AZ::Vector2 rectTopLeft = AZ::Vector2(xOffset - 2, yOffset);
@@ -1182,7 +1182,7 @@ void UiCanvasManager::DebugDisplayDrawCallData() const
// local function to write a line of text (with a background rect) and increment Y offset
AZStd::function<void(const char*, const AZ::Vector3&)> WriteLine = [&](const char* buffer, const AZ::Vector3& color)
{
IDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
CDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
textOptions.color = color;
AZ::Vector2 textSize = draw2d->GetTextSize(buffer, 16, &textOptions);
AZ::Vector2 rectTopLeft = AZ::Vector2(xOffset - 2, yOffset);
+1 -1
View File
@@ -489,7 +489,7 @@ void UiRenderer::DebugDisplayTextureData(int recordingOption)
// local function to write a line of text (with a background rect) and increment Y offset
AZStd::function<void(const char*, const AZ::Vector3&)> WriteLine = [&](const char* buffer, const AZ::Vector3& color)
{
IDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
CDraw2d::TextOptions textOptions = draw2d->GetDefaultTextOptions();
textOptions.color = color;
AZ::Vector2 textSize = draw2d->GetTextSize(buffer, 16, &textOptions);
AZ::Vector2 rectTopLeft = AZ::Vector2(xOffset - 2, yOffset);