- 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(); uint8_t *source = (uint8_t *)lump.GetMem();
anim_t anim; 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); int numframes = ANIM_NumFrames(&anim);
if (numframes >= 1) if (numframes >= 1)

View file

@ -360,7 +360,8 @@ void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap)
uint8_t r = lump->ReadUInt8(); uint8_t r = lump->ReadUInt8();
uint8_t g = lump->ReadUInt8(); uint8_t g = lump->ReadUInt8();
uint8_t b = 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); lump->Seek(p, FileReader::SeekSet);
} }

View file

@ -65,73 +65,73 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
} }
else else
{ {
if (tx->isWarped()) if (tx->isWarped())
{
mShaderIndex = tx->isWarped(); // This picks SHADER_Warp1 or SHADER_Warp2
}
// 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() })
{ {
mTextureLayers.Push({ texture, 0, -1 }); mShaderIndex = tx->isWarped(); // This picks SHADER_Warp1 or SHADER_Warp2
} }
mShaderIndex = SHADER_Specular; // Note that the material takes no ownership of the texture!
} else if (tx->Normal.get() && tx->Specular.get())
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() })
{ {
mTextureLayers.Push({ texture, 0, -1 }); for (auto &texture : { tx->Normal.get(), tx->Specular.get() })
}
mShaderIndex = SHADER_PBR;
}
// Note that these layers must present a valid texture even if not used, because empty TMUs in the shader are an undefined condition.
tx->CreateDefaultBrightmap();
auto placeholder = TexMan.GameByIndex(1);
if (tx->Brightmap.get())
{
mTextureLayers.Push({ tx->Brightmap.get(), scaleflags, -1 });
mLayerFlags |= TEXF_Brightmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}
if (tx->Detailmap.get())
{
mTextureLayers.Push({ tx->Detailmap.get(), 0, CLAMP_NONE });
mLayerFlags |= TEXF_Detailmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}
if (tx->Glowmap.get())
{
mTextureLayers.Push({ tx->Glowmap.get(), scaleflags, -1 });
mLayerFlags |= TEXF_Glowmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}
auto index = tx->GetShaderIndex();
if (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)
{ {
if (texture == nullptr) continue; mTextureLayers.Push({ texture, 0, -1 });
mTextureLayers.Push({ texture.get(), 0 }); // scalability should be user-definable. }
mShaderIndex = SHADER_Specular;
}
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() })
{
mTextureLayers.Push({ texture, 0, -1 });
}
mShaderIndex = SHADER_PBR;
}
// Note that these layers must present a valid texture even if not used, because empty TMUs in the shader are an undefined condition.
tx->CreateDefaultBrightmap();
auto placeholder = TexMan.GameByIndex(1);
if (tx->Brightmap.get())
{
mTextureLayers.Push({ tx->Brightmap.get(), scaleflags, -1 });
mLayerFlags |= TEXF_Brightmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}
if (tx->Detailmap.get())
{
mTextureLayers.Push({ tx->Detailmap.get(), 0, CLAMP_NONE });
mLayerFlags |= TEXF_Detailmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}
if (tx->Glowmap.get())
{
mTextureLayers.Push({ tx->Glowmap.get(), scaleflags, -1 });
mLayerFlags |= TEXF_Glowmap;
}
else
{
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
}
auto index = tx->GetShaderIndex();
if (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)
{
if (texture == nullptr) continue;
mTextureLayers.Push({ texture.get(), 0 }); // scalability should be user-definable.
}
mShaderIndex = index;
} }
mShaderIndex = index;
} }
}
} }
mScaleFlags = scaleflags; mScaleFlags = scaleflags;

View file

@ -12,9 +12,9 @@ enum ECreateTexBufferFlags
CTF_Expand = 1, // create buffer with a one-pixel wide border CTF_Expand = 1, // create buffer with a one-pixel wide border
CTF_Upscale = 2, // Upscale the texture CTF_Upscale = 2, // Upscale the texture
CTF_CreateMask = 3, // Flags that are relevant for hardware texture creation. CTF_CreateMask = 3, // Flags that are relevant for hardware texture creation.
CTF_Indexed = 4, // Tell the backend to create an indexed texture. CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
CTF_ProcessData = 8, // 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_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_Indexed = 16 // Tell the backend to create an indexed texture.
}; };
class FHardwareTextureContainer class FHardwareTextureContainer

View file

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