2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
#ifndef __GL_SHADERS_H__
|
|
|
|
#define __GL_SHADERS_H__
|
|
|
|
|
|
|
|
#include "gl/renderer/gl_renderstate.h"
|
|
|
|
#include "name.h"
|
|
|
|
|
|
|
|
extern bool gl_shaderactive;
|
|
|
|
|
2014-06-29 09:00:21 +00:00
|
|
|
enum
|
|
|
|
{
|
2014-07-14 22:59:01 +00:00
|
|
|
VATTR_VERTEX = 0,
|
|
|
|
VATTR_TEXCOORD = 1,
|
|
|
|
VATTR_COLOR = 2,
|
|
|
|
VATTR_VERTEX2 = 3
|
2014-06-29 09:00:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
class FUniform1i
|
|
|
|
{
|
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Init(GLuint hShader, const GLchar *name)
|
|
|
|
{
|
|
|
|
mIndex = glGetUniformLocation(hShader, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(int newvalue)
|
|
|
|
{
|
|
|
|
glUniform1i(mIndex, newvalue);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FBufferedUniform1i
|
|
|
|
{
|
|
|
|
int mBuffer;
|
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Init(GLuint hShader, const GLchar *name)
|
|
|
|
{
|
|
|
|
mIndex = glGetUniformLocation(hShader, name);
|
|
|
|
mBuffer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(int newvalue)
|
|
|
|
{
|
|
|
|
if (newvalue != mBuffer)
|
|
|
|
{
|
|
|
|
mBuffer = newvalue;
|
|
|
|
glUniform1i(mIndex, newvalue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FBufferedUniform4i
|
|
|
|
{
|
|
|
|
int mBuffer[4];
|
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Init(GLuint hShader, const GLchar *name)
|
|
|
|
{
|
|
|
|
mIndex = glGetUniformLocation(hShader, name);
|
|
|
|
memset(mBuffer, 0, sizeof(mBuffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(const int *newvalue)
|
|
|
|
{
|
|
|
|
if (memcmp(newvalue, mBuffer, sizeof(mBuffer)))
|
|
|
|
{
|
|
|
|
memcpy(mBuffer, newvalue, sizeof(mBuffer));
|
|
|
|
glUniform4iv(mIndex, 1, newvalue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FBufferedUniform1f
|
|
|
|
{
|
2014-06-29 12:08:44 +00:00
|
|
|
float mBuffer;
|
2014-05-12 12:45:41 +00:00
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Init(GLuint hShader, const GLchar *name)
|
|
|
|
{
|
|
|
|
mIndex = glGetUniformLocation(hShader, name);
|
|
|
|
mBuffer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(float newvalue)
|
|
|
|
{
|
|
|
|
if (newvalue != mBuffer)
|
|
|
|
{
|
|
|
|
mBuffer = newvalue;
|
|
|
|
glUniform1f(mIndex, newvalue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FBufferedUniform4f
|
|
|
|
{
|
|
|
|
float mBuffer[4];
|
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Init(GLuint hShader, const GLchar *name)
|
|
|
|
{
|
|
|
|
mIndex = glGetUniformLocation(hShader, name);
|
|
|
|
memset(mBuffer, 0, sizeof(mBuffer));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(const float *newvalue)
|
|
|
|
{
|
|
|
|
if (memcmp(newvalue, mBuffer, sizeof(mBuffer)))
|
|
|
|
{
|
|
|
|
memcpy(mBuffer, newvalue, sizeof(mBuffer));
|
|
|
|
glUniform4fv(mIndex, 1, newvalue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FUniform4f
|
|
|
|
{
|
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Init(GLuint hShader, const GLchar *name)
|
|
|
|
{
|
|
|
|
mIndex = glGetUniformLocation(hShader, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(const float *newvalue)
|
|
|
|
{
|
|
|
|
glUniform4fv(mIndex, 1, newvalue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(float a, float b, float c, float d)
|
|
|
|
{
|
|
|
|
glUniform4f(mIndex, a, b, c, d);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FBufferedUniformPE
|
|
|
|
{
|
|
|
|
PalEntry mBuffer;
|
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Init(GLuint hShader, const GLchar *name)
|
|
|
|
{
|
|
|
|
mIndex = glGetUniformLocation(hShader, name);
|
|
|
|
mBuffer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set(PalEntry newvalue)
|
|
|
|
{
|
|
|
|
if (newvalue != mBuffer)
|
|
|
|
{
|
|
|
|
mBuffer = newvalue;
|
|
|
|
glUniform4f(mIndex, newvalue.r/255.f, newvalue.g/255.f, newvalue.b/255.f, newvalue.a/255.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
class FShader
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
friend class FShaderManager;
|
2013-06-23 07:49:34 +00:00
|
|
|
friend class FRenderState;
|
|
|
|
|
|
|
|
unsigned int hShader;
|
|
|
|
unsigned int hVertProg;
|
|
|
|
unsigned int hFragProg;
|
2014-05-12 12:45:41 +00:00
|
|
|
FName mName;
|
|
|
|
|
|
|
|
FBufferedUniform1f muDesaturation;
|
|
|
|
FBufferedUniform1i muFogEnabled;
|
|
|
|
FBufferedUniform1i muTextureMode;
|
|
|
|
FBufferedUniform4f muCameraPos;
|
|
|
|
FBufferedUniform4f muLightParms;
|
|
|
|
FUniform1i muFixedColormap;
|
|
|
|
FUniform4f muColormapStart;
|
|
|
|
FUniform4f muColormapRange;
|
|
|
|
FBufferedUniform4i muLightRange;
|
|
|
|
FBufferedUniformPE muFogColor;
|
2014-07-01 07:52:41 +00:00
|
|
|
FBufferedUniform4f muDynLightColor;
|
2014-05-12 12:45:41 +00:00
|
|
|
FBufferedUniformPE muObjectColor;
|
|
|
|
FUniform4f muGlowBottomColor;
|
|
|
|
FUniform4f muGlowTopColor;
|
|
|
|
FUniform4f muGlowBottomPlane;
|
|
|
|
FUniform4f muGlowTopPlane;
|
2014-06-29 09:00:21 +00:00
|
|
|
FBufferedUniform1f muInterpolationFactor;
|
2014-07-13 11:25:42 +00:00
|
|
|
FBufferedUniform1f muClipHeightTop;
|
|
|
|
FBufferedUniform1f muClipHeightBottom;
|
2014-07-14 19:14:43 +00:00
|
|
|
FBufferedUniform1f muAlphaThreshold;
|
2014-05-12 12:45:41 +00:00
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
int timer_index;
|
|
|
|
int lights_index;
|
2014-07-13 21:13:40 +00:00
|
|
|
int projectionmatrix_index;
|
|
|
|
int viewmatrix_index;
|
2014-07-13 18:41:20 +00:00
|
|
|
int modelmatrix_index;
|
|
|
|
int texturematrix_index;
|
2014-06-30 16:10:55 +00:00
|
|
|
public:
|
|
|
|
int fakevb_index;
|
|
|
|
private:
|
2014-05-10 15:09:43 +00:00
|
|
|
int currentglowstate;
|
2014-05-12 12:45:41 +00:00
|
|
|
int currentfixedcolormap;
|
2014-07-13 18:41:20 +00:00
|
|
|
bool currentTextureMatrixState;
|
|
|
|
bool currentModelMatrixState;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
public:
|
2014-05-12 12:45:41 +00:00
|
|
|
FShader(const char *name)
|
|
|
|
: mName(name)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
hShader = hVertProg = hFragProg = 0;
|
2014-05-12 12:45:41 +00:00
|
|
|
currentglowstate = 0;
|
|
|
|
currentfixedcolormap = 0;
|
2014-07-13 18:41:20 +00:00
|
|
|
currentTextureMatrixState = true; // by setting the matrix state to 'true' it is guaranteed to be set the first time the render state gets applied.
|
|
|
|
currentModelMatrixState = true;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~FShader();
|
|
|
|
|
|
|
|
bool Load(const char * name, const char * vert_prog_lump, const char * fragprog, const char * fragprog2, const char *defines);
|
|
|
|
|
|
|
|
void SetColormapColor(float r, float g, float b, float r1, float g1, float b1);
|
|
|
|
void SetGlowParams(float *topcolors, float topheight, float *bottomcolors, float bottomheight);
|
|
|
|
void SetLightRange(int start, int end, int forceadd);
|
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
bool Bind();
|
2013-06-23 07:49:34 +00:00
|
|
|
unsigned int GetHandle() const { return hShader; }
|
|
|
|
|
2014-07-13 21:13:40 +00:00
|
|
|
void ApplyMatrices(VSMatrix *proj, VSMatrix *view);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// The global shader manager
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
class FShaderManager
|
|
|
|
{
|
2014-05-12 12:45:41 +00:00
|
|
|
TArray<FShader*> mTextureEffects;
|
2013-06-23 07:49:34 +00:00
|
|
|
FShader *mActiveShader;
|
2014-05-12 12:45:41 +00:00
|
|
|
FShader *mEffectShaders[MAX_EFFECTS];
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
void Clean();
|
|
|
|
void CompileShaders();
|
|
|
|
|
|
|
|
public:
|
|
|
|
FShaderManager();
|
|
|
|
~FShaderManager();
|
2014-07-13 11:25:42 +00:00
|
|
|
FShader *Compile(const char *ShaderName, const char *ShaderPath, bool usediscard);
|
2013-06-23 07:49:34 +00:00
|
|
|
int Find(const char *mame);
|
|
|
|
FShader *BindEffect(int effect);
|
|
|
|
void SetActiveShader(FShader *sh);
|
2014-05-12 12:45:41 +00:00
|
|
|
void SetWarpSpeed(unsigned int eff, float speed);
|
2014-07-13 21:13:40 +00:00
|
|
|
void ApplyMatrices(VSMatrix *proj, VSMatrix *view);
|
2014-06-30 16:10:55 +00:00
|
|
|
FShader *GetActiveShader() const
|
|
|
|
{
|
|
|
|
return mActiveShader;
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2014-05-12 12:45:41 +00:00
|
|
|
FShader *Get(unsigned int eff)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom
|
|
|
|
if (eff < mTextureEffects.Size())
|
|
|
|
{
|
|
|
|
return mTextureEffects[eff];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FIRST_USER_SHADER 12
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|