mirror of
https://github.com/ZDoom/Raze.git
synced 2025-05-30 00:41:24 +00:00
- preparations for passing palette lookup textures through the low level texture code.
This commit is contained in:
parent
b907791558
commit
b753ea5db7
8 changed files with 104 additions and 79 deletions
|
@ -29,6 +29,13 @@
|
|||
#include "c_cvars.h"
|
||||
#include "v_video.h"
|
||||
|
||||
static IHardwareTexture* (*layercallback)(int layer, int translation);
|
||||
|
||||
void FMaterial::SetLayerCallback(IHardwareTexture* (*cb)(int layer, int translation))
|
||||
{
|
||||
layercallback = cb;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Constructor
|
||||
|
@ -42,8 +49,9 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
|||
auto imgtex = tx->GetTexture();
|
||||
mTextureLayers.Push({ imgtex, scaleflags, -1 });
|
||||
|
||||
if (tx->GetUseType() == ETextureType::SWCanvas && static_cast<FWrapperTexture*>(imgtex)->GetColorFormat() == 0)
|
||||
if ((tx->GetUseType() == ETextureType::SWCanvas && static_cast<FWrapperTexture*>(imgtex)->GetColorFormat() == 0) || (scaleflags & CTF_Indexed))
|
||||
{
|
||||
mTextureLayers[0].scaleFlags |= CTF_Indexed;
|
||||
mShaderIndex = SHADER_Paletted;
|
||||
}
|
||||
else if (tx->isHardwareCanvas())
|
||||
|
@ -57,74 +65,74 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
|||
}
|
||||
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() })
|
||||
{
|
||||
mShaderIndex = tx->isWarped(); // This picks SHADER_Warp1 or SHADER_Warp2
|
||||
mTextureLayers.Push({ texture, 0, -1 });
|
||||
}
|
||||
// Note that the material takes no ownership of the texture!
|
||||
else if (tx->Normal.get() && tx->Specular.get())
|
||||
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() })
|
||||
{
|
||||
for (auto &texture : { tx->Normal.get(), tx->Specular.get() })
|
||||
{
|
||||
mTextureLayers.Push({ texture, 0, -1 });
|
||||
}
|
||||
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;
|
||||
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 });
|
||||
}
|
||||
// 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)
|
||||
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
|
||||
{
|
||||
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.
|
||||
}
|
||||
mShaderIndex = index;
|
||||
if (texture == nullptr) continue;
|
||||
mTextureLayers.Push({ texture.get(), 0 }); // scalability should be user-definable.
|
||||
}
|
||||
mShaderIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
mScaleFlags = scaleflags;
|
||||
|
||||
mTextureLayers.ShrinkToFit();
|
||||
|
@ -149,12 +157,25 @@ FMaterial::~FMaterial()
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
IHardwareTexture *FMaterial::GetLayer(int i, int translation, MaterialLayerInfo **pLayer) const
|
||||
IHardwareTexture* FMaterial::GetLayer(int i, int translation, MaterialLayerInfo** pLayer) const
|
||||
{
|
||||
auto &layer = mTextureLayers[i];
|
||||
if (pLayer) *pLayer = &layer;
|
||||
|
||||
if (layer.layerTexture) return layer.layerTexture->GetHardwareTexture(translation, layer.scaleFlags);
|
||||
if (mShaderIndex == SHADER_Paletted && i > 0 && layercallback)
|
||||
{
|
||||
static MaterialLayerInfo deflayer = { nullptr, 0, CLAMP_XY };
|
||||
if (i == 1 || i == 2)
|
||||
{
|
||||
if (pLayer) *pLayer = &deflayer;
|
||||
//This must be done with a user supplied callback because we cannot set up the rules for palette data selection here
|
||||
return layercallback(i, translation);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto& layer = mTextureLayers[i];
|
||||
if (pLayer) *pLayer = &layer;
|
||||
if (mShaderIndex == SHADER_Paletted) translation = -1;
|
||||
if (layer.layerTexture) return layer.layerTexture->GetHardwareTexture(translation, layer.scaleFlags);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -169,6 +190,7 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool
|
|||
{
|
||||
if (gtex && gtex->isValid())
|
||||
{
|
||||
if (scaleflags & CTF_Indexed) scaleflags = CTF_Indexed;
|
||||
if (!gtex->expandSprites()) scaleflags &= ~CTF_Expand;
|
||||
|
||||
FMaterial *hwtex = gtex->Material[scaleflags];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue