Index: ddraw/ShaderGen2D.cpp |
— | — | @@ -194,6 +194,7 @@ |
195 | 195 | static const char op_texcoord1[] = "gl_TexCoord[1] = vec4(destst,0.0,1.0);\n";
|
196 | 196 | static const char op_texcoord3[] = "gl_TexCoord[3] = vec4(stencilst,0.0,1.0);\n";
|
197 | 197 | static const char op_ckeysrc[] = "if(pixel.rgb == ckeysrc) discard;\n";
|
| 198 | +static const char op_ckeydest[] = "if(dest.rgb != ckeydest) discard;\n";
|
198 | 199 | static const char op_clip[] = "if(texture2D(stenciltex, gl_TexCoord[3].st).r < .5) discard;";
|
199 | 200 |
|
200 | 201 | // Functions
|
— | — | @@ -780,6 +781,7 @@ |
781 | 782 | DWORD rop;
|
782 | 783 | tmp.ptr = NULL;
|
783 | 784 | BOOL intproc = FALSE;
|
| 785 | + BOOL usedest = FALSE;
|
784 | 786 | gen->genshaders2D[index].shader.vsrc.ptr = NULL;
|
785 | 787 | gen->genshaders2D[index].shader.fsrc.ptr = NULL;
|
786 | 788 | char idstring[22];
|
— | — | @@ -815,8 +817,10 @@ |
816 | 818 | else String_Append(vsrc, attr_srcst);
|
817 | 819 | if (id & DDBLT_ROP)
|
818 | 820 | {
|
819 | | - if (rop_texture_usage[rop] & 2) String_Append(vsrc, attr_destst);
|
| 821 | + if (rop_texture_usage[rop] & 2) usedest = TRUE;
|
820 | 822 | }
|
| 823 | + if (id & DDBLT_KEYDEST) usedest = TRUE;
|
| 824 | + if (usedest) String_Append(vsrc, attr_destst);
|
821 | 825 | if (id & 0x10000000) String_Append(vsrc, attr_stencilst);
|
822 | 826 |
|
823 | 827 | // Uniforms
|
— | — | @@ -827,10 +831,7 @@ |
828 | 832 | String_Append(vsrc, op_vertex);
|
829 | 833 | if (id & DDBLT_COLORFILL) String_Append(vsrc, op_vertcolorrgb);
|
830 | 834 | 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);
|
835 | 836 | if (id & 0x10000000) String_Append(vsrc, op_texcoord3);
|
836 | 837 | String_Append(vsrc, mainend);
|
837 | 838 | #ifdef _DEBUG
|
— | — | @@ -862,7 +863,7 @@ |
863 | 864 | free(infolog);
|
864 | 865 | }
|
865 | 866 | #endif
|
866 | | -
|
| 867 | + usedest = FALSE;
|
867 | 868 | // Create fragment shader
|
868 | 869 | STRING *fsrc = &gen->genshaders2D[index].shader.fsrc;
|
869 | 870 | String_Append(fsrc, revheader);
|
— | — | @@ -887,9 +888,10 @@ |
888 | 889 |
|
889 | 890 | // Uniforms
|
890 | 891 | if (!(id & DDBLT_COLORFILL)) String_Append(fsrc, unif_srctex);
|
| 892 | + if (id & DDBLT_KEYDEST) usedest = TRUE;
|
891 | 893 | if (id & DDBLT_ROP)
|
892 | 894 | {
|
893 | | - if (rop_texture_usage[rop] & 2) String_Append(fsrc, unif_desttex);
|
| 895 | + if (rop_texture_usage[rop] & 2) usedest = TRUE;
|
894 | 896 | if (rop_texture_usage[rop] & 4)
|
895 | 897 | {
|
896 | 898 | String_Append(fsrc, unif_patterntex);
|
— | — | @@ -896,14 +898,15 @@ |
897 | 899 | String_Append(fsrc, unif_patternsize);
|
898 | 900 | }
|
899 | 901 | }
|
| 902 | + if (usedest) String_Append(fsrc, unif_desttex);
|
900 | 903 | if (id & 0x10000000) String_Append(fsrc, unif_stenciltex);
|
901 | 904 | if (id & DDBLT_KEYSRC) String_Append(fsrc, unif_ckeysrc);
|
| 905 | + if (id & DDBLT_KEYDEST) String_Append(fsrc, unif_ckeydest);
|
902 | 906 |
|
903 | 907 | // Variables
|
904 | 908 | String_Append(fsrc, var_pixel);
|
905 | 909 | if (id & DDBLT_ROP)
|
906 | 910 | {
|
907 | | - if (rop_texture_usage[rop] & 2) String_Append(fsrc, var_dest);
|
908 | 911 | if (rop_texture_usage[rop] & 4)
|
909 | 912 | {
|
910 | 913 | String_Append(fsrc, var_pattern);
|
— | — | @@ -910,6 +913,7 @@ |
911 | 914 | String_Append(fsrc, var_patternst);
|
912 | 915 | }
|
913 | 916 | }
|
| 917 | + if (usedest) String_Append(fsrc, var_dest);
|
914 | 918 |
|
915 | 919 | // Main
|
916 | 920 | String_Append(fsrc, mainstart);
|
— | — | @@ -916,10 +920,11 @@ |
917 | 921 | if (id & 0x10000000) String_Append(fsrc, op_clip);
|
918 | 922 | if (id & DDBLT_COLORFILL) String_Append(fsrc, op_color);
|
919 | 923 | else String_Append(fsrc, op_src);
|
| 924 | + if (usedest) String_Append(fsrc, op_dest);
|
920 | 925 | if (id & DDBLT_KEYSRC) String_Append(fsrc, op_ckeysrc);
|
| 926 | + if (id & DDBLT_KEYDEST) String_Append(fsrc, op_ckeydest);
|
921 | 927 | if (id & DDBLT_ROP)
|
922 | 928 | {
|
923 | | - if (rop_texture_usage[rop] & 2) String_Append(fsrc, op_dest);
|
924 | 929 | if (rop_texture_usage[rop] & 4) String_Append(fsrc, op_pattern);
|
925 | 930 | if (intproc) String_Append(fsrc, op_ROP[rop]);
|
926 | 931 | else String_Append(fsrc, op_ROP_float[rop]);
|
— | — | @@ -984,5 +989,7 @@ |
985 | 990 | gen->genshaders2D[index].shader.uniforms[4] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "stenciltex");
|
986 | 991 | gen->genshaders2D[index].shader.uniforms[5] = gen->ext->glGetUniformLocation(gen->genshaders2D[index].shader.prog, "ckeysrc");
|
987 | 992 | 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");
|
989 | 996 | } |
\ No newline at end of file |
Index: ddraw/glRenderer.cpp |
— | — | @@ -971,6 +971,7 @@ |
972 | 972 | if (rop_texture_usage[(lpDDBltFx->dwROP >> 16) & 0xFF] & 4) usepattern = TRUE;
|
973 | 973 | }
|
974 | 974 | else shaderid = dwFlags & 0xF2FAADFF;
|
| 975 | + if (dwFlags & DDBLT_KEYDEST) usedest = TRUE;
|
975 | 976 | if (usedest)
|
976 | 977 | {
|
977 | 978 | This->shaders->SetShader(PROG_TEXTURE, NULL, NULL, 0);
|
— | — | @@ -1088,8 +1089,36 @@ |
1089 | 1090 | }
|
1090 | 1091 | This->ext->glUniform1i(shader->shader.uniforms[1],0);
|
1091 | 1092 | }
|
1092 | | - else if(!(dwFlags & DDBLT_COLORFILL))
|
| 1093 | + if ((dwFlags & DDBLT_KEYDEST) && (This && dest->colorkey[1].enabled))
|
1093 | 1094 | {
|
| 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 | + {
|
1094 | 1123 | This->ext->glUniform1i(shader->shader.uniforms[1],0);
|
1095 | 1124 | }
|
1096 | 1125 | if (usedest && (shader->shader.uniforms[2] != -1))
|
— | — | @@ -1102,7 +1131,7 @@ |
1103 | 1132 | glDirectDrawSurface7 *pattern = (glDirectDrawSurface7*)lpDDBltFx->lpDDSPattern;
|
1104 | 1133 | TextureManager_SetTexture(This->texman, 2, pattern->texture);
|
1105 | 1134 | 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);
|
1107 | 1136 | }
|
1108 | 1137 | if (dwFlags & 0x10000000) // Use clipper
|
1109 | 1138 | {
|
— | — | @@ -1136,7 +1165,7 @@ |
1137 | 1166 | This->util->EnableArray(shader->shader.attribs[3],true);
|
1138 | 1167 | This->ext->glVertexAttribPointer(shader->shader.attribs[3],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].s);
|
1139 | 1168 | }
|
1140 | | - if ((dwFlags & DDBLT_ROP) && usedest)
|
| 1169 | + if (usedest)
|
1141 | 1170 | {
|
1142 | 1171 | This->util->EnableArray(shader->shader.attribs[4], true);
|
1143 | 1172 | 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 @@ |
618 | 618 | }
|
619 | 619 | else if (i < 13) sprites[i].bltflags = DDBLTFAST_DESTCOLORKEY;
|
620 | 620 | else sprites[i].bltflags = DDBLTFAST_SRCCOLORKEY | DDBLTFAST_DESTCOLORKEY;
|
| 621 | + ddsrender->SetColorKey(DDCKEY_DESTBLT, &ckey);
|
621 | 622 | sprites[i].x = randfloat((float)ddsd.dwWidth);
|
622 | 623 | sprites[i].y = randfloat((float)ddsd.dwHeight);
|
623 | 624 | sprites[i].xvelocity = randfloat(5);
|