Skip to content

Commit bb7fb68

Browse files
committed
opengl default pipe: dont do unnecessary alpha test
1 parent 276ac82 commit bb7fb68

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

src/gl/gl3device.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int32 u_lightColor;
136136
int32 u_matColor;
137137
int32 u_surfProps;
138138

139-
Shader *defaultShader;
139+
Shader *defaultShader, *defaultShader_noAT;
140140

141141
static bool32 stateDirty = 1;
142142
static bool32 sceneDirty = 1;
@@ -1829,6 +1829,9 @@ initOpenGL(void)
18291829
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
18301830
defaultShader = Shader::create(vs, fs);
18311831
assert(defaultShader);
1832+
const char *fs_noAT[] = { shaderDecl, "#define NO_ALPHATEST\n", header_frag_src, simple_frag_src, nil };
1833+
defaultShader_noAT = Shader::create(vs, fs_noAT);
1834+
assert(defaultShader_noAT);
18321835

18331836
openIm2D();
18341837
openIm3D();
@@ -1841,6 +1844,15 @@ termOpenGL(void)
18411844
{
18421845
closeIm3D();
18431846
closeIm2D();
1847+
1848+
defaultShader->destroy();
1849+
defaultShader = nil;
1850+
defaultShader_noAT->destroy();
1851+
defaultShader_noAT = nil;
1852+
1853+
glDeleteTextures(1, &whitetex);
1854+
whitetex = nil;
1855+
18441856
return 1;
18451857
}
18461858

src/gl/gl3render.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
149149
InstanceData *inst = header->inst;
150150
int32 n = header->numMeshes;
151151

152-
defaultShader->use();
153-
154152
while(n--){
155153
m = inst->material;
156154

@@ -160,6 +158,11 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
160158

161159
rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
162160

161+
if(getAlphaTest())
162+
defaultShader->use();
163+
else
164+
defaultShader_noAT->use();
165+
163166
drawInst(header, inst);
164167
inst++;
165168
}

src/gl/rwgl3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct InstanceDataHeader : rw::InstanceDataHeader
9797

9898
struct Shader;
9999

100-
extern Shader *defaultShader;
100+
extern Shader *defaultShader, *defaultShader_noAT;
101101

102102
struct Im3DVertex
103103
{

src/gl/shaders/header.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ out vec4 fragColor;
2323

2424
void DoAlphaTest(float a)
2525
{
26+
#ifndef NO_ALPHATEST
2627
if(a < u_alphaRef.x || a >= u_alphaRef.y)
2728
discard;
29+
#endif
2830
}

src/gl/shaders/header_fs.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ const char *header_frag_src =
2424

2525
"void DoAlphaTest(float a)\n"
2626
"{\n"
27+
"#ifndef NO_ALPHATEST\n"
2728
" if(a < u_alphaRef.x || a >= u_alphaRef.y)\n"
2829
" discard;\n"
30+
"#endif\n"
2931
"}\n"
3032
;

0 commit comments

Comments
 (0)