mirror of https://github.com/aap/librw.git
some more state caching for gl3
This commit is contained in:
parent
3b385c44ae
commit
90ce0f90be
|
@ -1,11 +1,13 @@
|
||||||
uniform vec2 u_alphaRef;
|
uniform vec2 u_alphaRef;
|
||||||
|
|
||||||
uniform float u_fogStart;
|
uniform vec4 u_fogData;
|
||||||
uniform float u_fogEnd;
|
|
||||||
uniform float u_fogRange;
|
|
||||||
uniform float u_fogDisable;
|
|
||||||
uniform vec4 u_fogColor;
|
uniform vec4 u_fogColor;
|
||||||
|
|
||||||
|
#define u_fogStart (u_fogData.x)
|
||||||
|
#define u_fogEnd (u_fogData.y)
|
||||||
|
#define u_fogRange (u_fogData.z)
|
||||||
|
#define u_fogDisable (u_fogData.w)
|
||||||
|
|
||||||
void DoAlphaTest(float a)
|
void DoAlphaTest(float a)
|
||||||
{
|
{
|
||||||
if(a < u_alphaRef.x || a >= u_alphaRef.y)
|
if(a < u_alphaRef.x || a >= u_alphaRef.y)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
// State
|
// State
|
||||||
uniform float u_fogStart;
|
uniform vec4 u_fogData;
|
||||||
uniform float u_fogEnd;
|
|
||||||
uniform float u_fogRange;
|
|
||||||
uniform float u_fogDisable;
|
|
||||||
//uniform vec4 u_fogColor;
|
//uniform vec4 u_fogColor;
|
||||||
|
|
||||||
|
#define u_fogStart (u_fogData.x)
|
||||||
|
#define u_fogEnd (u_fogData.y)
|
||||||
|
#define u_fogRange (u_fogData.z)
|
||||||
|
#define u_fogDisable (u_fogData.w)
|
||||||
|
|
||||||
// Scene
|
// Scene
|
||||||
uniform mat4 u_proj;
|
uniform mat4 u_proj;
|
||||||
uniform mat4 u_view;
|
uniform mat4 u_view;
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
const char *header_frag_src =
|
const char *header_frag_src =
|
||||||
"uniform vec2 u_alphaRef;\n"
|
"uniform vec2 u_alphaRef;\n"
|
||||||
|
|
||||||
"uniform float u_fogStart;\n"
|
"uniform vec4 u_fogData;\n"
|
||||||
"uniform float u_fogEnd;\n"
|
|
||||||
"uniform float u_fogRange;\n"
|
|
||||||
"uniform float u_fogDisable;\n"
|
|
||||||
"uniform vec4 u_fogColor;\n"
|
"uniform vec4 u_fogColor;\n"
|
||||||
|
|
||||||
|
"#define u_fogStart (u_fogData.x)\n"
|
||||||
|
"#define u_fogEnd (u_fogData.y)\n"
|
||||||
|
"#define u_fogRange (u_fogData.z)\n"
|
||||||
|
"#define u_fogDisable (u_fogData.w)\n"
|
||||||
|
|
||||||
"void DoAlphaTest(float a)\n"
|
"void DoAlphaTest(float a)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
|
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
const char *header_vert_src =
|
const char *header_vert_src =
|
||||||
"// State\n"
|
"// State\n"
|
||||||
"uniform float u_fogStart;\n"
|
"uniform vec4 u_fogData;\n"
|
||||||
"uniform float u_fogEnd;\n"
|
|
||||||
"uniform float u_fogRange;\n"
|
|
||||||
"uniform float u_fogDisable;\n"
|
|
||||||
"//uniform vec4 u_fogColor;\n"
|
"//uniform vec4 u_fogColor;\n"
|
||||||
|
|
||||||
|
"#define u_fogStart (u_fogData.x)\n"
|
||||||
|
"#define u_fogEnd (u_fogData.y)\n"
|
||||||
|
"#define u_fogRange (u_fogData.z)\n"
|
||||||
|
"#define u_fogDisable (u_fogData.w)\n"
|
||||||
|
|
||||||
"// Scene\n"
|
"// Scene\n"
|
||||||
"uniform mat4 u_proj;\n"
|
"uniform mat4 u_proj;\n"
|
||||||
"uniform mat4 u_view;\n"
|
"uniform mat4 u_view;\n"
|
||||||
|
|
|
@ -65,12 +65,12 @@ struct UniformState
|
||||||
{
|
{
|
||||||
float32 alphaRefLow;
|
float32 alphaRefLow;
|
||||||
float32 alphaRefHigh;
|
float32 alphaRefHigh;
|
||||||
|
int32 pad[2];
|
||||||
|
|
||||||
float32 fogStart;
|
float32 fogStart;
|
||||||
float32 fogEnd;
|
float32 fogEnd;
|
||||||
|
|
||||||
float32 fogRange;
|
float32 fogRange;
|
||||||
float32 fogDisable;
|
float32 fogDisable;
|
||||||
int32 pad[2];
|
|
||||||
|
|
||||||
RGBAf fogColor;
|
RGBAf fogColor;
|
||||||
};
|
};
|
||||||
|
@ -133,10 +133,11 @@ static UniformObject uniformObject;
|
||||||
#ifndef RW_GL_USE_UBOS
|
#ifndef RW_GL_USE_UBOS
|
||||||
// State
|
// State
|
||||||
int32 u_alphaRef;
|
int32 u_alphaRef;
|
||||||
int32 u_fogStart;
|
int32 u_fogData;
|
||||||
int32 u_fogEnd;
|
//int32 u_fogStart;
|
||||||
int32 u_fogRange;
|
//int32 u_fogEnd;
|
||||||
int32 u_fogDisable;
|
//int32 u_fogRange;
|
||||||
|
//int32 u_fogDisable;
|
||||||
int32 u_fogColor;
|
int32 u_fogColor;
|
||||||
|
|
||||||
// Scene
|
// Scene
|
||||||
|
@ -193,6 +194,44 @@ struct RwStateCache {
|
||||||
};
|
};
|
||||||
static RwStateCache rwStateCache;
|
static RwStateCache rwStateCache;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
// actual gl states
|
||||||
|
RWGL_BLEND,
|
||||||
|
RWGL_SRCBLEND,
|
||||||
|
RWGL_DESTBLEND,
|
||||||
|
RWGL_DEPTHTEST,
|
||||||
|
RWGL_DEPTHFUNC,
|
||||||
|
RWGL_DEPTHMASK,
|
||||||
|
RWGL_CULL,
|
||||||
|
RWGL_CULLFACE,
|
||||||
|
|
||||||
|
// uniforms
|
||||||
|
RWGL_ALPHAFUNC,
|
||||||
|
RWGL_ALPHAREF,
|
||||||
|
RWGL_FOG,
|
||||||
|
RWGL_FOGSTART,
|
||||||
|
RWGL_FOGEND,
|
||||||
|
RWGL_FOGCOLOR,
|
||||||
|
|
||||||
|
RWGL_NUM_STATES
|
||||||
|
};
|
||||||
|
static bool uniformStateDirty[RWGL_NUM_STATES];
|
||||||
|
|
||||||
|
struct GlState {
|
||||||
|
bool32 blendEnable;
|
||||||
|
uint32 srcblend, destblend;
|
||||||
|
|
||||||
|
bool32 depthTest;
|
||||||
|
uint32 depthFunc;
|
||||||
|
|
||||||
|
uint32 depthMask;
|
||||||
|
|
||||||
|
bool32 cullEnable;
|
||||||
|
uint32 cullFace;
|
||||||
|
};
|
||||||
|
static GlState curGlState, oldGlState;
|
||||||
|
|
||||||
static int32 activeTexture;
|
static int32 activeTexture;
|
||||||
static uint32 boundTexture[MAXNUMSTAGES];
|
static uint32 boundTexture[MAXNUMSTAGES];
|
||||||
|
|
||||||
|
@ -211,12 +250,71 @@ static uint32 blendMap[] = {
|
||||||
GL_SRC_ALPHA_SATURATE,
|
GL_SRC_ALPHA_SATURATE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GL state cache
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
setGlRenderState(uint32 state, uint32 value)
|
||||||
|
{
|
||||||
|
switch(state){
|
||||||
|
case RWGL_BLEND: curGlState.blendEnable = value; break;
|
||||||
|
case RWGL_SRCBLEND: curGlState.srcblend = value; break;
|
||||||
|
case RWGL_DESTBLEND: curGlState.destblend = value; break;
|
||||||
|
case RWGL_DEPTHTEST: curGlState.depthTest = value; break;
|
||||||
|
case RWGL_DEPTHFUNC: curGlState.depthFunc = value; break;
|
||||||
|
case RWGL_DEPTHMASK: curGlState.depthMask = value; break;
|
||||||
|
case RWGL_CULL: curGlState.cullEnable = value; break;
|
||||||
|
case RWGL_CULLFACE: curGlState.cullFace = value; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
flushGlRenderState(void)
|
||||||
|
{
|
||||||
|
if(oldGlState.blendEnable != curGlState.blendEnable){
|
||||||
|
oldGlState.blendEnable = curGlState.blendEnable;
|
||||||
|
(oldGlState.blendEnable ? glEnable : glDisable)(GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(oldGlState.srcblend != curGlState.srcblend ||
|
||||||
|
oldGlState.destblend != curGlState.destblend){
|
||||||
|
oldGlState.srcblend = curGlState.srcblend;
|
||||||
|
oldGlState.destblend = curGlState.destblend;
|
||||||
|
glBlendFunc(oldGlState.srcblend, oldGlState.destblend);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(oldGlState.depthTest != curGlState.depthTest){
|
||||||
|
oldGlState.depthTest = curGlState.depthTest;
|
||||||
|
(oldGlState.depthTest ? glEnable : glDisable)(GL_DEPTH_TEST);
|
||||||
|
}
|
||||||
|
if(oldGlState.depthFunc != curGlState.depthFunc){
|
||||||
|
oldGlState.depthFunc = curGlState.depthFunc;
|
||||||
|
glDepthFunc(oldGlState.depthFunc);
|
||||||
|
}
|
||||||
|
if(oldGlState.depthMask != curGlState.depthMask){
|
||||||
|
oldGlState.depthMask = curGlState.depthMask;
|
||||||
|
glDepthMask(oldGlState.depthMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(oldGlState.cullEnable != curGlState.cullEnable){
|
||||||
|
oldGlState.cullEnable = curGlState.cullEnable;
|
||||||
|
(oldGlState.cullEnable ? glEnable : glDisable)(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
if(oldGlState.cullFace != curGlState.cullFace){
|
||||||
|
oldGlState.cullFace = curGlState.cullFace;
|
||||||
|
glCullFace(oldGlState.cullFace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
setAlphaBlend(bool32 enable)
|
setAlphaBlend(bool32 enable)
|
||||||
{
|
{
|
||||||
if(rwStateCache.blendEnable != enable){
|
if(rwStateCache.blendEnable != enable){
|
||||||
rwStateCache.blendEnable = enable;
|
rwStateCache.blendEnable = enable;
|
||||||
(enable ? glEnable : glDisable)(GL_BLEND);
|
setGlRenderState(RWGL_BLEND, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,14 +331,11 @@ setDepthTest(bool32 enable)
|
||||||
rwStateCache.ztest = enable;
|
rwStateCache.ztest = enable;
|
||||||
if(rwStateCache.zwrite && !enable){
|
if(rwStateCache.zwrite && !enable){
|
||||||
// If we still want to write, enable but set mode to always
|
// If we still want to write, enable but set mode to always
|
||||||
glEnable(GL_DEPTH_TEST);
|
setGlRenderState(RWGL_DEPTHTEST, true);
|
||||||
glDepthFunc(GL_ALWAYS);
|
setGlRenderState(RWGL_DEPTHFUNC, GL_ALWAYS);
|
||||||
}else{
|
}else{
|
||||||
if(rwStateCache.ztest)
|
setGlRenderState(RWGL_DEPTHTEST, rwStateCache.ztest);
|
||||||
glEnable(GL_DEPTH_TEST);
|
setGlRenderState(RWGL_DEPTHFUNC, GL_LEQUAL);
|
||||||
else
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
glDepthFunc(GL_LEQUAL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,10 +348,10 @@ setDepthWrite(bool32 enable)
|
||||||
rwStateCache.zwrite = enable;
|
rwStateCache.zwrite = enable;
|
||||||
if(enable && !rwStateCache.ztest){
|
if(enable && !rwStateCache.ztest){
|
||||||
// Have to switch on ztest so writing can work
|
// Have to switch on ztest so writing can work
|
||||||
glEnable(GL_DEPTH_TEST);
|
setGlRenderState(RWGL_DEPTHTEST, true);
|
||||||
glDepthFunc(GL_ALWAYS);
|
setGlRenderState(RWGL_DEPTHFUNC, GL_ALWAYS);
|
||||||
}
|
}
|
||||||
glDepthMask(rwStateCache.zwrite);
|
setGlRenderState(RWGL_DEPTHMASK, rwStateCache.zwrite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,6 +364,7 @@ setAlphaTest(bool32 enable)
|
||||||
shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS;
|
shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS;
|
||||||
if(alphaFunc != shaderfunc){
|
if(alphaFunc != shaderfunc){
|
||||||
alphaFunc = shaderfunc;
|
alphaFunc = shaderfunc;
|
||||||
|
uniformStateDirty[RWGL_ALPHAFUNC] = true;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,6 +379,7 @@ setAlphaTestFunction(uint32 function)
|
||||||
shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS;
|
shaderfunc = rwStateCache.alphaTestEnable ? rwStateCache.alphaFunc : ALPHAALWAYS;
|
||||||
if(alphaFunc != shaderfunc){
|
if(alphaFunc != shaderfunc){
|
||||||
alphaFunc = shaderfunc;
|
alphaFunc = shaderfunc;
|
||||||
|
uniformStateDirty[RWGL_ALPHAFUNC] = true;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,10 +498,6 @@ setRasterStageOnly(uint32 stage, Raster *raster)
|
||||||
alpha = natras->hasAlpha;
|
alpha = natras->hasAlpha;
|
||||||
}else{
|
}else{
|
||||||
bindTexture(whitetex);
|
bindTexture(whitetex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
alpha = 0;
|
alpha = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,10 +543,6 @@ setRasterStage(uint32 stage, Raster *raster)
|
||||||
alpha = natras->hasAlpha;
|
alpha = natras->hasAlpha;
|
||||||
}else{
|
}else{
|
||||||
bindTexture(whitetex);
|
bindTexture(whitetex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
alpha = 0;
|
alpha = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,13 +598,13 @@ setRenderState(int32 state, void *pvalue)
|
||||||
case SRCBLEND:
|
case SRCBLEND:
|
||||||
if(rwStateCache.srcblend != value){
|
if(rwStateCache.srcblend != value){
|
||||||
rwStateCache.srcblend = value;
|
rwStateCache.srcblend = value;
|
||||||
glBlendFunc(blendMap[rwStateCache.srcblend], blendMap[rwStateCache.destblend]);
|
setGlRenderState(RWGL_SRCBLEND, blendMap[rwStateCache.srcblend]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DESTBLEND:
|
case DESTBLEND:
|
||||||
if(rwStateCache.destblend != value){
|
if(rwStateCache.destblend != value){
|
||||||
rwStateCache.destblend = value;
|
rwStateCache.destblend = value;
|
||||||
glBlendFunc(blendMap[rwStateCache.srcblend], blendMap[rwStateCache.destblend]);
|
setGlRenderState(RWGL_DESTBLEND, blendMap[rwStateCache.destblend]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ZTESTENABLE:
|
case ZTESTENABLE:
|
||||||
|
@ -527,6 +616,7 @@ setRenderState(int32 state, void *pvalue)
|
||||||
case FOGENABLE:
|
case FOGENABLE:
|
||||||
if(rwStateCache.fogEnable != value){
|
if(rwStateCache.fogEnable != value){
|
||||||
rwStateCache.fogEnable = value;
|
rwStateCache.fogEnable = value;
|
||||||
|
uniformStateDirty[RWGL_FOG] = true;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -538,16 +628,17 @@ setRenderState(int32 state, void *pvalue)
|
||||||
c.blue = value>>16;
|
c.blue = value>>16;
|
||||||
c.alpha = value>>24;
|
c.alpha = value>>24;
|
||||||
convColor(&uniformState.fogColor, &c);
|
convColor(&uniformState.fogColor, &c);
|
||||||
|
uniformStateDirty[RWGL_FOGCOLOR] = true;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
break;
|
break;
|
||||||
case CULLMODE:
|
case CULLMODE:
|
||||||
if(rwStateCache.cullmode != value){
|
if(rwStateCache.cullmode != value){
|
||||||
rwStateCache.cullmode = value;
|
rwStateCache.cullmode = value;
|
||||||
if(rwStateCache.cullmode == CULLNONE)
|
if(rwStateCache.cullmode == CULLNONE)
|
||||||
glDisable(GL_CULL_FACE);
|
setGlRenderState(RWGL_CULL, false);
|
||||||
else{
|
else{
|
||||||
glEnable(GL_CULL_FACE);
|
setGlRenderState(RWGL_CULL, true);
|
||||||
glCullFace(rwStateCache.cullmode == CULLBACK ? GL_BACK : GL_FRONT);
|
setGlRenderState(RWGL_CULLFACE, rwStateCache.cullmode == CULLBACK ? GL_BACK : GL_FRONT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -558,6 +649,7 @@ setRenderState(int32 state, void *pvalue)
|
||||||
case ALPHATESTREF:
|
case ALPHATESTREF:
|
||||||
if(alphaRef != value/255.0f){
|
if(alphaRef != value/255.0f){
|
||||||
alphaRef = value/255.0f;
|
alphaRef = value/255.0f;
|
||||||
|
uniformStateDirty[RWGL_ALPHAREF] = true;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -656,21 +748,25 @@ resetRenderState(void)
|
||||||
rwStateCache.textureAlpha = 0;
|
rwStateCache.textureAlpha = 0;
|
||||||
rwStateCache.alphaTestEnable = 0;
|
rwStateCache.alphaTestEnable = 0;
|
||||||
|
|
||||||
|
memset(&oldGlState, 0xFF, sizeof(oldGlState));
|
||||||
|
|
||||||
rwStateCache.blendEnable = 0;
|
rwStateCache.blendEnable = 0;
|
||||||
glDisable(GL_BLEND);
|
setGlRenderState(RWGL_BLEND, false);
|
||||||
rwStateCache.srcblend = BLENDSRCALPHA;
|
rwStateCache.srcblend = BLENDSRCALPHA;
|
||||||
rwStateCache.destblend = BLENDINVSRCALPHA;
|
rwStateCache.destblend = BLENDINVSRCALPHA;
|
||||||
glBlendFunc(blendMap[rwStateCache.srcblend], blendMap[rwStateCache.destblend]);
|
setGlRenderState(RWGL_SRCBLEND, blendMap[rwStateCache.srcblend]);
|
||||||
|
setGlRenderState(RWGL_DESTBLEND, blendMap[rwStateCache.destblend]);
|
||||||
|
|
||||||
rwStateCache.zwrite = GL_TRUE;
|
rwStateCache.zwrite = GL_TRUE;
|
||||||
glDepthMask(rwStateCache.zwrite);
|
setGlRenderState(RWGL_DEPTHMASK, rwStateCache.zwrite);
|
||||||
|
|
||||||
rwStateCache.ztest = 1;
|
rwStateCache.ztest = 1;
|
||||||
glEnable(GL_DEPTH_TEST);
|
setGlRenderState(RWGL_DEPTHTEST, true);
|
||||||
glDepthFunc(GL_LEQUAL);
|
setGlRenderState(RWGL_DEPTHFUNC, GL_LEQUAL);
|
||||||
|
|
||||||
rwStateCache.cullmode = CULLNONE;
|
rwStateCache.cullmode = CULLNONE;
|
||||||
glDisable(GL_CULL_FACE);
|
setGlRenderState(RWGL_CULL, false);
|
||||||
|
setGlRenderState(RWGL_CULLFACE, GL_BACK);
|
||||||
|
|
||||||
activeTexture = -1;
|
activeTexture = -1;
|
||||||
for(int i = 0; i < MAXNUMSTAGES; i++){
|
for(int i = 0; i < MAXNUMSTAGES; i++){
|
||||||
|
@ -773,6 +869,8 @@ Shader *lastShaderUploaded;
|
||||||
void
|
void
|
||||||
flushCache(void)
|
flushCache(void)
|
||||||
{
|
{
|
||||||
|
flushGlRenderState();
|
||||||
|
|
||||||
#ifndef RW_GL_USE_UBOS
|
#ifndef RW_GL_USE_UBOS
|
||||||
#define U(i) currentShader->uniformLocations[i]
|
#define U(i) currentShader->uniformLocations[i]
|
||||||
|
|
||||||
|
@ -782,6 +880,16 @@ flushCache(void)
|
||||||
objectDirty = 1;
|
objectDirty = 1;
|
||||||
sceneDirty = 1;
|
sceneDirty = 1;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < RWGL_NUM_STATES; i++)
|
||||||
|
uniformStateDirty[i] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sceneDirty){
|
||||||
|
glUniformMatrix4fv(U(u_proj), 1, 0, uniformScene.proj);
|
||||||
|
glUniformMatrix4fv(U(u_view), 1, 0, uniformScene.view);
|
||||||
|
sceneDirty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(objectDirty){
|
if(objectDirty){
|
||||||
|
@ -794,38 +902,52 @@ flushCache(void)
|
||||||
objectDirty = 0;
|
objectDirty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sceneDirty){
|
// if(stateDirty){
|
||||||
glUniformMatrix4fv(U(u_proj), 1, 0, uniformScene.proj);
|
|
||||||
glUniformMatrix4fv(U(u_view), 1, 0, uniformScene.view);
|
|
||||||
sceneDirty = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(stateDirty){
|
|
||||||
uniformState.fogDisable = rwStateCache.fogEnable ? 0.0f : 1.0f;
|
uniformState.fogDisable = rwStateCache.fogEnable ? 0.0f : 1.0f;
|
||||||
uniformState.fogStart = rwStateCache.fogStart;
|
uniformState.fogStart = rwStateCache.fogStart;
|
||||||
uniformState.fogEnd = rwStateCache.fogEnd;
|
uniformState.fogEnd = rwStateCache.fogEnd;
|
||||||
uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd);
|
uniformState.fogRange = 1.0f/(rwStateCache.fogStart - rwStateCache.fogEnd);
|
||||||
|
|
||||||
switch(alphaFunc){
|
if(uniformStateDirty[RWGL_ALPHAFUNC] || uniformStateDirty[RWGL_ALPHAREF]){
|
||||||
case ALPHAALWAYS:
|
switch(alphaFunc){
|
||||||
default:
|
case ALPHAALWAYS:
|
||||||
glUniform2f(U(u_alphaRef), -1000.0f, 1000.0f);
|
default:
|
||||||
break;
|
glUniform2f(U(u_alphaRef), -1000.0f, 1000.0f);
|
||||||
case ALPHAGREATEREQUAL:
|
break;
|
||||||
glUniform2f(U(u_alphaRef), alphaRef, 1000.0f);
|
case ALPHAGREATEREQUAL:
|
||||||
break;
|
glUniform2f(U(u_alphaRef), alphaRef, 1000.0f);
|
||||||
case ALPHALESS:
|
break;
|
||||||
glUniform2f(U(u_alphaRef), -1000.0f, alphaRef);
|
case ALPHALESS:
|
||||||
break;
|
glUniform2f(U(u_alphaRef), -1000.0f, alphaRef);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
uniformStateDirty[RWGL_ALPHAFUNC] = false;
|
||||||
|
uniformStateDirty[RWGL_ALPHAREF] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
glUniform1f(U(u_fogStart), uniformState.fogStart);
|
if(uniformStateDirty[RWGL_FOG] ||
|
||||||
glUniform1f(U(u_fogEnd), uniformState.fogEnd);
|
uniformStateDirty[RWGL_FOGSTART] ||
|
||||||
glUniform1f(U(u_fogRange), uniformState.fogRange);
|
uniformStateDirty[RWGL_FOGEND]){
|
||||||
glUniform1f(U(u_fogDisable), uniformState.fogDisable);
|
float fogData[4] = {
|
||||||
glUniform4fv(U(u_fogColor), 1, (float*)&uniformState.fogColor);
|
uniformState.fogStart,
|
||||||
stateDirty = 0;
|
uniformState.fogEnd,
|
||||||
}
|
uniformState.fogRange,
|
||||||
|
uniformState.fogDisable
|
||||||
|
};
|
||||||
|
glUniform4fv(U(u_fogData), 1, fogData);
|
||||||
|
uniformStateDirty[RWGL_FOG] = false;
|
||||||
|
uniformStateDirty[RWGL_FOGSTART] = false;
|
||||||
|
uniformStateDirty[RWGL_FOGEND] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(uniformStateDirty[RWGL_FOGCOLOR]){
|
||||||
|
glUniform4fv(U(u_fogColor), 1, (float*)&uniformState.fogColor);
|
||||||
|
uniformStateDirty[RWGL_FOGCOLOR] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// stateDirty = 0;
|
||||||
|
// }
|
||||||
#else
|
#else
|
||||||
if(objectDirty){
|
if(objectDirty){
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, ubo_object);
|
glBindBuffer(GL_UNIFORM_BUFFER, ubo_object);
|
||||||
|
@ -991,10 +1113,12 @@ beginUpdate(Camera *cam)
|
||||||
|
|
||||||
if(rwStateCache.fogStart != cam->fogPlane){
|
if(rwStateCache.fogStart != cam->fogPlane){
|
||||||
rwStateCache.fogStart = cam->fogPlane;
|
rwStateCache.fogStart = cam->fogPlane;
|
||||||
|
uniformStateDirty[RWGL_FOGSTART] = true;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
if(rwStateCache.fogEnd != cam->farPlane){
|
if(rwStateCache.fogEnd != cam->farPlane){
|
||||||
rwStateCache.fogEnd = cam->farPlane;
|
rwStateCache.fogEnd = cam->farPlane;
|
||||||
|
uniformStateDirty[RWGL_FOGEND] = true;
|
||||||
stateDirty = 1;
|
stateDirty = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1239,10 +1363,11 @@ initOpenGL(void)
|
||||||
{
|
{
|
||||||
#ifndef RW_GL_USE_UBOS
|
#ifndef RW_GL_USE_UBOS
|
||||||
u_alphaRef = registerUniform("u_alphaRef");
|
u_alphaRef = registerUniform("u_alphaRef");
|
||||||
u_fogStart = registerUniform("u_fogStart");
|
u_fogData = registerUniform("u_fogData");
|
||||||
u_fogEnd = registerUniform("u_fogEnd");
|
// u_fogStart = registerUniform("u_fogStart");
|
||||||
u_fogRange = registerUniform("u_fogRange");
|
// u_fogEnd = registerUniform("u_fogEnd");
|
||||||
u_fogDisable = registerUniform("u_fogDisable");
|
// u_fogRange = registerUniform("u_fogRange");
|
||||||
|
// u_fogDisable = registerUniform("u_fogDisable");
|
||||||
u_fogColor = registerUniform("u_fogColor");
|
u_fogColor = registerUniform("u_fogColor");
|
||||||
u_proj = registerUniform("u_proj");
|
u_proj = registerUniform("u_proj");
|
||||||
u_view = registerUniform("u_view");
|
u_view = registerUniform("u_view");
|
||||||
|
@ -1266,8 +1391,10 @@ initOpenGL(void)
|
||||||
byte whitepixel[4] = {0xFF, 0xFF, 0xFF, 0xFF};
|
byte whitepixel[4] = {0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
glGenTextures(1, &whitetex);
|
glGenTextures(1, &whitetex);
|
||||||
glBindTexture(GL_TEXTURE_2D, whitetex);
|
glBindTexture(GL_TEXTURE_2D, whitetex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1,
|
||||||
0, GL_RGBA, GL_UNSIGNED_BYTE, &whitepixel);
|
0, GL_RGBA, GL_UNSIGNED_BYTE, &whitepixel);
|
||||||
|
|
||||||
|
|
|
@ -2,25 +2,21 @@
|
||||||
layout(std140) uniform State
|
layout(std140) uniform State
|
||||||
{
|
{
|
||||||
vec2 u_alphaRef;
|
vec2 u_alphaRef;
|
||||||
|
vec4 u_fogData;
|
||||||
float u_fogStart;
|
|
||||||
float u_fogEnd;
|
|
||||||
float u_fogRange;
|
|
||||||
float u_fogDisable;
|
|
||||||
vec4 u_fogColor;
|
vec4 u_fogColor;
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
//uniform int u_alphaTest;
|
|
||||||
//uniform float u_alphaRef;
|
|
||||||
uniform vec2 u_alphaRef;
|
uniform vec2 u_alphaRef;
|
||||||
|
|
||||||
uniform float u_fogStart;
|
uniform vec4 u_fogData;
|
||||||
uniform float u_fogEnd;
|
|
||||||
uniform float u_fogRange;
|
|
||||||
uniform float u_fogDisable;
|
|
||||||
uniform vec4 u_fogColor;
|
uniform vec4 u_fogColor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define u_fogStart (u_fogData.x)
|
||||||
|
#define u_fogEnd (u_fogData.y)
|
||||||
|
#define u_fogRange (u_fogData.z)
|
||||||
|
#define u_fogDisable (u_fogData.w)
|
||||||
|
|
||||||
void DoAlphaTest(float a)
|
void DoAlphaTest(float a)
|
||||||
{
|
{
|
||||||
if(a < u_alphaRef.x || a >= u_alphaRef.y)
|
if(a < u_alphaRef.x || a >= u_alphaRef.y)
|
||||||
|
|
|
@ -7,23 +7,20 @@
|
||||||
layout(std140) uniform State
|
layout(std140) uniform State
|
||||||
{
|
{
|
||||||
vec2 u_alphaRef;
|
vec2 u_alphaRef;
|
||||||
|
vec4 u_fogData;
|
||||||
float u_fogStart;
|
|
||||||
float u_fogEnd;
|
|
||||||
float u_fogRange;
|
|
||||||
float u_fogDisable;
|
|
||||||
vec4 u_fogColor;
|
vec4 u_fogColor;
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
uniform vec2 u_alphaRef;
|
uniform vec2 u_alphaRef;
|
||||||
|
uniform vec4 u_fogData;
|
||||||
uniform float u_fogStart;
|
|
||||||
uniform float u_fogEnd;
|
|
||||||
uniform float u_fogRange;
|
|
||||||
uniform float u_fogDisable;
|
|
||||||
uniform vec4 u_fogColor;
|
uniform vec4 u_fogColor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define u_fogStart (u_fogData.x)
|
||||||
|
#define u_fogEnd (u_fogData.y)
|
||||||
|
#define u_fogRange (u_fogData.z)
|
||||||
|
#define u_fogDisable (u_fogData.w)
|
||||||
|
|
||||||
#ifdef USE_UBOS
|
#ifdef USE_UBOS
|
||||||
layout(std140) uniform Scene
|
layout(std140) uniform Scene
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,25 +3,21 @@ const char *header_frag_src =
|
||||||
"layout(std140) uniform State\n"
|
"layout(std140) uniform State\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec2 u_alphaRef;\n"
|
" vec2 u_alphaRef;\n"
|
||||||
|
" vec4 u_fogData;\n"
|
||||||
" float u_fogStart;\n"
|
|
||||||
" float u_fogEnd;\n"
|
|
||||||
" float u_fogRange;\n"
|
|
||||||
" float u_fogDisable;\n"
|
|
||||||
" vec4 u_fogColor;\n"
|
" vec4 u_fogColor;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"//uniform int u_alphaTest;\n"
|
|
||||||
"//uniform float u_alphaRef;\n"
|
|
||||||
"uniform vec2 u_alphaRef;\n"
|
"uniform vec2 u_alphaRef;\n"
|
||||||
|
|
||||||
"uniform float u_fogStart;\n"
|
"uniform vec4 u_fogData;\n"
|
||||||
"uniform float u_fogEnd;\n"
|
|
||||||
"uniform float u_fogRange;\n"
|
|
||||||
"uniform float u_fogDisable;\n"
|
|
||||||
"uniform vec4 u_fogColor;\n"
|
"uniform vec4 u_fogColor;\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
|
|
||||||
|
"#define u_fogStart (u_fogData.x)\n"
|
||||||
|
"#define u_fogEnd (u_fogData.y)\n"
|
||||||
|
"#define u_fogRange (u_fogData.z)\n"
|
||||||
|
"#define u_fogDisable (u_fogData.w)\n"
|
||||||
|
|
||||||
"void DoAlphaTest(float a)\n"
|
"void DoAlphaTest(float a)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
|
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
|
||||||
|
|
|
@ -8,23 +8,20 @@ const char *header_vert_src =
|
||||||
"layout(std140) uniform State\n"
|
"layout(std140) uniform State\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec2 u_alphaRef;\n"
|
" vec2 u_alphaRef;\n"
|
||||||
|
" vec4 u_fogData;\n"
|
||||||
" float u_fogStart;\n"
|
|
||||||
" float u_fogEnd;\n"
|
|
||||||
" float u_fogRange;\n"
|
|
||||||
" float u_fogDisable;\n"
|
|
||||||
" vec4 u_fogColor;\n"
|
" vec4 u_fogColor;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"#else\n"
|
"#else\n"
|
||||||
"uniform vec2 u_alphaRef;\n"
|
"uniform vec2 u_alphaRef;\n"
|
||||||
|
"uniform vec4 u_fogData;\n"
|
||||||
"uniform float u_fogStart;\n"
|
|
||||||
"uniform float u_fogEnd;\n"
|
|
||||||
"uniform float u_fogRange;\n"
|
|
||||||
"uniform float u_fogDisable;\n"
|
|
||||||
"uniform vec4 u_fogColor;\n"
|
"uniform vec4 u_fogColor;\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
|
|
||||||
|
"#define u_fogStart (u_fogData.x)\n"
|
||||||
|
"#define u_fogEnd (u_fogData.y)\n"
|
||||||
|
"#define u_fogRange (u_fogData.z)\n"
|
||||||
|
"#define u_fogDisable (u_fogData.w)\n"
|
||||||
|
|
||||||
"#ifdef USE_UBOS\n"
|
"#ifdef USE_UBOS\n"
|
||||||
"layout(std140) uniform Scene\n"
|
"layout(std140) uniform Scene\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue