2019-09-16 17:35:04 +00:00
|
|
|
#pragma once
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <algorithm>
|
2019-09-16 20:56:48 +00:00
|
|
|
#include <vector>
|
2019-09-17 17:03:42 +00:00
|
|
|
#include <map>
|
2020-09-12 19:23:14 +00:00
|
|
|
#include "c_cvars.h"
|
2019-09-16 21:28:26 +00:00
|
|
|
#include "gl_samplers.h"
|
2019-09-17 17:03:42 +00:00
|
|
|
#include "gl_hwtexture.h"
|
2019-10-04 16:12:03 +00:00
|
|
|
#include "matrix.h"
|
2019-10-06 17:32:35 +00:00
|
|
|
#include "palentry.h"
|
2019-11-05 22:35:38 +00:00
|
|
|
#include "renderstyle.h"
|
2020-05-30 19:45:17 +00:00
|
|
|
#include "hw_material.h"
|
2020-05-31 08:24:04 +00:00
|
|
|
#include "hw_renderstate.h"
|
|
|
|
#include "pm_renderstate.h"
|
2020-06-12 19:40:49 +00:00
|
|
|
#include "templates.h"
|
2019-09-16 20:56:48 +00:00
|
|
|
|
2019-10-05 10:28:08 +00:00
|
|
|
class FShader;
|
2020-05-25 21:59:07 +00:00
|
|
|
class FGameTexture;
|
2019-10-06 19:15:53 +00:00
|
|
|
class GLInstance;
|
2019-11-06 22:40:10 +00:00
|
|
|
class F2DDrawer;
|
2019-11-10 20:11:17 +00:00
|
|
|
struct palette_t;
|
2020-01-02 22:56:35 +00:00
|
|
|
extern int xdim, ydim;
|
2019-10-06 19:15:53 +00:00
|
|
|
|
2020-06-11 16:40:53 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
DM_MAINVIEW,
|
|
|
|
DM_OFFSCREEN
|
|
|
|
};
|
|
|
|
|
2019-10-06 19:15:53 +00:00
|
|
|
class PaletteManager
|
|
|
|
{
|
2020-06-14 18:59:26 +00:00
|
|
|
IHardwareTexture* palettetextures[256] = {};
|
2020-06-15 18:09:49 +00:00
|
|
|
IHardwareTexture* lookuptextures[256] = {};
|
2019-10-06 19:15:53 +00:00
|
|
|
|
|
|
|
GLInstance* const inst;
|
|
|
|
|
2019-11-10 20:11:17 +00:00
|
|
|
unsigned FindPalswap(const uint8_t* paldata, palette_t& fadecolor);
|
2019-10-06 19:15:53 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
PaletteManager(GLInstance *inst_) : inst(inst_)
|
|
|
|
{}
|
|
|
|
~PaletteManager();
|
|
|
|
void DeleteAll();
|
2020-06-15 18:09:49 +00:00
|
|
|
IHardwareTexture *GetPalette(int index);
|
|
|
|
IHardwareTexture* GetLookup(int index);
|
2019-10-06 19:15:53 +00:00
|
|
|
};
|
|
|
|
|
2019-09-16 17:35:04 +00:00
|
|
|
|
2019-10-04 19:13:04 +00:00
|
|
|
struct glinfo_t {
|
|
|
|
float maxanisotropy;
|
|
|
|
};
|
|
|
|
|
2020-05-31 08:24:04 +00:00
|
|
|
enum ECullSide
|
2019-09-16 17:35:04 +00:00
|
|
|
{
|
2019-10-04 16:12:03 +00:00
|
|
|
Cull_Front,
|
|
|
|
Cull_Back
|
|
|
|
};
|
|
|
|
|
2019-10-04 19:13:04 +00:00
|
|
|
enum EWinding
|
|
|
|
{
|
|
|
|
Winding_CCW,
|
|
|
|
Winding_CW
|
|
|
|
};
|
2019-10-17 22:20:27 +00:00
|
|
|
|
2019-11-07 19:31:16 +00:00
|
|
|
struct ImDrawData;
|
2019-11-10 20:11:17 +00:00
|
|
|
struct palette_t;
|
2019-11-07 19:31:16 +00:00
|
|
|
|
2020-01-05 11:56:32 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-05-30 18:55:29 +00:00
|
|
|
MAX_TEXTURES = 4, /*15*/ // slot 15 is used internally and not available. - The renderer uses only 5, though.
|
2020-01-05 11:56:32 +00:00
|
|
|
};
|
|
|
|
|
2020-01-03 09:09:38 +00:00
|
|
|
struct GLState
|
|
|
|
{
|
2020-06-12 20:32:49 +00:00
|
|
|
int Flags;
|
|
|
|
int DepthFunc;
|
2020-01-03 09:09:38 +00:00
|
|
|
};
|
|
|
|
|
2019-09-16 17:35:04 +00:00
|
|
|
class GLInstance
|
|
|
|
{
|
2020-06-15 18:09:49 +00:00
|
|
|
friend IHardwareTexture* setpalettelayer(int layer, int translation);
|
|
|
|
|
2020-06-05 15:02:21 +00:00
|
|
|
public:
|
2020-01-18 21:41:08 +00:00
|
|
|
TArray<PolymostRenderState> rendercommands;
|
2019-10-06 19:15:53 +00:00
|
|
|
PaletteManager palmanager;
|
2019-10-06 22:07:45 +00:00
|
|
|
int lastPalswapIndex = -1;
|
2020-05-25 21:59:07 +00:00
|
|
|
FGameTexture* currentTexture = nullptr;
|
2019-10-17 22:20:27 +00:00
|
|
|
int MatrixChange = 0;
|
2020-01-03 09:09:38 +00:00
|
|
|
|
2019-10-05 10:28:08 +00:00
|
|
|
PolymostRenderState renderState;
|
2019-09-17 17:03:42 +00:00
|
|
|
|
2019-09-16 17:35:04 +00:00
|
|
|
|
|
|
|
public:
|
2020-06-04 16:46:44 +00:00
|
|
|
float mProjectionM5 = 1.0f; // needed by ssao
|
2019-10-04 19:13:04 +00:00
|
|
|
glinfo_t glinfo;
|
2019-09-16 20:56:48 +00:00
|
|
|
|
2019-11-07 19:31:16 +00:00
|
|
|
void Init(int y);
|
2020-06-12 20:32:49 +00:00
|
|
|
|
2019-09-16 20:56:48 +00:00
|
|
|
void Deinit();
|
2019-09-17 17:03:42 +00:00
|
|
|
|
|
|
|
static int GetTexDimension(int value)
|
|
|
|
{
|
|
|
|
//if (value > gl.max_texturesize) return gl.max_texturesize;
|
|
|
|
return value;
|
|
|
|
}
|
2019-09-16 17:35:04 +00:00
|
|
|
|
2019-10-06 19:15:53 +00:00
|
|
|
GLInstance();
|
2019-09-16 17:35:04 +00:00
|
|
|
void Draw(EDrawType type, size_t start, size_t count);
|
2020-01-18 21:41:08 +00:00
|
|
|
void DoDraw();
|
|
|
|
|
2020-01-04 08:54:47 +00:00
|
|
|
float GetProjectionM5() { return mProjectionM5; }
|
2020-01-19 13:08:48 +00:00
|
|
|
int SetMatrix(int num, const VSMatrix *mat );
|
|
|
|
int SetMatrix(int num, const float *mat)
|
2019-10-04 16:12:03 +00:00
|
|
|
{
|
2020-01-19 13:08:48 +00:00
|
|
|
return SetMatrix(num, reinterpret_cast<const VSMatrix*>(mat));
|
2019-10-04 16:12:03 +00:00
|
|
|
}
|
2020-06-04 16:46:44 +00:00
|
|
|
void SetIdentityMatrix(int num);
|
2020-01-19 13:08:48 +00:00
|
|
|
void RestoreMatrix(int num, int index)
|
|
|
|
{
|
|
|
|
renderState.matrixIndex[num] = index;
|
2020-01-03 22:38:50 +00:00
|
|
|
}
|
2019-10-04 16:44:16 +00:00
|
|
|
|
2020-06-11 21:55:23 +00:00
|
|
|
void SetTextureMode(int m)
|
|
|
|
{
|
|
|
|
renderState.TextureMode = m;
|
|
|
|
}
|
|
|
|
|
2020-02-06 17:43:27 +00:00
|
|
|
void SetDepthBias(float a, float b)
|
|
|
|
{
|
|
|
|
renderState.mBias.mFactor = a;
|
|
|
|
renderState.mBias.mUnits = b;
|
|
|
|
renderState.mBias.mChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearDepthBias()
|
|
|
|
{
|
|
|
|
renderState.mBias.mFactor = 0;
|
|
|
|
renderState.mBias.mUnits = 0;
|
|
|
|
renderState.mBias.mChanged = true;
|
|
|
|
}
|
|
|
|
|
2019-10-06 22:07:45 +00:00
|
|
|
void SetPalswap(int index);
|
2020-09-20 18:39:11 +00:00
|
|
|
void SetFade(int palette);
|
2019-10-05 10:28:08 +00:00
|
|
|
|
|
|
|
void SetShade(int32_t shade, int numshades)
|
|
|
|
{
|
2020-07-05 07:02:23 +00:00
|
|
|
renderState.Shade = std::min(shade, numshades-1);
|
2019-10-19 23:14:48 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 17:06:31 +00:00
|
|
|
void SetVisibility(float visibility)
|
2019-10-05 10:28:08 +00:00
|
|
|
{
|
2020-06-05 17:06:31 +00:00
|
|
|
renderState.VisFactor = visibility;
|
2019-10-05 10:28:08 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 22:22:59 +00:00
|
|
|
void EnableBlend(bool on)
|
|
|
|
{
|
|
|
|
if (on) renderState.StateFlags |= STF_BLEND;
|
|
|
|
else renderState.StateFlags &= ~STF_BLEND;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableDepthTest(bool on)
|
|
|
|
{
|
|
|
|
if (on) renderState.StateFlags |= STF_DEPTHTEST;
|
|
|
|
else renderState.StateFlags &= ~STF_DEPTHTEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableStencilWrite(int value)
|
|
|
|
{
|
|
|
|
renderState.StateFlags |= STF_STENCILWRITE;
|
|
|
|
renderState.StateFlags &= ~STF_STENCILTEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableStencilTest(int value)
|
|
|
|
{
|
|
|
|
renderState.StateFlags &= ~STF_STENCILWRITE;
|
|
|
|
renderState.StateFlags |= STF_STENCILTEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableStencil()
|
|
|
|
{
|
|
|
|
renderState.StateFlags &= ~(STF_STENCILWRITE | STF_STENCILTEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCull(int type, int winding = Winding_CW)
|
|
|
|
{
|
|
|
|
renderState.StateFlags &= ~(STF_CULLCCW | STF_CULLCW);
|
|
|
|
if (type != Cull_None)
|
|
|
|
{
|
|
|
|
if (winding == Winding_CW) renderState.StateFlags |= STF_CULLCW;
|
|
|
|
else renderState.StateFlags |= STF_CULLCCW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetColorMask(bool on)
|
|
|
|
{
|
|
|
|
if (on) renderState.StateFlags |= STF_COLORMASK;
|
|
|
|
else renderState.StateFlags &= ~STF_COLORMASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDepthMask(bool on)
|
|
|
|
{
|
|
|
|
if (on) renderState.StateFlags |= STF_DEPTHMASK;
|
|
|
|
else renderState.StateFlags &= ~STF_DEPTHMASK;
|
|
|
|
}
|
|
|
|
|
2020-01-02 22:56:35 +00:00
|
|
|
void ClearScreen(PalEntry pe, bool depth)
|
|
|
|
{
|
|
|
|
renderState.ClearColor = pe;
|
|
|
|
renderState.StateFlags |= STF_CLEARCOLOR;
|
|
|
|
if (depth) renderState.StateFlags |= STF_CLEARDEPTH;
|
|
|
|
}
|
|
|
|
|
2020-01-03 09:48:01 +00:00
|
|
|
void SetViewport(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
renderState.vp_x = (short)x;
|
|
|
|
renderState.vp_y = (short)y;
|
|
|
|
renderState.vp_w = (short)w;
|
|
|
|
renderState.vp_h = (short)h;
|
|
|
|
renderState.StateFlags |= STF_VIEWPORTSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetScissor(int x1, int y1, int x2, int y2)
|
|
|
|
{
|
|
|
|
renderState.sc_x = (short)x1;
|
|
|
|
renderState.sc_y = (short)y1;
|
|
|
|
renderState.sc_w = (short)x2;
|
|
|
|
renderState.sc_h = (short)y2;
|
|
|
|
renderState.StateFlags |= STF_SCISSORSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableScissor()
|
|
|
|
{
|
2020-01-05 09:21:34 +00:00
|
|
|
renderState.sc_x = SHRT_MIN;
|
2020-01-03 09:48:01 +00:00
|
|
|
renderState.StateFlags |= STF_SCISSORSET;
|
|
|
|
}
|
|
|
|
|
2020-01-03 10:43:44 +00:00
|
|
|
void SetDepthFunc(int func)
|
|
|
|
{
|
|
|
|
renderState.DepthFunc = func;
|
|
|
|
}
|
|
|
|
|
2020-01-03 09:48:01 +00:00
|
|
|
|
2020-01-02 22:56:35 +00:00
|
|
|
void ClearScreen(PalEntry pe)
|
|
|
|
{
|
|
|
|
//twod->Clear();
|
|
|
|
SetViewport(0, 0, xdim, ydim);
|
2020-06-12 18:31:23 +00:00
|
|
|
ClearScreen(pe, true);
|
2020-01-02 22:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearDepth()
|
|
|
|
{
|
|
|
|
renderState.StateFlags |= STF_CLEARDEPTH;
|
|
|
|
}
|
2020-01-02 22:22:59 +00:00
|
|
|
|
2020-01-03 09:09:38 +00:00
|
|
|
void SetRenderStyle(FRenderStyle style)
|
|
|
|
{
|
|
|
|
renderState.Style = style;
|
|
|
|
}
|
|
|
|
|
2020-01-03 10:43:44 +00:00
|
|
|
void SetColor(float r, float g, float b, float a = 1.f)
|
|
|
|
{
|
|
|
|
renderState.Color[0] = r;
|
|
|
|
renderState.Color[1] = g;
|
|
|
|
renderState.Color[2] = b;
|
|
|
|
renderState.Color[3] = a;
|
|
|
|
}
|
|
|
|
void SetColorub(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
|
|
|
|
{
|
|
|
|
SetColor(r * (1 / 255.f), g * (1 / 255.f), b * (1 / 255.f), a * (1 / 255.f));
|
|
|
|
}
|
|
|
|
|
2020-05-30 19:45:17 +00:00
|
|
|
void SetMaterial(FMaterial* mat, int clampmode, int translation, int overrideshader)
|
|
|
|
{
|
|
|
|
assert(mat);
|
|
|
|
renderState.mMaterial.mMaterial = mat;
|
|
|
|
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);
|
|
|
|
}
|
2020-01-03 10:43:44 +00:00
|
|
|
|
2019-10-19 20:46:37 +00:00
|
|
|
void UseColorOnly(bool yes)
|
|
|
|
{
|
|
|
|
if (yes) renderState.Flags |= RF_ColorOnly;
|
|
|
|
else renderState.Flags &= ~RF_ColorOnly;
|
|
|
|
}
|
|
|
|
|
2020-06-07 07:30:55 +00:00
|
|
|
void SetNpotEmulation(float factor, float xOffset)
|
2019-10-05 10:28:08 +00:00
|
|
|
{
|
2020-06-08 06:16:50 +00:00
|
|
|
renderState.NPOTEmulation.Y = factor;
|
|
|
|
renderState.NPOTEmulation.X = xOffset;
|
2019-10-05 10:28:08 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 20:46:37 +00:00
|
|
|
void SetShadeInterpolate(int32_t yes)
|
2019-10-05 10:28:08 +00:00
|
|
|
{
|
2019-10-19 20:46:37 +00:00
|
|
|
if (yes) renderState.Flags |= RF_ShadeInterpolate;
|
|
|
|
else renderState.Flags &= ~RF_ShadeInterpolate;
|
2019-10-05 10:28:08 +00:00
|
|
|
}
|
|
|
|
|
2019-10-19 20:46:37 +00:00
|
|
|
void SetFadeDisable(bool yes)
|
2019-10-05 10:28:08 +00:00
|
|
|
{
|
2019-10-19 22:45:47 +00:00
|
|
|
if (yes) renderState.Flags |= RF_FogDisabled;
|
2019-10-19 20:46:37 +00:00
|
|
|
else renderState.Flags &= ~RF_FogDisabled;
|
2019-10-05 10:28:08 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 22:21:35 +00:00
|
|
|
// Hack...
|
|
|
|
bool useMapFog = false;
|
|
|
|
|
|
|
|
void SetMapFog(bool yes)
|
|
|
|
{
|
|
|
|
useMapFog = yes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyMapFog()
|
|
|
|
{
|
|
|
|
if (useMapFog) renderState.Flags |= RF_MapFog;
|
|
|
|
else renderState.Flags &= ~RF_MapFog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearMapFog()
|
|
|
|
{
|
|
|
|
renderState.Flags &= ~RF_MapFog;
|
|
|
|
}
|
|
|
|
|
2020-01-11 21:18:06 +00:00
|
|
|
void SetTinting(int flags, PalEntry color, PalEntry overlayColor)
|
2019-10-09 22:07:45 +00:00
|
|
|
{
|
2020-01-11 21:18:06 +00:00
|
|
|
renderState.hictint = color;
|
|
|
|
renderState.hictint_overlay = overlayColor;
|
|
|
|
renderState.hictint_flags = flags;
|
2019-10-09 22:07:45 +00:00
|
|
|
}
|
2019-10-17 18:29:58 +00:00
|
|
|
|
|
|
|
void SetBasepalTint(PalEntry color)
|
|
|
|
{
|
2020-01-11 21:18:06 +00:00
|
|
|
renderState.fullscreenTint = color;
|
2019-10-17 18:29:58 +00:00
|
|
|
}
|
2019-11-05 22:35:38 +00:00
|
|
|
|
2019-11-10 09:01:31 +00:00
|
|
|
void EnableAlphaTest(bool on)
|
|
|
|
{
|
|
|
|
renderState.AlphaTest = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAlphaThreshold(float al)
|
|
|
|
{
|
|
|
|
renderState.AlphaThreshold = al;
|
|
|
|
}
|
|
|
|
|
2020-09-13 19:08:10 +00:00
|
|
|
bool SetTexture(int globalpicnum, FGameTexture* tex, int palette, int sampleroverride, bool notindexed = false);
|
2019-09-16 17:35:04 +00:00
|
|
|
};
|
|
|
|
|
2019-10-04 16:12:03 +00:00
|
|
|
extern GLInstance GLInterface;
|
2020-08-30 08:42:44 +00:00
|
|
|
extern F2DDrawer twodpsp;
|
2020-05-30 22:01:00 +00:00
|
|
|
|
2020-06-04 16:46:44 +00:00
|
|
|
void renderSetProjectionMatrix(const float* p);
|
|
|
|
void renderSetViewMatrix(const float* p);
|
2020-06-05 17:06:31 +00:00
|
|
|
void renderSetVisibility(float v);
|
2020-05-30 22:01:00 +00:00
|
|
|
void renderBeginScene();
|
|
|
|
void renderFinishScene();
|
|
|
|
void DrawRateStuff();
|
2020-08-28 07:06:49 +00:00
|
|
|
void videoShowFrame(int32_t);
|
2020-08-14 19:01:27 +00:00
|
|
|
void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha = 1);
|