- texture manager fixes from GZDoom

* missing null check in FPngTexture.
* ignore identity translations when creating textures.
This commit is contained in:
Christoph Oelckers 2020-09-27 10:39:10 +02:00
parent f8ae35f8a5
commit 0314cdec55
5 changed files with 68 additions and 66 deletions

View file

@ -106,7 +106,7 @@ void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
uint8_t *source = (uint8_t *)lump.GetMem();
anim_t anim;
if (ANIM_LoadAnim(&anim, source, lump.GetSize()) >= 0)
if (ANIM_LoadAnim(&anim, source, (int)lump.GetSize()) >= 0)
{
int numframes = ANIM_NumFrames(&anim);
if (numframes >= 1)

View file

@ -360,7 +360,8 @@ void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap)
uint8_t r = lump->ReadUInt8();
uint8_t g = lump->ReadUInt8();
uint8_t b = lump->ReadUInt8();
alpharemap[i] = PaletteMap[i] == 0 ? 0 : Luminance(r, g, b);
int palmap = PaletteMap ? PaletteMap[i] : i;
alpharemap[i] = palmap == 0 ? 0 : Luminance(r, g, b);
}
lump->Seek(p, FileReader::SeekSet);
}

View file

@ -72,7 +72,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
// Note that the material takes no ownership of the texture!
else if (tx->Normal.get() && tx->Specular.get())
{
for (auto& texture : { tx->Normal.get(), tx->Specular.get() })
for (auto &texture : { tx->Normal.get(), tx->Specular.get() })
{
mTextureLayers.Push({ texture, 0, -1 });
}
@ -80,7 +80,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
}
else if (tx->Normal.get() && tx->Metallic.get() && tx->Roughness.get() && tx->AmbientOcclusion.get())
{
for (auto& texture : { tx->Normal.get(), tx->Metallic.get(), tx->Roughness.get(), tx->AmbientOcclusion.get() })
for (auto &texture : { tx->Normal.get(), tx->Metallic.get(), tx->Roughness.get(), tx->AmbientOcclusion.get() })
{
mTextureLayers.Push({ texture, 0, -1 });
}
@ -121,10 +121,10 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
auto index = tx->GetShaderIndex();
if (index >= FIRST_USER_SHADER)
{
const UserShaderDesc& usershader = usershaders[index - FIRST_USER_SHADER];
const UserShaderDesc &usershader = usershaders[index - FIRST_USER_SHADER];
if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material
{
for (auto& texture : tx->CustomShaderTextures)
for (auto &texture : tx->CustomShaderTextures)
{
if (texture == nullptr) continue;
mTextureLayers.Push({ texture.get(), 0 }); // scalability should be user-definable.

View file

@ -12,9 +12,9 @@ enum ECreateTexBufferFlags
CTF_Expand = 1, // create buffer with a one-pixel wide border
CTF_Upscale = 2, // Upscale the texture
CTF_CreateMask = 3, // Flags that are relevant for hardware texture creation.
CTF_Indexed = 4, // Tell the backend to create an indexed texture.
CTF_ProcessData = 8, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
CTF_CheckOnly = 16, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures.
CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures.
CTF_Indexed = 16 // Tell the backend to create an indexed texture.
};
class FHardwareTextureContainer

View file

@ -357,6 +357,7 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags)
memset(buffer, 0, W * (H + 1) * 4);
auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation);
if (remap && remap->Inactive) remap = nullptr;
if (remap) translation = remap->Index;
FBitmap bmp(buffer, W * 4, W, H);