- changed render interface to resolve textures to materials in the backend.

This is needed to have a unified spot where to resolve textures for both 2D and 3D.
This commit is contained in:
Christoph Oelckers 2020-11-10 09:08:48 +01:00
parent 601680d08e
commit 40358febc1
6 changed files with 45 additions and 32 deletions

View file

@ -4,6 +4,9 @@
#include "intrect.h"
struct event_t;
class FRenderState;
class FGameTexture;
enum EUpscaleFlags;
struct SystemCallbacks
{
@ -27,6 +30,7 @@ struct SystemCallbacks
void (*MenuClosed)();
bool (*CheckMenudefOption)(const char* opt);
void (*ConsoleToggled)(int state);
bool (*PreBindTexture)(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& clampmode, int& translation, int& overrideshader);
};
extern SystemCallbacks sysCallbacks;

View file

@ -5,6 +5,7 @@
#include "hw_material.h"
#include "texmanip.h"
#include "version.h"
#include "i_interface.h"
struct FColormap;
class IVertexBuffer;
@ -569,6 +570,7 @@ public:
mBias.mChanged = true;
}
private:
void SetMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader)
{
mMaterial.mMaterial = mat;
@ -581,9 +583,13 @@ public:
mStreamData.uDetailParms = { scale.X, scale.Y, 2, 0 };
}
public:
void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, int translation, int overrideshader)
{
if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale;
if (sysCallbacks.PreBindTexture && !sysCallbacks.PreBindTexture(this, tex, upscalemask, clampmode, translation, overrideshader))
{
if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale;
}
SetMaterial(FMaterial::ValidateTexture(tex, scaleflags), clampmode, translation, overrideshader);
}

View file

@ -78,8 +78,9 @@ bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sa
SetBasepalTint(texpick.basepalTint);
auto &mat = renderState.mMaterial;
int flags = (TextureType == TT_INDEXED) ? CTF_Indexed : 0;
mat.mMaterial = FMaterial::ValidateTexture(texpick.texture, flags); // todo allow scaling
mat.mTexture = texpick.texture;
mat.uFlags = UF_None;
mat.mScaleFlags = (TextureType == TT_INDEXED) ? CTF_Indexed : 0;
mat.mClampMode = sampler;
mat.mTranslation = texpick.translation;
mat.mOverrideShader = -1;

View file

@ -58,16 +58,6 @@ static int BufferLock = 0;
TArray<VSMatrix> matrixArray;
void Draw2D(F2DDrawer* drawer, FRenderState& state);
FileReader GetResource(const char* fn)
{
auto fr = fileSystem.OpenFileReader(fn);
if (!fr.isOpen())
{
I_Error("Fatal: '%s' not found", fn);
}
return fr;
}
GLInstance GLInterface;
GLInstance::GLInstance()
@ -77,10 +67,6 @@ GLInstance::GLInstance()
matrixArray.Push(mat);
}
//void ImGui_Init_Backend();
//ImGuiContext* im_ctx;
TArray<uint8_t> ttf;
IHardwareTexture *setpalettelayer(int layer, int translation)
{
if (layer == 1)
@ -171,7 +157,7 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState)
else
{
state.EnableTexture(gl_texture);
state.SetMaterial(mMaterial.mMaterial, mMaterial.mClampMode, mMaterial.mTranslation, mMaterial.mOverrideShader);
state.SetMaterial(mMaterial.mTexture, mMaterial.uFlags, mMaterial.mScaleFlags, mMaterial.mClampMode, mMaterial.mTranslation, mMaterial.mOverrideShader);
}
state.SetColor(Color[0], Color[1], Color[2], Color[3]);
@ -262,7 +248,6 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState)
FVector4 blendcol(0, 0, 0, 0);
int flags = 0;
if (Flags & RF_ShadeInterpolate) flags |= 16384; // hijack a free bit in here.
if (fullscreenTint != 0xffffff) flags |= 16;
if (hictint_flags != -1)
{
@ -274,7 +259,7 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState)
modcol.Z *= hictint.b / 64.f;
}
if (hictint_flags & TINTF_GRAYSCALE)
modcol.W = 1.f;
modcol.W = 1.f;
if (hictint_flags & TINTF_INVERT)
flags |= TextureManipulation::InvertBit;
@ -286,6 +271,7 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState)
}
}
addcol.W = flags;
if (Flags & RF_ShadeInterpolate) addcol.W += 16384; // hijack a free bit in here.
state.SetTextureColors(&modcol.X, &addcol.X, &blendcol.X);
if (matrixIndex[Matrix_Model] != -1)

View file

@ -269,22 +269,16 @@ public:
SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f));
}
void SetMaterial(FMaterial* mat, int clampmode, int translation, int overrideshader)
void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, int translation, int overrideshader)
{
assert(mat);
renderState.mMaterial.mMaterial = mat;
assert(tex);
renderState.mMaterial.mTexture = tex;
renderState.mMaterial.uFlags = upscalemask;
renderState.mMaterial.mScaleFlags = scaleflags;
renderState.mMaterial.mClampMode = clampmode;
renderState.mMaterial.mTranslation = translation;
renderState.mMaterial.mOverrideShader = overrideshader;
renderState.mMaterial.mChanged = true;
//mTextureModeFlags = mat->GetLayerFlags();
}
void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, int translation, int overrideshader)
{
assert(tex);
if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale;
SetMaterial(FMaterial::ValidateTexture(tex, scaleflags), clampmode, translation, overrideshader);
}
void UseColorOnly(bool yes)

View file

@ -43,6 +43,28 @@ enum PRSFlags
STF_SCISSORSET = 8192,
};
struct PolymostTextureState
{
FGameTexture* mTexture = nullptr;
EUpscaleFlags uFlags;
int mScaleFlags;
int mClampMode;
int mTranslation;
int mOverrideShader;
bool mChanged;
void Reset()
{
mTexture = nullptr;
uFlags = UF_None;
mScaleFlags = 0;
mTranslation = 0;
mClampMode = CLAMP_NONE;
mOverrideShader = -1;
mChanged = false;
}
};
struct PolymostRenderState
{
int vindex, vcount, primtype;
@ -59,7 +81,7 @@ struct PolymostRenderState
PalEntry fullscreenTint = 0xffffff, hictint = 0xffffff, hictint_overlay = 0xffffff;
int hictint_flags = -1;
FDepthBiasState mBias{ };
FMaterialState mMaterial;
PolymostTextureState mMaterial;
int StateFlags = STF_COLORMASK|STF_DEPTHMASK;
FRenderStyle Style{};