mirror of https://github.com/aap/librw.git
opengl default pipe: dont do unnecessary alpha test
This commit is contained in:
parent
276ac82ddf
commit
bb7fb68531
|
@ -136,7 +136,7 @@ int32 u_lightColor;
|
|||
int32 u_matColor;
|
||||
int32 u_surfProps;
|
||||
|
||||
Shader *defaultShader;
|
||||
Shader *defaultShader, *defaultShader_noAT;
|
||||
|
||||
static bool32 stateDirty = 1;
|
||||
static bool32 sceneDirty = 1;
|
||||
|
@ -1829,6 +1829,9 @@ initOpenGL(void)
|
|||
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
|
||||
defaultShader = Shader::create(vs, fs);
|
||||
assert(defaultShader);
|
||||
const char *fs_noAT[] = { shaderDecl, "#define NO_ALPHATEST\n", header_frag_src, simple_frag_src, nil };
|
||||
defaultShader_noAT = Shader::create(vs, fs_noAT);
|
||||
assert(defaultShader_noAT);
|
||||
|
||||
openIm2D();
|
||||
openIm3D();
|
||||
|
@ -1841,6 +1844,15 @@ termOpenGL(void)
|
|||
{
|
||||
closeIm3D();
|
||||
closeIm2D();
|
||||
|
||||
defaultShader->destroy();
|
||||
defaultShader = nil;
|
||||
defaultShader_noAT->destroy();
|
||||
defaultShader_noAT = nil;
|
||||
|
||||
glDeleteTextures(1, &whitetex);
|
||||
whitetex = nil;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -149,8 +149,6 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||
InstanceData *inst = header->inst;
|
||||
int32 n = header->numMeshes;
|
||||
|
||||
defaultShader->use();
|
||||
|
||||
while(n--){
|
||||
m = inst->material;
|
||||
|
||||
|
@ -160,6 +158,11 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|||
|
||||
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
||||
|
||||
if(getAlphaTest())
|
||||
defaultShader->use();
|
||||
else
|
||||
defaultShader_noAT->use();
|
||||
|
||||
drawInst(header, inst);
|
||||
inst++;
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ struct InstanceDataHeader : rw::InstanceDataHeader
|
|||
|
||||
struct Shader;
|
||||
|
||||
extern Shader *defaultShader;
|
||||
extern Shader *defaultShader, *defaultShader_noAT;
|
||||
|
||||
struct Im3DVertex
|
||||
{
|
||||
|
|
|
@ -23,6 +23,8 @@ out vec4 fragColor;
|
|||
|
||||
void DoAlphaTest(float a)
|
||||
{
|
||||
#ifndef NO_ALPHATEST
|
||||
if(a < u_alphaRef.x || a >= u_alphaRef.y)
|
||||
discard;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -24,7 +24,9 @@ const char *header_frag_src =
|
|||
|
||||
"void DoAlphaTest(float a)\n"
|
||||
"{\n"
|
||||
"#ifndef NO_ALPHATEST\n"
|
||||
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
|
||||
" discard;\n"
|
||||
"#endif\n"
|
||||
"}\n"
|
||||
;
|
||||
|
|
Loading…
Reference in New Issue