Skip to content

Commit 7df60d6

Browse files
TextureLoader: fixed issue with grayscale images
1 parent 849aa39 commit 7df60d6

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

TextureLoader/src/TextureLoaderImpl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,14 @@ void TextureLoaderImpl::LoadFromImage(Image* pImage, const TextureLoadInfo& TexL
217217

218218
if (m_TexDesc.Format == TEX_FORMAT_UNKNOWN)
219219
{
220+
const COMPONENT_TYPE CompType = ValueTypeToComponentType(ImgDesc.ComponentType, /*IsNormalized = */ true, TexLoadInfo.IsSRGB);
221+
220222
Uint32 NumComponents = ImgDesc.NumComponents;
221-
if (NumComponents == 3)
223+
if (NumComponents == 3 || CompType == COMPONENT_TYPE_UNORM_SRGB)
222224
{
223225
// Note that there is RGB32_FLOAT format, but it can't be filtered, so always extend RGB to RGBA.
224226
NumComponents = 4;
225227
}
226-
const COMPONENT_TYPE CompType = ValueTypeToComponentType(ImgDesc.ComponentType, /*IsNormalized = */ true, TexLoadInfo.IsSRGB);
227228
DEV_CHECK_ERR(CompType != COMPONENT_TYPE_UNDEFINED, "Failed to deduce component type from image component type ", GetValueTypeString(ImgDesc.ComponentType), " and sRGB flag ", TexLoadInfo.IsSRGB);
228229

229230
m_TexDesc.Format = TextureComponentAttribsToTextureFormat(CompType, CompSize, NumComponents);
@@ -368,12 +369,10 @@ void TextureLoaderImpl::CompressSubresources(Uint32 NumComponents, Uint32 NumSrc
368369
break;
369370

370371
case 4:
371-
if (NumSrcComponents == 3)
372-
CompressedFormat = TexLoadInfo.IsSRGB ? TEX_FORMAT_BC1_UNORM_SRGB : TEX_FORMAT_BC1_UNORM;
373-
else if (NumSrcComponents == 4)
372+
if (NumSrcComponents == 4)
374373
CompressedFormat = TexLoadInfo.IsSRGB ? TEX_FORMAT_BC3_UNORM_SRGB : TEX_FORMAT_BC3_UNORM;
375374
else
376-
UNEXPECTED("Unexpected number of source components ", NumSrcComponents);
375+
CompressedFormat = TexLoadInfo.IsSRGB ? TEX_FORMAT_BC1_UNORM_SRGB : TEX_FORMAT_BC1_UNORM;
377376
break;
378377

379378
default:

0 commit comments

Comments
 (0)