Update UiCustomImageComponent to use Atom (#6628)

Signed-off-by: abrmich <abrmich@amazon.com>
This commit is contained in:
michabr
2022-01-04 18:13:44 -08:00
committed by GitHub
parent b719b1e8ee
commit 5eb6c2d24b
2 changed files with 12 additions and 30 deletions
@@ -353,7 +353,6 @@ void UiImageComponent::SetOverrideSprite(ISprite* sprite, AZ::u32 cellIndex)
////////////////////////////////////////////////////////////////////////////////////////////////////
void UiImageComponent::Render(LyShine::IRenderGraph* renderGraph)
{
// get fade value (tracked by UiRenderer) and compute the desired alpha for the image
float fade = renderGraph->GetAlphaFade();
float desiredAlpha = m_overrideAlpha * fade;
@@ -376,9 +375,8 @@ void UiImageComponent::Render(LyShine::IRenderGraph* renderGraph)
ImageType imageType = m_imageType;
#ifdef LYSHINE_ATOM_TODO // support default white texture
// if there is no texture we will just use a white texture and want to stretch it
const bool spriteOrTextureIsNull = sprite == nullptr || sprite->GetTexture() == nullptr;
const bool spriteOrTextureIsNull = sprite == nullptr || sprite->GetImage() == nullptr;
// Zero texture size may occur even if the UiImageComponent has a valid non-zero-sized texture,
// because a canvas can be requested to Render() before the texture asset is done loading.
@@ -399,12 +397,6 @@ void UiImageComponent::Render(LyShine::IRenderGraph* renderGraph)
{
imageType = ImageType::Stretched;
}
#else
if (sprite == nullptr)
{
imageType = ImageType::Stretched;
}
#endif
switch (imageType)
{
@@ -72,36 +72,25 @@ namespace LyShineExamples
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void UiCustomImageComponent::Render([[maybe_unused]] LyShine::IRenderGraph* renderGraph)
void UiCustomImageComponent::Render(LyShine::IRenderGraph* renderGraph)
{
#ifdef LYSHINE_ATOM_TODO // [GHI #3568] Convert draws to use Atom
// get fade value (tracked by UiRenderer) and compute the desired alpha for the image
float fade = renderGraph->GetAlphaFade();
float desiredAlpha = m_overrideAlpha * fade;
uint8 desiredPackedAlpha = static_cast<uint8>(desiredAlpha * 255.0f);
// if desired alpha is zero then no need to do any more
if (desiredPackedAlpha == 0)
{
return;
}
ISprite* sprite = (m_overrideSprite) ? m_overrideSprite : m_sprite;
ITexture* texture = (sprite) ? sprite->GetTexture() : nullptr;
if (!texture)
{
// if there is no texture we will just use a white texture
// TODO: Get a default atom texture here when possible
//texture = ???->EF_GetTextureByID(???->GetWhiteTextureId());
}
if (m_isRenderCacheDirty)
{
RenderToCache(renderGraph);
m_isRenderCacheDirty = false;
}
// if desired alpha is zero then no need to do any more
if (desiredPackedAlpha == 0)
{
return;
}
// Render cache is now valid - render using the cache
// If the fade value has changed we need to update the alpha values in the vertex colors but we do
@@ -109,7 +98,7 @@ namespace LyShineExamples
if (m_cachedPrimitive.m_vertices[0].color.a != desiredPackedAlpha)
{
// go through all the cached vertices and update the alpha values
UCol desiredPackedColor = m_cachedPrimitive.m_vertices[0].color;
LyShine::UCol desiredPackedColor = m_cachedPrimitive.m_vertices[0].color;
desiredPackedColor.a = desiredPackedAlpha;
for (int i = 0; i < m_cachedPrimitive.m_numVertices; ++i)
{
@@ -117,11 +106,12 @@ namespace LyShineExamples
}
}
ISprite* sprite = (m_overrideSprite) ? m_overrideSprite : m_sprite;
AZ::Data::Instance<AZ::RPI::Image> image = sprite->GetImage();
bool isTextureSRGB = false;
bool isTexturePremultipliedAlpha = false; // we are not rendering from a render target with alpha in it
LyShine::BlendMode blendMode = LyShine::BlendMode::Normal;
renderGraph->AddPrimitive(&m_cachedPrimitive, texture, m_clamp, isTextureSRGB, isTexturePremultipliedAlpha, blendMode);
#endif
renderGraph->AddPrimitive(&m_cachedPrimitive, image, m_clamp, isTextureSRGB, isTexturePremultipliedAlpha, blendMode);
}
////////////////////////////////////////////////////////////////////////////////////////////////////