DXGL r288 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r287‎ | r288 | r289 >
Date:17:12, 15 December 2012
Author:admin
Status:new
Tags:
Comment:
Add texture color keys to fragment shader code.
Modified paths:
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/shadergen.cpp
@@ -262,6 +262,7 @@
263263 static const char unif_size[] = "uniform float width;\n\
264264 uniform float height;\n";
265265 static const char unif_alpharef[] = "uniform int alpharef;\n";
 266+static const char unif_key[] = "uniform ivec4 keyX;\n";
266267 // Variables
267268 static const char var_common[] = "vec4 diffuse;\n\
268269 vec4 specular;\n\
@@ -277,7 +278,7 @@
278279 static const char op_normalpassthru[] = "N = gl_NormalMatrix*nxyz;\n";
279280 static const char op_passthru[] = "gl_Position = vec4(((xyz.x/rhw)/(width/2.0))-1.0,((xyz.y/rhw)/(height/2.0))-1.0,(xyz.z/rhw),1.0/rhw);\n";
280281 static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
281 -ambient = ambientcolor / 255.5;\n";
 282+ambient = ambientcolor / 255.0;\n";
282283 static const char op_dirlight[] = "DirLight(lightX);\n";
283284 static const char op_pointlight[] = "PointLight(lightX);\n";
284285 static const char op_spotlight[] = "SpotLight(lightX);\n";
@@ -289,6 +290,7 @@
290291 static const char op_colorwhite[] = "gl_FrontColor = vec4(1.0,1.0,1.0,1.0);\n";
291292 static const char op_colorfragout[] = "gl_FragColor = color;\n";
292293 static const char op_colorfragin[] = "color = gl_Color;\n";
 294+static const char op_colorkey[] = "if(ivec4(texture2DProj(texX,gl_TexCoord[Y])*255.5) == keyZ) discard;\n";
293295 static const char op_texpassthru1[] = "gl_TexCoord[x] = ";
294296 static const char op_texpassthru2s[] = "vec4(sX,0,0,1);\n";
295297 static const char op_texpassthru2st[] = "vec4(stX,0,1);\n";
@@ -648,12 +650,29 @@
649651 bool alphadisabled = false;
650652 const string blendargs[] = {"color","gl_Color","texture2DProj(texX,gl_TexCoord[Y])",
651653 "","texfactor","gl_SecondaryColor","vec3(1,1,1)","1",".rgb",".a",".aaa"};
 654+ bool usecolorkey = false;
 655+ if((id>>13)&1) usecolorkey = true;
652656 for(i = 0; i < 8; i++)
653657 {
654658 if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
 659+ args[0] = (texstate[i].shaderid>>5)&63;
 660+ args[1] = (texstate[i].shaderid>>11)&63;
 661+ args[2] = (texstate[i].shaderid>>22)&63;
 662+ args[3] = (texstate[i].shaderid>>28)&63;
 663+ // Color key
 664+ if(usecolorkey)
 665+ {
 666+ if((texstate[i].shaderid>>60)&1)
 667+ {
 668+ arg1.assign(op_colorkey);
 669+ arg1.replace(26,1,_itoa(i,idstring,10));
 670+ arg1.replace(40,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 671+ arg1.replace(57,1,_itoa(i,idstring,10));
 672+ fsrc->append(arg1);
 673+ }
 674+ }
655675 // Color stage
656676 texfail = false;
657 - args[0] = (texstate[i].shaderid>>5)&63;
658677 switch(args[0]&7) //arg1
659678 {
660679 case D3DTA_CURRENT:
@@ -683,7 +702,6 @@
684703 if(args[0] & D3DTA_COMPLEMENT) arg1 = "(1.0 - " + arg1 + ")";
685704 if(args[0] & D3DTA_ALPHAREPLICATE) arg1.append(blendargs[10]);
686705 else arg1.append(blendargs[8]);
687 - args[1] = (texstate[i].shaderid>>11)&63;
688706 switch(args[1]&7) //arg2
689707 {
690708 case D3DTA_CURRENT:
@@ -775,7 +793,6 @@
776794 if(alphadisabled) continue;
777795 // Alpha stage
778796 texfail = false;
779 - args[2] = (texstate[i].shaderid>>22)&63;
780797 switch(args[2]&7) //arg1
781798 {
782799 case D3DTA_CURRENT:
@@ -804,7 +821,6 @@
805822 }
806823 if(args[2] & D3DTA_COMPLEMENT)
807824 arg1 = "(1.0 - " + arg1 + ")";
808 - args[3] = (texstate[i].shaderid>>28)&63;
809825 switch(args[3]&7) //arg2
810826 {
811827 case D3DTA_CURRENT:
@@ -1039,4 +1055,10 @@
10401056 genshaders[index].shader.uniforms[137] = glGetUniformLocation(genshaders[index].shader.prog,"width");
10411057 genshaders[index].shader.uniforms[138] = glGetUniformLocation(genshaders[index].shader.prog,"height");
10421058 genshaders[index].shader.uniforms[139] = glGetUniformLocation(genshaders[index].shader.prog,"alpharef");
 1059+ char unifkey[] = "keyX";
 1060+ for(int i = 0; i < 8; i++)
 1061+ {
 1062+ unifkey[3] = i + '0';
 1063+ genshaders[index].shader.uniforms[128+i] = glGetUniformLocation(genshaders[index].shader.prog,unifkey);
 1064+ }
10431065 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r290Fix multi-texture regression in r288admin19:14, 16 December 2012