DXGL r487 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r486‎ | r487 | r488 >
Date:23:50, 15 August 2014
Author:admin
Status:new
Tags:
Comment:
Fix sampling of source color for color keys.
Add colorspace color key for source and destination Blt.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -51,8 +51,8 @@
5252 Bit 26: ROP index bit 6
5353 Bit 27: ROP index bit 7
5454 Bit 28: (DXGL) Use Clipper
55 -Bit 29: reserved for DXGL usage
56 -Bit 30: reserved for DXGL usage
 55+Bit 29: (DXGL) Source color key range
 56+Bit 30: (DXGL) Dest. color key range
5757 Bit 31: reserved for DXGL usage
5858 AND the dwFlags by 0xF2FAADFF before packing ROP index bits
5959 */
@@ -164,6 +164,8 @@
165165 static const char unif_stenciltex[] = "uniform sampler2D stenciltex;\n";
166166 static const char unif_ckeysrc[] = "uniform ivec3 ckeysrc;\n";
167167 static const char unif_ckeydest[] = "uniform ivec3 ckeydest;\n";
 168+static const char unif_ckeysrchigh[] = "uniform ivec3 ckeysrchigh;\n";
 169+static const char unif_ckeydesthigh[] = "uniform ivec3 ckeydesthigh;\n";
168170 static const char unif_patternsize[] = "uniform ivec2 patternsize;\n";
169171 static const char unif_colorsizesrc[] = "uniform ivec4 colorsizesrc;\n";
170172 static const char unif_colorsizedest[] = "uniform ivec4 colorsizedest;\n";
@@ -197,9 +199,13 @@
198200 static const char op_texcoord0[] = "gl_TexCoord[0] = vec4(srcst,0.0,1.0);\n";
199201 static const char op_texcoord1[] = "gl_TexCoord[1] = vec4(destst,0.0,1.0);\n";
200202 static const char op_texcoord3[] = "gl_TexCoord[3] = vec4(stencilst,0.0,1.0);\n";
201 -static const char op_ckeysrc[] = "if(pixel.rgb == ckeysrc) discard;\n";
 203+static const char op_ckeysrc[] = "if(src.rgb == ckeysrc) discard;\n";
202204 static const char op_ckeydest[] = "if(dest.rgb != ckeydest) discard;\n";
203 -static const char op_clip[] = "if(texture2D(stenciltex, gl_TexCoord[3].st).r < .5) discard;";
 205+static const char op_ckeysrcrange[] = "if(!((src.r < ckeysrc.r) || (src.g < ckeysrc.g) || (src.b < ckeysrc.b) ||\
 206+ (src.r > ckeysrchigh.r) || (src.g > ckeysrchigh.g) || (src.b > ckeysrchigh.b))) discard;\n";
 207+static const char op_ckeydestrange[] = "if((dest.r < ckeydest.r) || (dest.g < ckeydest.g) || (dest.b < ckeydest.b) ||\
 208+ (dest.r > ckeydesthigh.r) || (dest.g > ckeydesthigh.g) || (dest.b > ckeydesthigh.b)) discard;\n";
 209+static const char op_clip[] = "if(texture2D(stenciltex, gl_TexCoord[3].st).r < .5) discard;\n";
204210
205211 // Functions
206212
@@ -906,10 +912,15 @@
907913 if (id & DDBLT_KEYSRC)
908914 {
909915 String_Append(fsrc, unif_ckeysrc);
 916+ if (id & 0x20000000) String_Append(fsrc, unif_ckeysrchigh);
910917 String_Append(fsrc, unif_colorsizesrc);
911918 }
912919 String_Append(fsrc, unif_colorsizedest);
913 - if (id & DDBLT_KEYDEST) String_Append(fsrc, unif_ckeydest);
 920+ if (id & DDBLT_KEYDEST)
 921+ {
 922+ String_Append(fsrc, unif_ckeydest);
 923+ if (id & 0x40000000) String_Append(fsrc, unif_ckeydesthigh);
 924+ }
914925
915926 // Variables
916927 String_Append(fsrc, var_pixel);
@@ -931,8 +942,16 @@
932943 else String_Append(fsrc, op_pixel);
933944 if (id & DDBLT_KEYSRC) String_Append(fsrc, op_src);
934945 if (usedest) String_Append(fsrc, op_dest);
935 - if (id & DDBLT_KEYSRC) String_Append(fsrc, op_ckeysrc);
936 - if (id & DDBLT_KEYDEST) String_Append(fsrc, op_ckeydest);
 946+ if (id & DDBLT_KEYSRC)
 947+ {
 948+ if (id & 0x20000000) String_Append(fsrc, op_ckeysrcrange);
 949+ else String_Append(fsrc, op_ckeysrc);
 950+ }
 951+ if (id & DDBLT_KEYDEST)
 952+ {
 953+ if (id & 0x40000000) String_Append(fsrc, op_ckeydestrange);
 954+ else String_Append(fsrc, op_ckeydest);
 955+ }
937956 if (id & DDBLT_ROP)
938957 {
939958 if (rop_texture_usage[rop] & 4) String_Append(fsrc, op_pattern);
Index: ddraw/glDirectDrawSurface.cpp
@@ -613,6 +613,7 @@
614614 TRACE_ENTER(6,14,this,26,lpDestRect,14,lpDDSrcSurface,26,lpSrcRect,9,dwFlags,14,lpDDBltFx);
615615 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
616616 if((dwFlags & DDBLT_COLORFILL) && !lpDDBltFx) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 617+ if((dwFlags & DDBLT_DDFX) && !lpDDBltFx) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
617618 if (dwFlags & DDBLT_ROP)
618619 {
619620 if (!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
@@ -627,6 +628,12 @@
628629 pattern->ddsd.ddpfPixelFormat.dwRGBBitCount);
629630 }
630631 }
 632+ if (dwFlags & DDBLT_KEYSRC)
 633+ {
 634+ if (!lpDDSrcSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 635+ if (((glDirectDrawSurface7*)lpDDSrcSurface)->colorkey[0].colorspace) dwFlags |= 0x20000000;
 636+ }
 637+ if ((dwFlags & DDBLT_KEYDEST) && colorkey[1].colorspace) dwFlags |= 0x40000000;
631638 glDirectDrawSurface7 *src = (glDirectDrawSurface7 *)lpDDSrcSurface;
632639 if(dirty & 1)
633640 {
Index: ddraw/glRenderer.cpp
@@ -1191,12 +1191,20 @@
11921192 if (dwFlags & DDBLT_COLORFILL) SetColorFillUniform(lpDDBltFx->dwFillColor, dest->texture->colorsizes,
11931193 dest->texture->colororder, dest->texture->colorbits, shader->shader.uniforms[12], This->ext);
11941194 if ((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
 1195+ {
11951196 SetColorKeyUniform(src->colorkey[0].key.dwColorSpaceLowValue, src->texture->colorsizes,
1196 - src->texture->colororder, shader->shader.uniforms[5], src->texture->colorbits, This->ext);
 1197+ src->texture->colororder, shader->shader.uniforms[5], src->texture->colorbits, This->ext);
 1198+ if (dwFlags & 0x20000000) SetColorKeyUniform(src->colorkey[0].key.dwColorSpaceHighValue, src->texture->colorsizes,
 1199+ src->texture->colororder, shader->shader.uniforms[7], src->texture->colorbits, This->ext);
 1200+ }
11971201 if (!(dwFlags & DDBLT_COLORFILL)) This->ext->glUniform1i(shader->shader.uniforms[1], 0);
11981202 if ((dwFlags & DDBLT_KEYDEST) && (This && dest->colorkey[1].enabled))
 1203+ {
11991204 SetColorKeyUniform(dest->colorkey[1].key.dwColorSpaceLowValue, dest->texture->colorsizes,
1200 - dest->texture->colororder, shader->shader.uniforms[6], dest->texture->colorbits, This->ext);
 1205+ dest->texture->colororder, shader->shader.uniforms[6], dest->texture->colorbits, This->ext);
 1206+ if(dwFlags & 0x40000000) SetColorKeyUniform(dest->colorkey[1].key.dwColorSpaceHighValue, dest->texture->colorsizes,
 1207+ dest->texture->colororder, shader->shader.uniforms[8], dest->texture->colorbits, This->ext);
 1208+ }
12011209 if (usedest && (shader->shader.uniforms[2] != -1))
12021210 {
12031211 TextureManager_SetTexture(This->texman, 1, This->backbuffer);