mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-27 20:20:40 +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
|
@ -91,7 +91,7 @@ class FGameTexture
|
||||||
SpritePositioningInfo* spi = nullptr;
|
SpritePositioningInfo* spi = nullptr;
|
||||||
|
|
||||||
ISoftwareTexture* SoftwareTexture = nullptr;
|
ISoftwareTexture* SoftwareTexture = nullptr;
|
||||||
FMaterial* Material[4] = { };
|
FMaterial* Material[5] = { };
|
||||||
|
|
||||||
// Material properties
|
// Material properties
|
||||||
FVector2 detailScale = { 1.f, 1.f };
|
FVector2 detailScale = { 1.f, 1.f };
|
||||||
|
|
|
@ -29,6 +29,13 @@
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
#include "v_video.h"
|
#include "v_video.h"
|
||||||
|
|
||||||
|
static IHardwareTexture* (*layercallback)(int layer, int translation);
|
||||||
|
|
||||||
|
void FMaterial::SetLayerCallback(IHardwareTexture* (*cb)(int layer, int translation))
|
||||||
|
{
|
||||||
|
layercallback = cb;
|
||||||
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//
|
//
|
||||||
// Constructor
|
// Constructor
|
||||||
|
@ -42,8 +49,9 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
||||||
auto imgtex = tx->GetTexture();
|
auto imgtex = tx->GetTexture();
|
||||||
mTextureLayers.Push({ imgtex, scaleflags, -1 });
|
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;
|
mShaderIndex = SHADER_Paletted;
|
||||||
}
|
}
|
||||||
else if (tx->isHardwareCanvas())
|
else if (tx->isHardwareCanvas())
|
||||||
|
@ -57,74 +65,74 @@ 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() })
|
||||||
{
|
{
|
||||||
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!
|
mShaderIndex = SHADER_Specular;
|
||||||
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() })
|
||||||
{
|
{
|
||||||
for (auto &texture : { tx->Normal.get(), tx->Specular.get() })
|
mTextureLayers.Push({ texture, 0, -1 });
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
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.
|
// 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();
|
tx->CreateDefaultBrightmap();
|
||||||
auto placeholder = TexMan.GameByIndex(1);
|
auto placeholder = TexMan.GameByIndex(1);
|
||||||
if (tx->Brightmap.get())
|
if (tx->Brightmap.get())
|
||||||
{
|
{
|
||||||
mTextureLayers.Push({ tx->Brightmap.get(), scaleflags, -1 });
|
mTextureLayers.Push({ tx->Brightmap.get(), scaleflags, -1 });
|
||||||
mLayerFlags |= TEXF_Brightmap;
|
mLayerFlags |= TEXF_Brightmap;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
|
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
|
||||||
}
|
}
|
||||||
if (tx->Detailmap.get())
|
if (tx->Detailmap.get())
|
||||||
{
|
{
|
||||||
mTextureLayers.Push({ tx->Detailmap.get(), 0, CLAMP_NONE });
|
mTextureLayers.Push({ tx->Detailmap.get(), 0, CLAMP_NONE });
|
||||||
mLayerFlags |= TEXF_Detailmap;
|
mLayerFlags |= TEXF_Detailmap;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
|
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
|
||||||
}
|
}
|
||||||
if (tx->Glowmap.get())
|
if (tx->Glowmap.get())
|
||||||
{
|
{
|
||||||
mTextureLayers.Push({ tx->Glowmap.get(), scaleflags, -1 });
|
mTextureLayers.Push({ tx->Glowmap.get(), scaleflags, -1 });
|
||||||
mLayerFlags |= TEXF_Glowmap;
|
mLayerFlags |= TEXF_Glowmap;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
|
mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
auto index = tx->GetShaderIndex();
|
auto index = tx->GetShaderIndex();
|
||||||
if (index >= FIRST_USER_SHADER)
|
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];
|
for (auto& texture : tx->CustomShaderTextures)
|
||||||
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.
|
||||||
if (texture == nullptr) continue;
|
|
||||||
mTextureLayers.Push({ texture.get(), 0 }); // scalability should be user-definable.
|
|
||||||
}
|
|
||||||
mShaderIndex = index;
|
|
||||||
}
|
}
|
||||||
|
mShaderIndex = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mScaleFlags = scaleflags;
|
mScaleFlags = scaleflags;
|
||||||
|
|
||||||
mTextureLayers.ShrinkToFit();
|
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 (mShaderIndex == SHADER_Paletted && i > 0 && layercallback)
|
||||||
if (pLayer) *pLayer = &layer;
|
{
|
||||||
|
static MaterialLayerInfo deflayer = { nullptr, 0, CLAMP_XY };
|
||||||
if (layer.layerTexture) return layer.layerTexture->GetHardwareTexture(translation, layer.scaleFlags);
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +190,7 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool
|
||||||
{
|
{
|
||||||
if (gtex && gtex->isValid())
|
if (gtex && gtex->isValid())
|
||||||
{
|
{
|
||||||
|
if (scaleflags & CTF_Indexed) scaleflags = CTF_Indexed;
|
||||||
if (!gtex->expandSprites()) scaleflags &= ~CTF_Expand;
|
if (!gtex->expandSprites()) scaleflags &= ~CTF_Expand;
|
||||||
|
|
||||||
FMaterial *hwtex = gtex->Material[scaleflags];
|
FMaterial *hwtex = gtex->Material[scaleflags];
|
||||||
|
|
|
@ -30,6 +30,8 @@ class FMaterial
|
||||||
int mScaleFlags;
|
int mScaleFlags;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static void SetLayerCallback(IHardwareTexture* (*layercallback)(int layer, int translation));
|
||||||
|
|
||||||
FGameTexture *sourcetex; // the owning texture.
|
FGameTexture *sourcetex; // the owning texture.
|
||||||
|
|
||||||
FMaterial(FGameTexture *tex, int scaleflags);
|
FMaterial(FGameTexture *tex, int scaleflags);
|
||||||
|
|
|
@ -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_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
|
CTF_Indexed = 4, // Tell the backend to create an indexed 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_ProcessData = 8, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture.
|
||||||
CTF_Indexed = 16 // Tell the backend to create an indexed 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.
|
||||||
};
|
};
|
||||||
|
|
||||||
class FHardwareTextureContainer
|
class FHardwareTextureContainer
|
||||||
|
|
|
@ -527,17 +527,15 @@ outl:
|
||||||
|
|
||||||
IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags)
|
IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags)
|
||||||
{
|
{
|
||||||
//if (UseType != ETextureType::Null)
|
int indexed = scaleflags & CTF_Indexed;
|
||||||
|
if (indexed) translation = -1;
|
||||||
|
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags);
|
||||||
|
if (hwtex == nullptr)
|
||||||
{
|
{
|
||||||
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags);
|
hwtex = screen->CreateHardwareTexture(indexed? 1 : 4);
|
||||||
if (hwtex == nullptr)
|
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
|
||||||
{
|
|
||||||
hwtex = screen->CreateHardwareTexture(4);
|
|
||||||
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
|
|
||||||
}
|
}
|
||||||
return hwtex;
|
return hwtex;
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -393,7 +393,6 @@ static void G_SetupCamTile(int spriteNum, int tileNum, int smoothRatio)
|
||||||
|
|
||||||
screen->RenderTextureView(canvas, [=](IntRect& rect)
|
screen->RenderTextureView(canvas, [=](IntRect& rect)
|
||||||
{
|
{
|
||||||
// Beware! Apparently this is allowed to render to the camera itself. Breakage is basically guarenteed...
|
|
||||||
if (VM_OnEventWithReturn(EVENT_DISPLAYROOMSCAMERATILE, spriteNum, screenpeek, 0) != 1)
|
if (VM_OnEventWithReturn(EVENT_DISPLAYROOMSCAMERATILE, spriteNum, screenpeek, 0) != 1)
|
||||||
{
|
{
|
||||||
yax_preparedrawrooms();
|
yax_preparedrawrooms();
|
||||||
|
|
|
@ -78,7 +78,8 @@ bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sa
|
||||||
|
|
||||||
SetBasepalTint(texpick.basepalTint);
|
SetBasepalTint(texpick.basepalTint);
|
||||||
auto &mat = renderState.mMaterial;
|
auto &mat = renderState.mMaterial;
|
||||||
mat.mMaterial = FMaterial::ValidateTexture(tex, 0); // todo allow scaling
|
int flags = hw_useindexedcolortextures ? CTF_Indexed : 0;
|
||||||
|
mat.mMaterial = FMaterial::ValidateTexture(tex, flags); // todo allow scaling
|
||||||
mat.mClampMode = sampler;
|
mat.mClampMode = sampler;
|
||||||
mat.mTranslation = texpick.translation;
|
mat.mTranslation = texpick.translation;
|
||||||
mat.mOverrideShader = 0;
|
mat.mOverrideShader = 0;
|
||||||
|
|
|
@ -1577,7 +1577,10 @@ OptionValue GPUSwitch
|
||||||
OptionMenu VideoModeMenu //protected
|
OptionMenu VideoModeMenu //protected
|
||||||
{
|
{
|
||||||
Title "$VIDMNU_TITLE"
|
Title "$VIDMNU_TITLE"
|
||||||
|
|
||||||
|
// does not work yet.
|
||||||
|
//Option "$VIDMNU_PREFERBACKEND", "vid_preferbackend", "PreferBackend"
|
||||||
|
//StaticText " "
|
||||||
Option "$VIDMNU_FULLSCREEN", "vid_fullscreen", "YesNo"
|
Option "$VIDMNU_FULLSCREEN", "vid_fullscreen", "YesNo"
|
||||||
|
|
||||||
IfOption(Mac)
|
IfOption(Mac)
|
||||||
|
|
Loading…
Reference in a new issue