DXGL r584 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r583‎ | r584 | r585 >
Date:01:27, 15 January 2015
Author:admin
Status:new
Tags:
Comment:
Fix Direct3D color keying to take into account surface pixel format.
Update some copyright dates.
Modified paths:
  • /ddraw/ShaderGen3D.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen3D.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2014 William Feely
 3+// Copyright (C) 2012-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -320,6 +320,7 @@
321321 uniform float maxz;\n";
322322 static const char unif_alpharef[] = "uniform int alpharef;\n";
323323 static const char unif_key[] = "uniform ivec3 keyX;\n";
 324+static const char unif_keybits[] = "uniform ivec4 keybitsX;\n";
324325 static const char unif_world[] = "uniform mat4 matWorld;\n";
325326 static const char unif_ditherbits[] = "uniform ivec4 ditherbits;\n";
326327 // Variables
@@ -331,6 +332,7 @@
332333 static const char var_xyzw[] = "vec4 xyzw;\n";
333334 static const char var_fogfactorvertex[] = "varying float fogfactor;\n";
334335 static const char var_fogfactorpixel[] = "float fogfactor;\n";
 336+static const char var_keycomp[] = "ivec4 keycomp;\n";
335337 // Constants
336338 static const char const_nxyz[] = "const vec3 nxyz = vec3(0,0,0);\n";
337339 static const char const_threshold[] = "mat4 threshold = mat4(\n\
@@ -361,7 +363,8 @@
362364 static const char op_colorfragout[] = "gl_FragColor = color;\n";
363365 static const char op_dither[] = "color = dither(color);\n";
364366 static const char op_colorfragin[] = "color = gl_Color;\n";
365 -static const char op_colorkey[] = "if(ivec3(texture2DProj(texX,gl_TexCoord[Y])*255.5).rgb == keyZ) discard;\n";
 367+static const char op_colorkeyin[] = "keycomp = ivec4(texture2DProj(texX,gl_TexCoord[Y])*vec4(keybitsZ)+.5);\n";
 368+static const char op_colorkey[] = "if(keycomp.rgb == keyX) discard;\n";
366369 static const char op_texpassthru1[] = "gl_TexCoord[x] = ";
367370 static const char op_texpassthru2s[] = "vec4(sX,0,0,1);\n";
368371 static const char op_texpassthru2st[] = "vec4(stX,0,1);\n";
@@ -491,6 +494,7 @@
492495 bool haspoint = false;
493496 bool hasspot = false;
494497 bool dither = false;
 498+ BOOL haskey = FALSE;
495499 int count;
496500 int numlights;
497501 int vertexfog,pixelfog;
@@ -795,6 +799,10 @@
796800 String_Assign(&tmp, unif_key);
797801 tmp.ptr[17] = *(_itoa(i,idstring,10));
798802 String_Append(fsrc, tmp.ptr);
 803+ String_Assign(&tmp, unif_keybits);
 804+ tmp.ptr[21] = *(_itoa(i, idstring, 10));
 805+ String_Append(fsrc, tmp.ptr);
 806+ haskey = TRUE;
799807 }
800808 }
801809 }
@@ -805,6 +813,7 @@
806814 if(vertexfog && !pixelfog) String_Append(fsrc, var_fogfactorvertex);
807815 if(pixelfog) String_Append(fsrc, var_fogfactorpixel);
808816 if (dither) String_Append(fsrc, const_threshold);
 817+ if (haskey) String_Append(fsrc, var_keycomp);
809818 // Functions
810819 if (dither) String_Append(fsrc, func_dither);
811820 // Main
@@ -834,10 +843,13 @@
835844 {
836845 if((texstate[i].shaderid>>60)&1)
837846 {
 847+ String_Assign(&arg1, op_colorkeyin);
 848+ arg1.ptr[33] = *(_itoa(i, idstring, 10));
 849+ arg1.ptr[47] = *(_itoa((texstate[i].shaderid >> 54) & 7, idstring, 10));
 850+ arg1.ptr[63] = *(_itoa(i, idstring, 10));
 851+ String_Append(fsrc, arg1.ptr);
838852 String_Assign(&arg1, op_colorkey);
839 - arg1.ptr[26] = *(_itoa(i,idstring,10));
840 - arg1.ptr[40] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
841 - arg1.ptr[61] = *(_itoa(i,idstring,10));
 853+ arg1.ptr[21] = *(_itoa(i,idstring,10));
842854 String_Append(fsrc, arg1.ptr);
843855 }
844856 }
@@ -1434,7 +1446,13 @@
14351447 }
14361448 This->genshaders[index].shader.uniforms[150] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog,"ditherbits");
14371449 This->genshaders[index].shader.uniforms[151] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, "minz");
1438 - This->genshaders[index].shader.uniforms[151] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, "maxz");
 1450+ This->genshaders[index].shader.uniforms[152] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, "maxz");
 1451+ char unifkeybits[] = "keybitsX";
 1452+ for (int i = 0; i < 8; i++)
 1453+ {
 1454+ unifkeybits[7] = i + '0';
 1455+ This->genshaders[index].shader.uniforms[153 + i] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, unifkeybits);
 1456+ }
14391457 }
14401458
14411459 }
\ No newline at end of file
Index: ddraw/glDirect3DDevice.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/glDirect3DDevice.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/glDirectDrawSurface.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2014 William Feely
 3+// Copyright (C) 2011-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/glRenderer.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012-2014 William Feely
 3+// Copyright (C) 2012-2015 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -1995,8 +1995,13 @@
19961996 {
19971997 if(device->texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT)
19981998 {
1999 - dwordto4int(device->texstages[i].texture->colorkey[0].key.dwColorSpaceLowValue,keycolor);
2000 - This->ext->glUniform3iv(prog.uniforms[142+i],1,keycolor);
 1999+ SetColorKeyUniform(device->texstages[i].texture->colorkey[0].key.dwColorSpaceLowValue,
 2000+ device->texstages[i].texture->texture->colorsizes, device->texstages[i].texture->texture->colororder,
 2001+ prog.uniforms[142 + i], device->texstages[i].texture->texture->colorbits, This->ext);
 2002+ This->ext->glUniform4i(prog.uniforms[153+i], device->texstages[i].texture->texture->colorsizes[0],
 2003+ device->texstages[i].texture->texture->colorsizes[1],
 2004+ device->texstages[i].texture->texture->colorsizes[2],
 2005+ device->texstages[i].texture->texture->colorsizes[3]);
20012006 }
20022007 }
20032008 }