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"
|
2014-05-12 12:45:41 +00:00
|
|
|
#include "gl/data/gl_data.h"
|
2014-07-13 18:41:20 +00:00
|
|
|
#include "gl/data/gl_matrix.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;
|
2014-08-01 18:59:39 +00:00
|
|
|
class FShader;
|
2014-07-13 20:37:34 +00:00
|
|
|
extern TArray<VSMatrix> gl_MatrixStack;
|
2014-05-10 19:47:07 +00:00
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
EXTERN_CVAR(Bool, gl_direct_state_change)
|
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
struct FStateVec4
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
float vec[4];
|
|
|
|
|
|
|
|
void Set(float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
vec[0] = r;
|
|
|
|
vec[1] = g;
|
|
|
|
vec[2] = b;
|
|
|
|
vec[3] = a;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum EEffect
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
EFF_NONE=-1,
|
2013-06-23 07:49:34 +00:00
|
|
|
EFF_FOGBOUNDARY,
|
|
|
|
EFF_SPHEREMAP,
|
2014-05-12 12:45:41 +00:00
|
|
|
EFF_BURN,
|
|
|
|
EFF_STENCIL,
|
|
|
|
|
|
|
|
MAX_EFFECTS
|
2013-06-23 07:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FRenderState
|
|
|
|
{
|
|
|
|
bool mTextureEnabled;
|
|
|
|
bool mFogEnabled;
|
|
|
|
bool mGlowEnabled;
|
|
|
|
bool mBrightmapEnabled;
|
2014-08-01 18:59:39 +00:00
|
|
|
int mLightIndex;
|
2013-06-23 07:49:34 +00:00
|
|
|
int mSpecialEffect;
|
|
|
|
int mTextureMode;
|
2014-05-12 12:45:41 +00:00
|
|
|
int mDesaturation;
|
2014-05-11 22:13:19 +00:00
|
|
|
int mSoftLight;
|
2014-05-12 12:45:41 +00:00
|
|
|
float mLightParms[4];
|
2013-06-23 07:49:34 +00:00
|
|
|
int mSrcBlend, mDstBlend;
|
|
|
|
float mAlphaThreshold;
|
|
|
|
int mBlendEquation;
|
2014-08-01 18:59:39 +00:00
|
|
|
bool mAlphaTest;
|
2013-06-23 07:49:34 +00:00
|
|
|
bool m2D;
|
2014-07-13 18:41:20 +00:00
|
|
|
bool mModelMatrixEnabled;
|
|
|
|
bool mTextureMatrixEnabled;
|
2014-08-01 18:59:39 +00:00
|
|
|
float mInterpolationFactor;
|
|
|
|
float mClipHeightTop, mClipHeightBottom;
|
2014-07-26 18:56:10 +00:00
|
|
|
float mShaderTimer;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-05-10 19:47:07 +00:00
|
|
|
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer;
|
2014-05-11 14:06:25 +00:00
|
|
|
FStateVec4 mColor;
|
2014-05-12 12:45:41 +00:00
|
|
|
FStateVec4 mCameraPos;
|
2013-06-23 07:49:34 +00:00
|
|
|
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-07-01 07:52:41 +00:00
|
|
|
FStateVec4 mDynColor;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
int mEffectState;
|
|
|
|
int mColormapState;
|
|
|
|
|
2014-07-27 10:33:54 +00:00
|
|
|
float stAlphaThreshold;
|
|
|
|
int stSrcBlend, stDstBlend;
|
|
|
|
bool stAlphaTest;
|
|
|
|
int stBlendEquation;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-08-01 18:59:39 +00:00
|
|
|
FShader *activeShader;
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
bool ApplyShader();
|
|
|
|
|
|
|
|
public:
|
2014-07-13 18:41:20 +00:00
|
|
|
|
|
|
|
VSMatrix mProjectionMatrix;
|
|
|
|
VSMatrix mViewMatrix;
|
|
|
|
VSMatrix mModelMatrix;
|
|
|
|
VSMatrix mTextureMatrix;
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
FRenderState()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
2014-07-26 18:56:10 +00:00
|
|
|
void SetShader(int shaderindex, float warptime)
|
|
|
|
{
|
|
|
|
mEffectState = shaderindex;
|
|
|
|
mShaderTimer = warptime;
|
|
|
|
}
|
|
|
|
|
2014-06-21 13:50:32 +00:00
|
|
|
void Apply();
|
2014-07-13 18:41:20 +00:00
|
|
|
void ApplyMatrices();
|
2014-08-01 18:59:39 +00:00
|
|
|
void ApplyLightIndex(int index);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-05-10 19:47:07 +00:00
|
|
|
void SetVertexBuffer(FVertexBuffer *vb)
|
|
|
|
{
|
|
|
|
mVertexBuffer = vb;
|
|
|
|
}
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
void ResetVertexBuffer()
|
|
|
|
{
|
|
|
|
// forces rebinding with the next 'apply' call.
|
|
|
|
mCurrentVertexBuffer = NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-13 11:25:42 +00:00
|
|
|
void SetClipHeightTop(float clip)
|
2014-07-13 10:14:12 +00:00
|
|
|
{
|
2014-07-13 11:25:42 +00:00
|
|
|
mClipHeightTop = clip;
|
2014-07-13 10:14:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-13 11:25:42 +00:00
|
|
|
float GetClipHeightTop()
|
2014-07-13 10:14:12 +00:00
|
|
|
{
|
2014-07-13 11:25:42 +00:00
|
|
|
return mClipHeightTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetClipHeightBottom(float clip)
|
|
|
|
{
|
|
|
|
mClipHeightBottom = clip;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetClipHeightBottom()
|
|
|
|
{
|
|
|
|
return mClipHeightBottom;
|
2014-07-13 10:14:12 +00:00
|
|
|
}
|
|
|
|
|
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-12 12:45:41 +00:00
|
|
|
mDesaturation = desat;
|
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-12 12:45:41 +00:00
|
|
|
mDesaturation = desat;
|
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-12 12:45:41 +00:00
|
|
|
mDesaturation = desat;
|
2014-05-11 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResetColor()
|
|
|
|
{
|
|
|
|
mColor.Set(1,1,1,1);
|
2014-05-12 12:45:41 +00:00
|
|
|
mDesaturation = 0;
|
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;
|
|
|
|
}
|
|
|
|
|
2014-08-01 18:59:39 +00:00
|
|
|
void SetLightIndex(int n)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2014-08-01 18:59:39 +00:00
|
|
|
mLightIndex = n;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EnableBrightmap(bool on)
|
|
|
|
{
|
|
|
|
mBrightmapEnabled = on;
|
|
|
|
}
|
|
|
|
|
2014-07-13 18:41:20 +00:00
|
|
|
void EnableModelMatrix(bool on)
|
|
|
|
{
|
|
|
|
mModelMatrixEnabled = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableTextureMatrix(bool on)
|
|
|
|
{
|
|
|
|
mTextureMatrixEnabled = on;
|
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
void SetCameraPos(float x, float y, float z)
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
mCameraPos.Set(x, z, y, 0);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-11 22:13:19 +00:00
|
|
|
void SetSoftLightLevel(int level)
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
if (glset.lightmode == 8) mLightParms[3] = level / 255.f;
|
|
|
|
else mLightParms[3] = -1.f;
|
2014-05-11 22:13:19 +00:00
|
|
|
}
|
|
|
|
|
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-07-01 07:52:41 +00:00
|
|
|
mDynColor.Set(r, g, b, 0);
|
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)
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
const float LOG2E = 1.442692f; // = 1/log(2)
|
2013-06-23 07:49:34 +00:00
|
|
|
mFogColor = c;
|
2014-05-12 12:45:41 +00:00
|
|
|
if (d >= 0.0f) mLightParms[2] = d * (-LOG2E / 64000.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetLightParms(float f, float d)
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
mLightParms[1] = f;
|
|
|
|
mLightParms[0] = d;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-07-14 19:14:43 +00:00
|
|
|
if (func == GL_GREATER) mAlphaThreshold = thresh;
|
|
|
|
else mAlphaThreshold = thresh - 0.001f;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BlendEquation(int eq)
|
|
|
|
{
|
|
|
|
if (!gl_direct_state_change)
|
|
|
|
{
|
|
|
|
mBlendEquation = eq;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-27 10:33:54 +00:00
|
|
|
glBlendEquation(eq);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set2DMode(bool on)
|
|
|
|
{
|
|
|
|
m2D = on;
|
|
|
|
}
|
2014-06-29 09:00:21 +00:00
|
|
|
|
|
|
|
void SetInterpolationFactor(float fac)
|
|
|
|
{
|
|
|
|
mInterpolationFactor = fac;
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern FRenderState gl_RenderState;
|
|
|
|
|
|
|
|
#endif
|