DXGL r481 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r480‎ | r481 | r482 >
Date:15:57, 10 August 2014
Author:admin
Status:new
Tags:
Comment:
Add destination color key support.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /dxgltest/Tests2D.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -194,6 +194,7 @@
195195 static const char op_texcoord1[] = "gl_TexCoord[1] = vec4(destst,0.0,1.0);\n";
196196 static const char op_texcoord3[] = "gl_TexCoord[3] = vec4(stencilst,0.0,1.0);\n";
197197 static const char op_ckeysrc[] = "if(pixel.rgb == ckeysrc) discard;\n";
 198+static const char op_ckeydest[] = "if(dest.rgb != ckeydest) discard;\n";
198199 static const char op_clip[] = "if(texture2D(stenciltex, gl_TexCoord[3].st).r < .5) discard;";
199200
200201 // Functions
@@ -780,6 +781,7 @@
781782 DWORD rop;
782783 tmp.ptr = NULL;
783784 BOOL intproc = FALSE;
 785+ BOOL usedest = FALSE;
784786 gen->genshaders2D[index].shader.vsrc.ptr = NULL;
785787 gen->genshaders2D[index].shader.fsrc.ptr = NULL;
786788 char idstring[22];
@@ -815,8 +817,10 @@
816818 else String_Append(vsrc, attr_srcst);
817819 if (id & DDBLT_ROP)
818820 {
819 - if (rop_texture_usage[rop] & 2) String_Append(vsrc, attr_destst);
 821+ if (rop_texture_usage[rop] & 2) usedest = TRUE;
820822 }
 823+ if (id & DDBLT_KEYDEST) usedest = TRUE;
 824+ if (usedest) String_Append(vsrc, attr_destst);
821825 if (id & 0x10000000) String_Append(vsrc, attr_stencilst);
822826
823827 // Uniforms
@@ -827,10 +831,7 @@
828832 String_Append(vsrc, op_vertex);
829833 if (id & DDBLT_COLORFILL) String_Append(vsrc, op_vertcolorrgb);
830834 else String_Append(vsrc, op_texcoord0);
831 - if (id & DDBLT_ROP)
832 - {
833 - if (rop_texture_usage[rop] & 2) String_Append(vsrc, op_texcoord1);
834 - }
 835+ if(usedest) String_Append(vsrc, op_texcoord1);
835836 if (id & 0x10000000) String_Append(vsrc, op_texcoord3);
836837 String_Append(vsrc, mainend);
837838 #ifdef _DEBUG
@@ -862,7 +863,7 @@
863864 free(infolog);
864865 }
865866 #endif
866 -
 867+ usedest = FALSE;
867868 // Create fragment shader
868869 STRING *fsrc = &gen->genshaders2D[index].shader.fsrc;
869870 String_Append(fsrc, revheader);
@@ -887,9 +888,10 @@
888889
889890 // Uniforms
890891 if (!(id & DDBLT_COLORFILL)) String_Append(fsrc, unif_srctex);
 892+ if (id & DDBLT_KEYDEST) usedest = TRUE;
891893 if (id & DDBLT_ROP)
892894 {
893 - if (rop_texture_usage[rop] & 2) String_Append(fsrc, unif_desttex);
 895+ if (rop_texture_usage[rop] & 2) usedest = TRUE;
894896 if (rop_texture_usage[rop] & 4)
895897 {
896898 String_Append(fsrc, unif_patterntex);
@@ -896,14 +898,15 @@
897899 String_Append(fsrc, unif_patternsize);
898900 }
899901 }
 902+ if (usedest) String_Append(fsrc, unif_desttex);
900903 if (id & 0x10000000) String_Append(fsrc, unif_stenciltex);
901904 if (id & DDBLT_KEYSRC) String_Append(fsrc, unif_ckeysrc);
 905+ if (id & DDBLT_KEYDEST) String_Append(fsrc, unif_ckeydest);
902906
903907 // Variables
904908 String_Append(fsrc, var_pixel);
905909 if (id & DDBLT_ROP)
906910 {
907 - if (rop_texture_usage[rop] & 2) String_Append(fsrc, var_dest);
908911 if (rop_texture_usage[rop] & 4)
909912 {
910913 String_Append(fsrc, var_pattern);
@@ -910,6 +913,7 @@
911914 String_Append(fsrc, var_patternst);
912915 }
913916 }
 917+ if (usedest) String_Append(fsrc, var_dest);
914918
915919 // Main
916920 String_Append(fsrc, mainstart);
@@ -916,10 +920,11 @@
917921 if (id & 0x10000000) String_Append(fsrc, op_clip);
918922 if (id & DDBLT_COLORFILL) String_Append(fsrc, op_color);
919923 else String_Append(fsrc, op_src);
 924+ if (usedest) String_Append(fsrc, op_dest);
920925 if (id & DDBLT_KEYSRC) String_Append(fsrc, op_ckeysrc);
 926+ if (id & DDBLT_KEYDEST) String_Append(fsrc, op_ckeydest);
921927 if (id & DDBLT_ROP)
922928 {
923 - if (rop_texture_usage[rop] & 2) String_Append(fsrc, op_dest);
924929 if (rop_texture_usage[rop] & 4) String_Append(fsrc, op_pattern);
925930 if (intproc) String_Append(fsrc, op_ROP[rop]);
926931 else String_Append(fsrc, op_ROP_float[rop]);
@@ -984,5 +989,7 @@
985990 gen->genshaders2D[index].shader.uniforms[4] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "stenciltex");
986991 gen->genshaders2D[index].shader.uniforms[5] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeysrc");
987992 gen->genshaders2D[index].shader.uniforms[6] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeydest");
988 - gen->genshaders2D[index].shader.uniforms[7] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "patternsize");
 993+ gen->genshaders2D[index].shader.uniforms[7] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeysrchigh");
 994+ gen->genshaders2D[index].shader.uniforms[8] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeydesthigh");
 995+ gen->genshaders2D[index].shader.uniforms[9] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "patternsize");
989996 }
\ No newline at end of file
Index: ddraw/glRenderer.cpp
@@ -971,6 +971,7 @@
972972 if (rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4) usepattern = TRUE;
973973 }
974974 else shaderid = dwFlags & 0xF2FAADFF;
 975+ if (dwFlags & DDBLT_KEYDEST) usedest = TRUE;
975976 if (usedest)
976977 {
977978 This->shaders->SetShader(PROG_TEXTURE, NULL, NULL, 0);
@@ -1088,8 +1089,36 @@
10891090 }
10901091 This->ext->glUniform1i(shader->shader.uniforms[1],0);
10911092 }
1092 - else if(!(dwFlags & DDBLT_COLORFILL))
 1093+ if ((dwFlags & DDBLT_KEYDEST) && (This && dest->colorkey[1].enabled))
10931094 {
 1095+ switch (This->ddInterface->GetBPP())
 1096+ {
 1097+ case 8:
 1098+ if (This->ext->glver_major >= 3) This->ext->glUniform3i(shader->shader.uniforms[6], dest->colorkey[1].key.dwColorSpaceHighValue, 0, 0);
 1099+ else This->ext->glUniform3i(shader->shader.uniforms[6], dest->colorkey[1].key.dwColorSpaceHighValue, dest->colorkey[1].key.dwColorSpaceHighValue,
 1100+ dest->colorkey[1].key.dwColorSpaceHighValue);
 1101+ break;
 1102+ case 15:
 1103+ This->ext->glUniform3i(shader->shader.uniforms[6], _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue >> 10 & 31),
 1104+ _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue >> 5 & 31),
 1105+ _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue & 31));
 1106+ break;
 1107+ case 16:
 1108+ This->ext->glUniform3i(shader->shader.uniforms[6], _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue >> 11 & 31),
 1109+ _6to8bit(dest->colorkey[1].key.dwColorSpaceHighValue >> 5 & 63),
 1110+ _5to8bit(dest->colorkey[1].key.dwColorSpaceHighValue & 31));
 1111+ break;
 1112+ case 24:
 1113+ case 32:
 1114+ default:
 1115+ This->ext->glUniform3i(shader->shader.uniforms[5], (dest->colorkey[1].key.dwColorSpaceHighValue >> 16 & 255),
 1116+ (dest->colorkey[1].key.dwColorSpaceHighValue >> 8 & 255),
 1117+ (dest->colorkey[1].key.dwColorSpaceHighValue & 255));
 1118+ break;
 1119+ }
 1120+ }
 1121+ else if (!(dwFlags & DDBLT_COLORFILL))
 1122+ {
10941123 This->ext->glUniform1i(shader->shader.uniforms[1],0);
10951124 }
10961125 if (usedest && (shader->shader.uniforms[2] != -1))
@@ -1102,7 +1131,7 @@
11031132 glDirectDrawSurface7 *pattern = (glDirectDrawSurface7*)lpDDBltFx->lpDDSPattern;
11041133 TextureManager_SetTexture(This->texman, 2, pattern->texture);
11051134 This->ext->glUniform1i(shader->shader.uniforms[3], 2);
1106 - This->ext->glUniform2i(shader->shader.uniforms[7], pattern->texture->width, pattern->texture->height);
 1135+ This->ext->glUniform2i(shader->shader.uniforms[9], pattern->texture->width, pattern->texture->height);
11071136 }
11081137 if (dwFlags & 0x10000000) // Use clipper
11091138 {
@@ -1136,7 +1165,7 @@
11371166 This->util->EnableArray(shader->shader.attribs[3],true);
11381167 This->ext->glVertexAttribPointer(shader->shader.attribs[3],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].s);
11391168 }
1140 - if ((dwFlags & DDBLT_ROP) && usedest)
 1169+ if (usedest)
11411170 {
11421171 This->util->EnableArray(shader->shader.attribs[4], true);
11431172 This->ext->glVertexAttribPointer(shader->shader.attribs[4],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].dests);
Index: dxgltest/Tests2D.cpp
@@ -617,6 +617,7 @@
618618 }
619619 else if (i < 13) sprites[i].bltflags = DDBLTFAST_DESTCOLORKEY;
620620 else sprites[i].bltflags = DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY;
 621+ ddsrender->SetColorKey(DDCKEY_DESTBLT, &ckey);
621622 sprites[i].x = randfloat((float)ddsd.dwWidth);
622623 sprites[i].y = randfloat((float)ddsd.dwHeight);
623624 sprites[i].xvelocity = randfloat(5);