2013-06-23 07:49:34 +00:00
|
|
|
#ifndef __GL_RENDERSTATE_H
|
|
|
|
#define __GL_RENDERSTATE_H
|
|
|
|
|
|
|
|
#include <string.h>
|
2014-05-11 17:44:19 +00:00
|
|
|
#include "gl/system/gl_interface.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "c_cvars.h"
|
2014-05-10 15:09:43 +00:00
|
|
|
#include "r_defs.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-05-10 19:47:07 +00:00
|
|
|
class FVertexBuffer;
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
EXTERN_CVAR(Bool, gl_direct_state_change)
|
|
|
|
|
|
|
|
struct FStateAttr
|
|
|
|
{
|
|
|
|
static int ChangeCounter;
|
|
|
|
int mLastChange;
|
|
|
|
|
|
|
|
FStateAttr()
|
|
|
|
{
|
|
|
|
mLastChange = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (const FStateAttr &other)
|
|
|
|
{
|
|
|
|
return mLastChange == other.mLastChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const FStateAttr &other)
|
|
|
|
{
|
|
|
|
return mLastChange != other.mLastChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FStateVec3 : public FStateAttr
|
|
|
|
{
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
bool Update(FStateVec3 *other)
|
|
|
|
{
|
|
|
|
if (mLastChange != other->mLastChange)
|
|
|
|
{
|
|
|
|
*this = *other;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(float x, float y, float z)
|
|
|
|
{
|
|
|
|
vec[0] = x;
|
|
|
|
vec[1] = z;
|
|
|
|
vec[2] = y;
|
|
|
|
mLastChange = ++ChangeCounter;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FStateVec4 : public FStateAttr
|
|
|
|
{
|
|
|
|
float vec[4];
|
|
|
|
|
|
|
|
bool Update(FStateVec4 *other)
|
|
|
|
{
|
|
|
|
if (mLastChange != other->mLastChange)
|
|
|
|
{
|
|
|
|
*this = *other;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
vec[0] = r;
|
|
|
|
vec[1] = g;
|
|
|
|
vec[2] = b;
|
|
|
|
vec[3] = a;
|
|
|
|
mLastChange = ++ChangeCounter;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum EEffect
|
|
|
|
{
|
|
|
|
EFF_NONE,
|
|
|
|
EFF_FOGBOUNDARY,
|
|
|
|
EFF_SPHEREMAP,
|
|
|
|
};
|
|
|
|
|
|
|
|
class FRenderState
|
|
|
|
{
|
|
|
|
bool mTextureEnabled;
|
|
|
|
bool mFogEnabled;
|
|
|
|
bool mGlowEnabled;
|
|
|
|
bool mLightEnabled;
|
|
|
|
bool mBrightmapEnabled;
|
|
|
|
int mSpecialEffect;
|
|
|
|
int mTextureMode;
|
|
|
|
float mLightParms[2];
|
|
|
|
int mNumLights[3];
|
|
|
|
float *mLightData;
|
|
|
|
int mSrcBlend, mDstBlend;
|
|
|
|
int mAlphaFunc;
|
|
|
|
float mAlphaThreshold;
|
|
|
|
bool mAlphaTest;
|
|
|
|
int mBlendEquation;
|
|
|
|
bool m2D;
|
|
|
|
|
2014-05-10 19:47:07 +00:00
|
|
|
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer;
|
2014-05-11 14:06:25 +00:00
|
|
|
FStateVec4 mColor;
|
2013-06-23 07:49:34 +00:00
|
|
|
FStateVec3 mCameraPos;
|
|
|
|
FStateVec4 mGlowTop, mGlowBottom;
|
2014-05-10 15:09:43 +00:00
|
|
|
FStateVec4 mGlowTopPlane, mGlowBottomPlane;
|
2013-06-23 07:49:34 +00:00
|
|
|
PalEntry mFogColor;
|
2014-05-11 14:06:25 +00:00
|
|
|
PalEntry mObjectColor;
|
2014-05-11 14:49:17 +00:00
|
|
|
PalEntry mDynColor;
|
2013-06-23 07:49:34 +00:00
|
|
|
float mFogDensity;
|
|
|
|
|
|
|
|
int mEffectState;
|
|
|
|
int mColormapState;
|
|
|
|
float mWarpTime;
|
|
|
|
|
|
|
|
int glSrcBlend, glDstBlend;
|
|
|
|
int glAlphaFunc;
|
|
|
|
float glAlphaThreshold;
|
|
|
|
bool glAlphaTest;
|
|
|
|
int glBlendEquation;
|
|
|
|
|
|
|
|
bool ffTextureEnabled;
|
|
|
|
bool ffFogEnabled;
|
|
|
|
int ffTextureMode;
|
|
|
|
int ffSpecialEffect;
|
|
|
|
PalEntry ffFogColor;
|
|
|
|
float ffFogDensity;
|
|
|
|
|
|
|
|
bool ApplyShader();
|
|
|
|
|
|
|
|
public:
|
|
|
|
FRenderState()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
2014-05-11 19:47:54 +00:00
|
|
|
int SetupShader(bool cameratexture, int &shaderindex, float warptime);
|
2013-06-23 07:49:34 +00:00
|
|
|
void Apply(bool forcenoshader = false);
|
|
|
|
|
2014-05-10 19:47:07 +00:00
|
|
|
void SetVertexBuffer(FVertexBuffer *vb)
|
|
|
|
{
|
|
|
|
mVertexBuffer = vb;
|
|
|
|
}
|
|
|
|
|
2014-05-11 14:06:25 +00:00
|
|
|
void SetColor(float r, float g, float b, float a = 1.f, int desat = 0)
|
|
|
|
{
|
|
|
|
mColor.Set(r, g, b, a);
|
2014-05-11 14:49:17 +00:00
|
|
|
glColor4fv(mColor.vec);
|
2014-05-11 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-05-11 14:49:17 +00:00
|
|
|
glColor4fv(mColor.vec);
|
2014-05-11 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2014-05-11 14:49:17 +00:00
|
|
|
glColor4fv(mColor.vec);
|
2014-05-11 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResetColor()
|
|
|
|
{
|
|
|
|
mColor.Set(1,1,1,1);
|
2014-05-11 14:49:17 +00:00
|
|
|
glColor4fv(mColor.vec);
|
2014-05-11 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
void SetTextureMode(int mode)
|
|
|
|
{
|
|
|
|
mTextureMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableTexture(bool on)
|
|
|
|
{
|
|
|
|
mTextureEnabled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableFog(bool on)
|
|
|
|
{
|
|
|
|
mFogEnabled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetEffect(int eff)
|
|
|
|
{
|
|
|
|
mSpecialEffect = eff;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableGlow(bool on)
|
|
|
|
{
|
|
|
|
mGlowEnabled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableLight(bool on)
|
|
|
|
{
|
|
|
|
mLightEnabled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableBrightmap(bool on)
|
|
|
|
{
|
|
|
|
mBrightmapEnabled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCameraPos(float x, float y, float z)
|
|
|
|
{
|
|
|
|
mCameraPos.Set(x,y,z);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetGlowParams(float *t, float *b)
|
|
|
|
{
|
|
|
|
mGlowTop.Set(t[0], t[1], t[2], t[3]);
|
|
|
|
mGlowBottom.Set(b[0], b[1], b[2], b[3]);
|
|
|
|
}
|
|
|
|
|
2014-05-10 15:09:43 +00:00
|
|
|
void SetGlowPlanes(const secplane_t &top, const secplane_t &bottom)
|
|
|
|
{
|
|
|
|
mGlowTopPlane.Set(FIXED2FLOAT(top.a), FIXED2FLOAT(top.b), FIXED2FLOAT(top.ic), FIXED2FLOAT(top.d));
|
|
|
|
mGlowBottomPlane.Set(FIXED2FLOAT(bottom.a), FIXED2FLOAT(bottom.b), FIXED2FLOAT(bottom.ic), FIXED2FLOAT(bottom.d));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDynLight(float r, float g, float b)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2014-05-11 14:49:17 +00:00
|
|
|
mDynColor = PalEntry(xs_CRoundToInt(r*255), xs_CRoundToInt(g*255), xs_CRoundToInt(b*255));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDynLight(PalEntry pe)
|
|
|
|
{
|
|
|
|
mDynColor = pe;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2014-05-11 14:54:11 +00:00
|
|
|
void SetObjectColor(PalEntry pe)
|
|
|
|
{
|
|
|
|
mObjectColor = pe;
|
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
void SetFog(PalEntry c, float d)
|
|
|
|
{
|
|
|
|
mFogColor = c;
|
|
|
|
if (d >= 0.0f) mFogDensity = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetLightParms(float f, float d)
|
|
|
|
{
|
|
|
|
mLightParms[0] = f;
|
|
|
|
mLightParms[1] = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetLights(int *numlights, float *lightdata)
|
|
|
|
{
|
|
|
|
mNumLights[0] = numlights[0];
|
|
|
|
mNumLights[1] = numlights[1];
|
|
|
|
mNumLights[2] = numlights[2];
|
|
|
|
mLightData = lightdata; // caution: the data must be preserved by the caller until the 'apply' call!
|
|
|
|
}
|
|
|
|
|
2013-12-05 14:06:10 +00:00
|
|
|
void SetFixedColormap(int cm)
|
|
|
|
{
|
|
|
|
mColormapState = cm;
|
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
PalEntry GetFogColor() const
|
|
|
|
{
|
|
|
|
return mFogColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlendFunc(int src, int dst)
|
|
|
|
{
|
|
|
|
if (!gl_direct_state_change)
|
|
|
|
{
|
|
|
|
mSrcBlend = src;
|
|
|
|
mDstBlend = dst;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
glBlendFunc(src, dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlphaFunc(int func, float thresh)
|
|
|
|
{
|
|
|
|
if (!gl_direct_state_change)
|
|
|
|
{
|
|
|
|
mAlphaFunc = func;
|
|
|
|
mAlphaThreshold = thresh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
::glAlphaFunc(func, thresh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableAlphaTest(bool on)
|
|
|
|
{
|
|
|
|
if (!gl_direct_state_change)
|
|
|
|
{
|
|
|
|
mAlphaTest = on;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (on) glEnable(GL_ALPHA_TEST);
|
|
|
|
else glDisable(GL_ALPHA_TEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlendEquation(int eq)
|
|
|
|
{
|
|
|
|
if (!gl_direct_state_change)
|
|
|
|
{
|
|
|
|
mBlendEquation = eq;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-03 16:29:39 +00:00
|
|
|
::glBlendEquation(eq);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set2DMode(bool on)
|
|
|
|
{
|
|
|
|
m2D = on;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern FRenderState gl_RenderState;
|
|
|
|
|
|
|
|
#endif
|