opengl default pipe: dont do unnecessary alpha test

This commit is contained in:
aap 2021-02-20 00:02:51 +01:00
parent 276ac82ddf
commit bb7fb68531
5 changed files with 23 additions and 4 deletions

View File

@ -136,7 +136,7 @@ int32 u_lightColor;
int32 u_matColor; int32 u_matColor;
int32 u_surfProps; int32 u_surfProps;
Shader *defaultShader; Shader *defaultShader, *defaultShader_noAT;
static bool32 stateDirty = 1; static bool32 stateDirty = 1;
static bool32 sceneDirty = 1; static bool32 sceneDirty = 1;
@ -1829,6 +1829,9 @@ initOpenGL(void)
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil }; const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
defaultShader = Shader::create(vs, fs); defaultShader = Shader::create(vs, fs);
assert(defaultShader); 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(); openIm2D();
openIm3D(); openIm3D();
@ -1841,6 +1844,15 @@ termOpenGL(void)
{ {
closeIm3D(); closeIm3D();
closeIm2D(); closeIm2D();
defaultShader->destroy();
defaultShader = nil;
defaultShader_noAT->destroy();
defaultShader_noAT = nil;
glDeleteTextures(1, &whitetex);
whitetex = nil;
return 1; return 1;
} }

View File

@ -149,8 +149,6 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
InstanceData *inst = header->inst; InstanceData *inst = header->inst;
int32 n = header->numMeshes; int32 n = header->numMeshes;
defaultShader->use();
while(n--){ while(n--){
m = inst->material; m = inst->material;
@ -160,6 +158,11 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
if(getAlphaTest())
defaultShader->use();
else
defaultShader_noAT->use();
drawInst(header, inst); drawInst(header, inst);
inst++; inst++;
} }

View File

@ -97,7 +97,7 @@ struct InstanceDataHeader : rw::InstanceDataHeader
struct Shader; struct Shader;
extern Shader *defaultShader; extern Shader *defaultShader, *defaultShader_noAT;
struct Im3DVertex struct Im3DVertex
{ {

View File

@ -23,6 +23,8 @@ out vec4 fragColor;
void DoAlphaTest(float a) void DoAlphaTest(float a)
{ {
#ifndef NO_ALPHATEST
if(a < u_alphaRef.x || a >= u_alphaRef.y) if(a < u_alphaRef.x || a >= u_alphaRef.y)
discard; discard;
#endif
} }

View File

@ -24,7 +24,9 @@ const char *header_frag_src =
"void DoAlphaTest(float a)\n" "void DoAlphaTest(float a)\n"
"{\n" "{\n"
"#ifndef NO_ALPHATEST\n"
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n" " if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
" discard;\n" " discard;\n"
"#endif\n"
"}\n" "}\n"
; ;