- started splitting the render state struct.

Reusable parts should be in hwrenderer later.
This commit is contained in:
Christoph Oelckers 2018-10-20 13:34:29 +02:00
parent 4603d01ba1
commit a4f7fd2e46
2 changed files with 148 additions and 135 deletions

View File

@ -59,24 +59,12 @@ static void matrixToGL(const VSMatrix &mat, int loc)
void FGLRenderState::Reset() void FGLRenderState::Reset()
{ {
mTextureEnabled = true; FRenderState::Reset();
mSplitEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false; mSplitEnabled = false;
mFogColor.d = -1;
mTextureMode = -1;
mDesaturation = 0;
mSrcBlend = GL_SRC_ALPHA; mSrcBlend = GL_SRC_ALPHA;
mDstBlend = GL_ONE_MINUS_SRC_ALPHA; mDstBlend = GL_ONE_MINUS_SRC_ALPHA;
mAlphaThreshold = 0.5f;
mBlendEquation = GL_FUNC_ADD; mBlendEquation = GL_FUNC_ADD;
mModelMatrixEnabled = false;
mTextureMatrixEnabled = false;
mObjectColor = 0xffffffff;
mObjectColor2 = 0;
mVertexBuffer = mCurrentVertexBuffer = NULL; mVertexBuffer = mCurrentVertexBuffer = NULL;
mSoftLight = 0;
mLightParms[0] = mLightParms[1] = mLightParms[2] = 0.0f;
mLightParms[3] = -1.f;
mSpecialEffect = EFF_NONE;
mGlossiness = 0.0f; mGlossiness = 0.0f;
mSpecularLevel = 0.0f; mSpecularLevel = 0.0f;
mShaderTimer = 0.0f; mShaderTimer = 0.0f;
@ -84,23 +72,12 @@ void FGLRenderState::Reset()
stSrcBlend = stDstBlend = -1; stSrcBlend = stDstBlend = -1;
stBlendEquation = -1; stBlendEquation = -1;
stAlphaThreshold = -1.f;
stAlphaTest = 0; stAlphaTest = 0;
mLastDepthClamp = true; mLastDepthClamp = true;
mInterpolationFactor = 0.0f; mInterpolationFactor = 0.0f;
mColor.Set(1.0f, 1.0f, 1.0f, 1.0f);
mGlowTop.Set(0.0f, 0.0f, 0.0f, 0.0f);
mGlowBottom.Set(0.0f, 0.0f, 0.0f, 0.0f);
mGlowTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mGlowBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mSplitTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mSplitBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f);
mEffectState = 0; mEffectState = 0;
activeShader = nullptr; activeShader = nullptr;
mModelMatrix.loadIdentity();
mTextureMatrix.loadIdentity();
mPassType = NORMAL_PASS; mPassType = NORMAL_PASS;
} }

View File

@ -74,31 +74,22 @@ enum EPassType
class FRenderState class FRenderState
{ {
}; protected:
class FGLRenderState : public FRenderState
{
bool mTextureEnabled;
uint8_t mFogEnabled; uint8_t mFogEnabled;
bool mGlowEnabled; uint8_t mTextureEnabled:1;
bool mSplitEnabled; uint8_t mGlowEnabled : 1;
bool mBrightmapEnabled; uint8_t mBrightmapEnabled : 1;
uint8_t mModelMatrixEnabled : 1;
uint8_t mTextureMatrixEnabled : 1;
int mSpecialEffect; int mSpecialEffect;
int mTextureMode; int mTextureMode;
int mDesaturation; int mDesaturation;
int mSoftLight; int mSoftLight;
float mLightParms[4]; float mLightParms[4];
int mSrcBlend, mDstBlend;
float mAlphaThreshold;
int mBlendEquation;
bool mModelMatrixEnabled;
bool mTextureMatrixEnabled;
bool mLastDepthClamp;
float mInterpolationFactor;
float mGlossiness, mSpecularLevel;
float mShaderTimer;
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer; float mAlphaThreshold;
FStateVec4 mNormal; FStateVec4 mNormal;
FStateVec4 mColor; FStateVec4 mColor;
FStateVec4 mGlowTop, mGlowBottom; FStateVec4 mGlowTop, mGlowBottom;
@ -108,61 +99,41 @@ class FGLRenderState : public FRenderState
PalEntry mObjectColor; PalEntry mObjectColor;
PalEntry mObjectColor2; PalEntry mObjectColor2;
FStateVec4 mDynColor; FStateVec4 mDynColor;
float mClipSplit[2];
int mEffectState;
int mTempTM = TM_MODULATE;
float stAlphaThreshold;
int stSrcBlend, stDstBlend;
bool stAlphaTest;
int stBlendEquation;
FShader *activeShader;
EPassType mPassType = NORMAL_PASS;
int mNumDrawBuffers = 1;
bool ApplyShader();
// Texture binding state
FMaterial *lastMaterial = nullptr;
int lastClamp = 0;
int lastTranslation = 0;
int maxBoundMaterial = -1;
public: public:
VSMatrix mModelMatrix; VSMatrix mModelMatrix;
VSMatrix mTextureMatrix; VSMatrix mTextureMatrix;
FGLRenderState() public:
void Reset()
{ {
Reset(); mTextureEnabled = true;
} mBrightmapEnabled = mFogEnabled = mGlowEnabled = false;
mFogColor.d = -1;
mTextureMode = -1;
mDesaturation = 0;
mAlphaThreshold = 0.5f;
mModelMatrixEnabled = false;
mTextureMatrixEnabled = false;
mObjectColor = 0xffffffff;
mObjectColor2 = 0;
mSoftLight = 0;
mLightParms[0] = mLightParms[1] = mLightParms[2] = 0.0f;
mLightParms[3] = -1.f;
mSpecialEffect = EFF_NONE;
void Reset(); mColor.Set(1.0f, 1.0f, 1.0f, 1.0f);
mGlowTop.Set(0.0f, 0.0f, 0.0f, 0.0f);
mGlowBottom.Set(0.0f, 0.0f, 0.0f, 0.0f);
mGlowTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mGlowBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mSplitTopPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mSplitBottomPlane.Set(0.0f, 0.0f, 0.0f, 0.0f);
mDynColor.Set(0.0f, 0.0f, 0.0f, 0.0f);
void ClearLastMaterial() mModelMatrix.loadIdentity();
{ mTextureMatrix.loadIdentity();
lastMaterial = nullptr;
}
void SetMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader, bool alphatexture);
void Apply();
void ApplyLightIndex(int index);
void SetVertexBuffer(FVertexBuffer *vb)
{
mVertexBuffer = vb;
}
void ResetVertexBuffer()
{
// forces rebinding with the next 'apply' call.
mCurrentVertexBuffer = NULL;
} }
void SetNormal(FVector3 norm) void SetNormal(FVector3 norm)
@ -183,19 +154,19 @@ public:
void SetColor(PalEntry pe, int desat = 0) void SetColor(PalEntry pe, int desat = 0)
{ {
mColor.Set(pe.r/255.f, pe.g/255.f, pe.b/255.f, pe.a/255.f); mColor.Set(pe.r / 255.f, pe.g / 255.f, pe.b / 255.f, pe.a / 255.f);
mDesaturation = desat; mDesaturation = desat;
} }
void SetColorAlpha(PalEntry pe, float alpha = 1.f, int desat = 0) void SetColorAlpha(PalEntry pe, float alpha = 1.f, int desat = 0)
{ {
mColor.Set(pe.r/255.f, pe.g/255.f, pe.b/255.f, alpha); mColor.Set(pe.r / 255.f, pe.g / 255.f, pe.b / 255.f, alpha);
mDesaturation = desat; mDesaturation = desat;
} }
void ResetColor() void ResetColor()
{ {
mColor.Set(1,1,1,1); mColor.Set(1, 1, 1, 1);
mDesaturation = 0; mDesaturation = 0;
} }
@ -229,24 +200,6 @@ public:
mGlowEnabled = on; mGlowEnabled = on;
} }
void EnableSplit(bool on)
{
if (!(gl.flags & RFL_NO_CLIP_PLANES))
{
mSplitEnabled = on;
if (on)
{
glEnable(GL_CLIP_DISTANCE3);
glEnable(GL_CLIP_DISTANCE4);
}
else
{
glDisable(GL_CLIP_DISTANCE3);
glDisable(GL_CLIP_DISTANCE4);
}
}
}
void EnableBrightmap(bool on) void EnableBrightmap(bool on)
{ {
mBrightmapEnabled = on; mBrightmapEnabled = on;
@ -305,12 +258,6 @@ public:
mObjectColor2 = pe; mObjectColor2 = pe;
} }
void SetSpecular(float glossiness, float specularLevel)
{
mGlossiness = glossiness;
mSpecularLevel = specularLevel;
}
void SetFog(PalEntry c, float d) void SetFog(PalEntry c, float d)
{ {
const float LOG2E = 1.442692f; // = 1/log(2) const float LOG2E = 1.442692f; // = 1/log(2)
@ -329,6 +276,113 @@ public:
return mFogColor; return mFogColor;
} }
void AlphaFunc(int func, float thresh)
{
if (func == GL_GREATER) mAlphaThreshold = thresh;
else mAlphaThreshold = thresh - 0.001f;
}
void SetPlaneTextureRotation(GLSectorPlane *plane, FMaterial *texture)
{
if (hw_SetPlaneTextureRotation(plane, texture, mTextureMatrix))
{
EnableTextureMatrix(true);
}
}
};
class FGLRenderState : public FRenderState
{
uint8_t mSplitEnabled : 1;
uint8_t mLastDepthClamp : 1;
int mSrcBlend, mDstBlend;
int mBlendEquation;
float mGlossiness, mSpecularLevel;
float mShaderTimer;
float mInterpolationFactor;
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer;
float mClipSplit[2];
int mEffectState;
int mTempTM = TM_MODULATE;
int stSrcBlend, stDstBlend;
bool stAlphaTest;
int stBlendEquation;
FShader *activeShader;
EPassType mPassType = NORMAL_PASS;
int mNumDrawBuffers = 1;
bool ApplyShader();
// Texture binding state
FMaterial *lastMaterial = nullptr;
int lastClamp = 0;
int lastTranslation = 0;
int maxBoundMaterial = -1;
public:
FGLRenderState()
{
Reset();
}
void Reset();
void ClearLastMaterial()
{
lastMaterial = nullptr;
}
void SetMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader, bool alphatexture);
void Apply();
void ApplyLightIndex(int index);
void SetVertexBuffer(FVertexBuffer *vb)
{
mVertexBuffer = vb;
}
void ResetVertexBuffer()
{
// forces rebinding with the next 'apply' call.
mCurrentVertexBuffer = NULL;
}
void EnableSplit(bool on)
{
if (!(gl.flags & RFL_NO_CLIP_PLANES))
{
mSplitEnabled = on;
if (on)
{
glEnable(GL_CLIP_DISTANCE3);
glEnable(GL_CLIP_DISTANCE4);
}
else
{
glDisable(GL_CLIP_DISTANCE3);
glDisable(GL_CLIP_DISTANCE4);
}
}
}
void SetSpecular(float glossiness, float specularLevel)
{
mGlossiness = glossiness;
mSpecularLevel = specularLevel;
}
void SetClipSplit(float bottom, float top) void SetClipSplit(float bottom, float top)
{ {
mClipSplit[0] = bottom; mClipSplit[0] = bottom;
@ -364,12 +418,6 @@ public:
} }
} }
void AlphaFunc(int func, float thresh)
{
if (func == GL_GREATER) mAlphaThreshold = thresh;
else mAlphaThreshold = thresh - 0.001f;
}
void BlendEquation(int eq) void BlendEquation(int eq)
{ {
if (!gl_direct_state_change) if (!gl_direct_state_change)
@ -428,18 +476,6 @@ public:
return mPassType == GBUFFER_PASS ? 3 : 1; return mPassType == GBUFFER_PASS ? 3 : 1;
} }
// Backwards compatibility crap follows
void ApplyFixedFunction();
void DrawColormapOverlay();
void SetPlaneTextureRotation(GLSectorPlane *plane, FMaterial *texture)
{
if (hw_SetPlaneTextureRotation(plane, texture, mTextureMatrix))
{
EnableTextureMatrix(true);
}
}
}; };
extern FGLRenderState gl_RenderState; extern FGLRenderState gl_RenderState;