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;
|
||||
|
||||
ISoftwareTexture* SoftwareTexture = nullptr;
|
||||
FMaterial* Material[4] = { };
|
||||
FMaterial* Material[5] = { };
|
||||
|
||||
// Material properties
|
||||
FVector2 detailScale = { 1.f, 1.f };
|
||||
|
|
|
@ -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())
|
||||
|
@ -64,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 });
|
||||
}
|
||||
|
@ -72,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 });
|
||||
}
|
||||
|
@ -113,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.
|
||||
|
@ -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)
|
||||
{
|
||||
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];
|
||||
|
|
|
@ -30,6 +30,8 @@ class FMaterial
|
|||
int mScaleFlags;
|
||||
|
||||
public:
|
||||
static void SetLayerCallback(IHardwareTexture* (*layercallback)(int layer, int translation));
|
||||
|
||||
FGameTexture *sourcetex; // the owning texture.
|
||||
|
||||
FMaterial(FGameTexture *tex, int scaleflags);
|
||||
|
|
|
@ -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_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.
|
||||
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.
|
||||
};
|
||||
|
||||
class FHardwareTextureContainer
|
||||
|
|
|
@ -527,17 +527,15 @@ outl:
|
|||
|
||||
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)
|
||||
{
|
||||
hwtex = screen->CreateHardwareTexture(4);
|
||||
hwtex = screen->CreateHardwareTexture(indexed? 1 : 4);
|
||||
SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex);
|
||||
}
|
||||
return hwtex;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -393,7 +393,6 @@ static void G_SetupCamTile(int spriteNum, int tileNum, int smoothRatio)
|
|||
|
||||
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)
|
||||
{
|
||||
yax_preparedrawrooms();
|
||||
|
|
|
@ -78,7 +78,8 @@ bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sa
|
|||
|
||||
SetBasepalTint(texpick.basepalTint);
|
||||
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.mTranslation = texpick.translation;
|
||||
mat.mOverrideShader = 0;
|
||||
|
|
|
@ -1578,6 +1578,9 @@ OptionMenu VideoModeMenu //protected
|
|||
{
|
||||
Title "$VIDMNU_TITLE"
|
||||
|
||||
// does not work yet.
|
||||
//Option "$VIDMNU_PREFERBACKEND", "vid_preferbackend", "PreferBackend"
|
||||
//StaticText " "
|
||||
Option "$VIDMNU_FULLSCREEN", "vid_fullscreen", "YesNo"
|
||||
|
||||
IfOption(Mac)
|
||||
|
|
Loading…
Reference in a new issue