Fix some textures being loaded without mipmaps

Some calls to `LoadTextureRaw` where passing the image format also in place of the texture load flags. Since the image format would be RGBA most of the time, this was interpreted as the flag `IGraphics::TEXLOAD_NOMIPMAPS` causing various textures (all sprites textures, assets when shown in menus, menu images, menu theme icons) to be loaded without mipmaps.

This is fixed by passing `0` as the texture load flags and by replacing uses of `LoadPNG` and `LoadTextureRaw` with `LoadTexture`.
This commit is contained in:
Robert Müller 2023-11-03 23:45:19 +01:00
parent e12f59b445
commit 367c7ba4e7
4 changed files with 26 additions and 66 deletions

View file

@ -368,7 +368,7 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadSpriteTextureImpl(CImageInfo &
const size_t PixelSize = FromImageInfo.PixelSize();
m_vSpriteHelper.resize(w * h * PixelSize);
CopyTextureFromTextureBufferSub(m_vSpriteHelper.data(), w, h, (uint8_t *)FromImageInfo.m_pData, FromImageInfo.m_Width, FromImageInfo.m_Height, PixelSize, x, y, w, h);
return LoadTextureRaw(w, h, FromImageInfo.m_Format, m_vSpriteHelper.data(), FromImageInfo.m_Format, 0);
return LoadTextureRaw(w, h, FromImageInfo.m_Format, m_vSpriteHelper.data(), 0);
}
IGraphics::CTextureHandle CGraphics_Threaded::LoadSpriteTexture(CImageInfo &FromImageInfo, CDataSprite *pSprite)

View file

@ -95,18 +95,13 @@ void CMenuBackground::LoadThemeIcon(CTheme &Theme)
{
char aIconPath[IO_MAX_PATH_LENGTH];
str_format(aIconPath, sizeof(aIconPath), "themes/%s.png", Theme.m_Name.empty() ? "none" : Theme.m_Name.c_str());
Theme.m_IconTexture = Graphics()->LoadTexture(aIconPath, IStorage::TYPE_ALL);
char aBuf[32 + IO_MAX_PATH_LENGTH];
CImageInfo Info;
if(!Graphics()->LoadPNG(&Info, aIconPath, IStorage::TYPE_ALL))
{
if(Theme.m_IconTexture.IsNullTexture())
str_format(aBuf, sizeof(aBuf), "failed to load theme icon '%s'", aIconPath);
}
else
{
str_format(aBuf, sizeof(aBuf), "loaded theme icon '%s'", aIconPath);
Theme.m_IconTexture = Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0);
Graphics()->FreePNG(&Info);
}
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "menuthemes", aBuf);
}

View file

@ -2195,7 +2195,7 @@ int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser
return 0;
}
MenuImage.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0);
MenuImage.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, 0);
// create gray scale version
unsigned char *pData = static_cast<unsigned char *>(Info.m_pData);
@ -2207,7 +2207,7 @@ int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser
pData[i * Step + 1] = v;
pData[i * Step + 2] = v;
}
MenuImage.m_GreyTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0);
MenuImage.m_GreyTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, 0);
pSelf->Graphics()->FreePNG(&Info);
str_truncate(MenuImage.m_aName, sizeof(MenuImage.m_aName), pName, str_length(pName) - str_length(pExtension));

View file

@ -40,50 +40,30 @@ void CMenus::LoadEntities(SCustomEntities *pEntitiesItem, void *pUser)
auto *pRealUser = (SMenuAssetScanUser *)pUser;
auto *pThis = (CMenus *)pRealUser->m_pUser;
char aBuff[IO_MAX_PATH_LENGTH];
char aPath[IO_MAX_PATH_LENGTH];
if(str_comp(pEntitiesItem->m_aName, "default") == 0)
{
for(int i = 0; i < MAP_IMAGE_MOD_TYPE_COUNT; ++i)
{
str_format(aBuff, sizeof(aBuff), "editor/entities_clear/%s.png", gs_apModEntitiesNames[i]);
CImageInfo ImgInfo;
if(pThis->Graphics()->LoadPNG(&ImgInfo, aBuff, IStorage::TYPE_ALL))
{
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pThis->Graphics()->FreePNG(&ImgInfo);
if(!pEntitiesItem->m_RenderTexture.IsValid())
pEntitiesItem->m_RenderTexture = pEntitiesItem->m_aImages[i].m_Texture;
}
str_format(aPath, sizeof(aPath), "editor/entities_clear/%s.png", gs_apModEntitiesNames[i]);
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTexture(aPath, IStorage::TYPE_ALL);
if(!pEntitiesItem->m_RenderTexture.IsValid() || pEntitiesItem->m_RenderTexture.IsNullTexture())
pEntitiesItem->m_RenderTexture = pEntitiesItem->m_aImages[i].m_Texture;
}
}
else
{
for(int i = 0; i < MAP_IMAGE_MOD_TYPE_COUNT; ++i)
{
str_format(aBuff, sizeof(aBuff), "assets/entities/%s/%s.png", pEntitiesItem->m_aName, gs_apModEntitiesNames[i]);
CImageInfo ImgInfo;
if(pThis->Graphics()->LoadPNG(&ImgInfo, aBuff, IStorage::TYPE_ALL))
str_format(aPath, sizeof(aPath), "assets/entities/%s/%s.png", pEntitiesItem->m_aName, gs_apModEntitiesNames[i]);
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTexture(aPath, IStorage::TYPE_ALL);
if(pEntitiesItem->m_aImages[i].m_Texture.IsNullTexture())
{
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pThis->Graphics()->FreePNG(&ImgInfo);
if(!pEntitiesItem->m_RenderTexture.IsValid())
pEntitiesItem->m_RenderTexture = pEntitiesItem->m_aImages[i].m_Texture;
}
else
{
str_format(aBuff, sizeof(aBuff), "assets/entities/%s.png", pEntitiesItem->m_aName);
if(pThis->Graphics()->LoadPNG(&ImgInfo, aBuff, IStorage::TYPE_ALL))
{
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pThis->Graphics()->FreePNG(&ImgInfo);
if(!pEntitiesItem->m_RenderTexture.IsValid())
pEntitiesItem->m_RenderTexture = pEntitiesItem->m_aImages[i].m_Texture;
}
str_format(aPath, sizeof(aPath), "assets/entities/%s.png", pEntitiesItem->m_aName);
pEntitiesItem->m_aImages[i].m_Texture = pThis->Graphics()->LoadTexture(aPath, IStorage::TYPE_ALL);
}
if(!pEntitiesItem->m_RenderTexture.IsValid() || pEntitiesItem->m_RenderTexture.IsNullTexture())
pEntitiesItem->m_RenderTexture = pEntitiesItem->m_aImages[i].m_Texture;
}
}
}
@ -131,35 +111,20 @@ int CMenus::EntitiesScan(const char *pName, int IsDir, int DirType, void *pUser)
template<typename TName>
static void LoadAsset(TName *pAssetItem, const char *pAssetName, IGraphics *pGraphics)
{
char aBuff[IO_MAX_PATH_LENGTH];
char aPath[IO_MAX_PATH_LENGTH];
if(str_comp(pAssetItem->m_aName, "default") == 0)
{
str_format(aBuff, sizeof(aBuff), "%s.png", pAssetName);
CImageInfo ImgInfo;
if(pGraphics->LoadPNG(&ImgInfo, aBuff, IStorage::TYPE_ALL))
{
pAssetItem->m_RenderTexture = pGraphics->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pGraphics->FreePNG(&ImgInfo);
}
str_format(aPath, sizeof(aPath), "%s.png", pAssetName);
pAssetItem->m_RenderTexture = pGraphics->LoadTexture(aPath, IStorage::TYPE_ALL);
}
else
{
str_format(aBuff, sizeof(aBuff), "assets/%s/%s.png", pAssetName, pAssetItem->m_aName);
CImageInfo ImgInfo;
if(pGraphics->LoadPNG(&ImgInfo, aBuff, IStorage::TYPE_ALL))
str_format(aPath, sizeof(aPath), "assets/%s/%s.png", pAssetName, pAssetItem->m_aName);
pAssetItem->m_RenderTexture = pGraphics->LoadTexture(aPath, IStorage::TYPE_ALL);
if(pAssetItem->m_RenderTexture.IsNullTexture())
{
pAssetItem->m_RenderTexture = pGraphics->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pGraphics->FreePNG(&ImgInfo);
}
else
{
str_format(aBuff, sizeof(aBuff), "assets/%s/%s/%s.png", pAssetName, pAssetItem->m_aName, pAssetName);
if(pGraphics->LoadPNG(&ImgInfo, aBuff, IStorage::TYPE_ALL))
{
pAssetItem->m_RenderTexture = pGraphics->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, ImgInfo.m_Format, 0);
pGraphics->FreePNG(&ImgInfo);
}
str_format(aPath, sizeof(aPath), "assets/%s/%s/%s.png", pAssetName, pAssetItem->m_aName, pAssetName);
pAssetItem->m_RenderTexture = pGraphics->LoadTexture(aPath, IStorage::TYPE_ALL);
}
}
}