DXGL r285 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r284‎ | r285 | r286 >
Date:01:12, 15 December 2012
Author:admin
Status:new
Tags:
Comment:
Add alpha tests.
Modified paths:
  • /ddraw/glDirect3D.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3D.cpp
@@ -45,7 +45,8 @@
4646 D3DPBLENDCAPS_SRCALPHA | D3DPBLENDCAPS_INVSRCALPHA | D3DPBLENDCAPS_DESTALPHA |
4747 D3DPBLENDCAPS_INVDESTALPHA | D3DPBLENDCAPS_DESTCOLOR | D3DPBLENDCAPS_INVDESTCOLOR |
4848 D3DPBLENDCAPS_SRCALPHASAT | D3DPBLENDCAPS_BOTHSRCALPHA | D3DPBLENDCAPS_BOTHINVSRCALPHA, //dwDestBlendCaps
49 - 0, //dwAlphaCmpCaps
 49+ D3DPCMPCAPS_ALWAYS | D3DPCMPCAPS_EQUAL | D3DPCMPCAPS_GREATER | D3DPCMPCAPS_GREATEREQUAL |
 50+ D3DPCMPCAPS_LESS | D3DPCMPCAPS_LESSEQUAL | D3DPCMPCAPS_NEVER | D3DPCMPCAPS_NOTEQUAL, //dwAlphaCmpCaps
5051 D3DPSHADECAPS_COLORGOURAUDRGB, //dwShadeCaps
5152 D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_PERSPECTIVE, //dwTextureCaps
5253 D3DPTFILTERCAPS_NEAREST | D3DPTFILTERCAPS_LINEAR | D3DPTFILTERCAPS_MIPNEAREST |
@@ -72,7 +73,8 @@
7374 D3DPBLENDCAPS_SRCALPHA | D3DPBLENDCAPS_INVSRCALPHA | D3DPBLENDCAPS_DESTALPHA |
7475 D3DPBLENDCAPS_INVDESTALPHA | D3DPBLENDCAPS_DESTCOLOR | D3DPBLENDCAPS_INVDESTCOLOR |
7576 D3DPBLENDCAPS_SRCALPHASAT | D3DPBLENDCAPS_BOTHSRCALPHA | D3DPBLENDCAPS_BOTHINVSRCALPHA, //dwDestBlendCaps
76 - 0, //dwAlphaCmpCaps
 77+ D3DPCMPCAPS_ALWAYS | D3DPCMPCAPS_EQUAL | D3DPCMPCAPS_GREATER | D3DPCMPCAPS_GREATEREQUAL |
 78+ D3DPCMPCAPS_LESS | D3DPCMPCAPS_LESSEQUAL | D3DPCMPCAPS_NEVER | D3DPCMPCAPS_NOTEQUAL, //dwAlphaCmpCaps
7779 D3DPSHADECAPS_COLORGOURAUDRGB, //dwShadeCaps
7880 D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_PERSPECTIVE, //dwTextureCaps
7981 D3DPTFILTERCAPS_NEAREST | D3DPTFILTERCAPS_LINEAR | D3DPTFILTERCAPS_MIPNEAREST |
Index: ddraw/glRenderer.cpp
@@ -1544,6 +1544,7 @@
15451545 }
15461546 if(prog.uniforms[137]!= -1) glUniform1f(prog.uniforms[137],device->glDDS7->fakex);
15471547 if(prog.uniforms[138]!= -1) glUniform1f(prog.uniforms[138],device->glDDS7->fakey);
 1548+ if(prog.uniforms[139]!= -1) glUniform1i(prog.uniforms[139],device->renderstate[D3DRENDERSTATE_ALPHAREF]);
15481549 if(device->glDDS7->zbuffer) SetFBO(device->glDDS7->texture,device->glDDS7->zbuffer->texture,device->glDDS7->zbuffer->hasstencil);
15491550 else SetFBO(device->glDDS7->texture,0,false);
15501551 SetViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
Index: ddraw/shadergen.cpp
@@ -39,7 +39,7 @@
4040 Bit 2 - Alpha test enable FS
4141 Bits 3-5 - Alpha test function: FS
4242 000=never 001=less 010=equal 011=lessequal
43 -100=greater 101=notequal 110=lessequal 111=always
 43+100=greater 101=notequal 110=greaterequal 111=always
4444 Bits 6-7 - Table fog: FS
4545 00 = none 01=exp 10=exp2 11=linear
4646 Bits 8-9 - Vertex fog: same as table VS
@@ -260,6 +260,7 @@
261261 static const char unif_tex[] = "uniform sampler2D texX;\n";
262262 static const char unif_size[] = "uniform float width;\n\
263263 uniform float height;\n";
 264+static const char unif_alpharef[] = "uniform int alpharef;\n";
264265 // Variables
265266 static const char var_common[] = "vec4 diffuse;\n\
266267 vec4 specular;\n\
@@ -632,6 +633,7 @@
633634 tmp.replace(21,1,_itoa(i,idstring,10));
634635 fsrc->append(tmp);
635636 }
 637+ if((id>>2)&1) fsrc->append(unif_alpharef);
636638 // Variables
637639 fsrc->append(var_color);
638640 // Functions
@@ -889,6 +891,36 @@
890892 break;
891893 }
892894 }
 895+ if((id>>2)&1)
 896+ {
 897+ switch((id>>3)&7)
 898+ {
 899+ case 0:
 900+ fsrc->append("discard;\n");
 901+ break;
 902+ case 1:
 903+ fsrc->append("if(int(color.a * 255.0) >= alpharef) discard;");
 904+ break;
 905+ case 2:
 906+ fsrc->append("if(int(color.a * 255.0) != alpharef) discard;");
 907+ break;
 908+ case 3:
 909+ fsrc->append("if(int(color.a * 255.0) > alpharef) discard;");
 910+ break;
 911+ case 4:
 912+ fsrc->append("if(int(color.a * 255.0) <= alpharef) discard;");
 913+ break;
 914+ case 5:
 915+ fsrc->append("if(int(color.a * 255.0) == alpharef) discard;");
 916+ break;
 917+ case 6:
 918+ fsrc->append("if(int(color.a * 255.0) < alpharef) discard;");
 919+ break;
 920+ case 7:
 921+ default:
 922+ break;
 923+ }
 924+ }
893925 fsrc->append(op_colorfragout);
894926 fsrc->append(mainend);
895927 #ifdef _DEBUG
@@ -1005,4 +1037,5 @@
10061038 genshaders[index].shader.uniforms[136] = glGetUniformLocation(genshaders[index].shader.prog,"ambientcolor");
10071039 genshaders[index].shader.uniforms[137] = glGetUniformLocation(genshaders[index].shader.prog,"width");
10081040 genshaders[index].shader.uniforms[138] = glGetUniformLocation(genshaders[index].shader.prog,"height");
 1041+ genshaders[index].shader.uniforms[139] = glGetUniformLocation(genshaders[index].shader.prog,"alpharef");
10091042 }