DXGL r741 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r740‎ | r741 | r742 >
Date:07:27, 4 September 2017
Author:admin
Status:new
Tags:
Comment:
Implement color key override, both source and destination.
Make 8-bit test pattern more contrasting.
Modified paths:
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/struct.h (modified) (history)
  • /dxgltest/surfacegen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirectDrawSurface.cpp
@@ -699,12 +699,12 @@
700700 if (dwFlags & DDBLT_KEYSRCOVERRIDE)
701701 {
702702 if(!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
703 - if(dwFlags) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 703+ if(dwFlags & DDBLT_KEYSRC) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
704704 }
705705 if (dwFlags & DDBLT_KEYDESTOVERRIDE)
706706 {
707707 if (!lpDDBltFx) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
708 - if (dwFlags) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 708+ if (dwFlags & DDBLT_KEYDEST) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
709709 }
710710 if (dwFlags & DDBLT_KEYSRC)
711711 {
@@ -714,15 +714,27 @@
715715 if (((glDirectDrawSurface7*)lpDDSrcSurface)->ddsd.ddckCKSrcBlt.dwColorSpaceHighValue !=
716716 ((glDirectDrawSurface7*)lpDDSrcSurface)->ddsd.ddckCKSrcBlt.dwColorSpaceLowValue)
717717 cmd.flags |= 0x20000000;
718 - if(dwFlags & DDBLT_KEYSRCOVERRIDE) cmd.flags |= 0x20000000;
719718 }
 719+ if (dwFlags & DDBLT_KEYSRCOVERRIDE)
 720+ {
 721+ if (lpDDBltFx->ddckSrcColorkey.dwColorSpaceHighValue !=
 722+ lpDDBltFx->ddckSrcColorkey.dwColorSpaceLowValue) cmd.flags |= 0x20000000;
 723+ cmd.flags |= DDBLT_KEYSRC;
 724+ memcpy(&cmd.srckey, &lpDDBltFx->ddckSrcColorkey, sizeof(DDCOLORKEY));
 725+ }
720726 if (dwFlags & DDBLT_KEYDEST)
721727 {
722728 if (!(this->ddsd.dwFlags & DDSD_CKDESTBLT)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
723729 if (this->ddsd.ddckCKDestBlt.dwColorSpaceHighValue != this->ddsd.ddckCKDestBlt.dwColorSpaceLowValue)
724730 cmd.flags |= 0x40000000;
725 - if(dwFlags & DDBLT_KEYDESTOVERRIDE) cmd.flags |= 0x40000000;
726731 }
 732+ if (dwFlags & DDBLT_KEYDESTOVERRIDE)
 733+ {
 734+ if (lpDDBltFx->ddckDestColorkey.dwColorSpaceHighValue !=
 735+ lpDDBltFx->ddckDestColorkey.dwColorSpaceLowValue) cmd.flags |= 0x40000000;
 736+ cmd.flags |= DDBLT_KEYDEST;
 737+ memcpy(&cmd.destkey, &lpDDBltFx->ddckDestColorkey, sizeof(DDCOLORKEY));
 738+ }
727739 glDirectDrawSurface7 *src = (glDirectDrawSurface7 *)lpDDSrcSurface;
728740 if (clipper)
729741 {
Index: ddraw/glRenderer.cpp
@@ -3125,20 +3125,42 @@
31263126 if (cmd->dest->levels[cmd->destlevel].fbo.fbz) glClear(GL_DEPTH_BUFFER_BIT);
31273127 if (cmd->flags & DDBLT_COLORFILL) SetColorFillUniform(cmd->bltfx.dwFillColor, cmd->dest->colorsizes,
31283128 cmd->dest->colororder, cmd->dest->colorbits, shader->shader.uniforms[12], This->ext);
3129 - if ((cmd->flags & DDBLT_KEYSRC) && (cmd->src && (cmd->src->levels[cmd->srclevel].ddsd.dwFlags & DDSD_CKSRCBLT)) && !(cmd->flags & DDBLT_COLORFILL))
 3129+ if ((cmd->flags & DDBLT_KEYSRC) && (cmd->src && ((cmd->src->levels[cmd->srclevel].ddsd.dwFlags & DDSD_CKSRCBLT))
 3130+ || (cmd->flags & DDBLT_KEYSRCOVERRIDE)) && !(cmd->flags & DDBLT_COLORFILL))
31303131 {
3131 - SetColorKeyUniform(cmd->src->levels[cmd->srclevel].ddsd.ddckCKSrcBlt.dwColorSpaceLowValue, cmd->src->colorsizes,
3132 - cmd->src->colororder, shader->shader.uniforms[5], cmd->src->colorbits, This->ext);
3133 - if (cmd->flags & 0x20000000) SetColorKeyUniform(cmd->src->levels[cmd->srclevel].ddsd.ddckCKSrcBlt.dwColorSpaceHighValue, cmd->src->colorsizes,
3134 - cmd->src->colororder, shader->shader.uniforms[7], cmd->src->colorbits, This->ext);
 3132+ if (cmd->flags & DDBLT_KEYSRCOVERRIDE)
 3133+ {
 3134+ SetColorKeyUniform(cmd->bltfx.ddckSrcColorkey.dwColorSpaceLowValue, cmd->src->colorsizes,
 3135+ cmd->src->colororder, shader->shader.uniforms[5], cmd->src->colorbits, This->ext);
 3136+ if (cmd->flags & 0x20000000) SetColorKeyUniform(cmd->bltfx.ddckSrcColorkey.dwColorSpaceHighValue, cmd->src->colorsizes,
 3137+ cmd->src->colororder, shader->shader.uniforms[7], cmd->src->colorbits, This->ext);
 3138+ }
 3139+ else
 3140+ {
 3141+ SetColorKeyUniform(cmd->src->levels[cmd->srclevel].ddsd.ddckCKSrcBlt.dwColorSpaceLowValue, cmd->src->colorsizes,
 3142+ cmd->src->colororder, shader->shader.uniforms[5], cmd->src->colorbits, This->ext);
 3143+ if (cmd->flags & 0x20000000) SetColorKeyUniform(cmd->src->levels[cmd->srclevel].ddsd.ddckCKSrcBlt.dwColorSpaceHighValue, cmd->src->colorsizes,
 3144+ cmd->src->colororder, shader->shader.uniforms[7], cmd->src->colorbits, This->ext);
 3145+ }
31353146 }
31363147 if (!(cmd->flags & DDBLT_COLORFILL)) This->ext->glUniform1i(shader->shader.uniforms[1], 8);
3137 - if ((cmd->flags & DDBLT_KEYDEST) && (This && (cmd->dest->levels[cmd->destlevel].ddsd.dwFlags & DDSD_CKDESTBLT)))
 3148+ if ((cmd->flags & DDBLT_KEYDEST) && (This && ((cmd->dest->levels[cmd->destlevel].ddsd.dwFlags & DDSD_CKDESTBLT)
 3149+ || (cmd->flags & DDBLT_KEYDESTOVERRIDE))))
31383150 {
3139 - SetColorKeyUniform(cmd->dest->levels[cmd->destlevel].ddsd.ddckCKDestBlt.dwColorSpaceLowValue, cmd->dest->colorsizes,
3140 - cmd->dest->colororder, shader->shader.uniforms[6], cmd->dest->colorbits, This->ext);
3141 - if (cmd->flags & 0x40000000) SetColorKeyUniform(cmd->dest->levels[cmd->destlevel].ddsd.ddckCKDestBlt.dwColorSpaceHighValue, cmd->dest->colorsizes,
3142 - cmd->dest->colororder, shader->shader.uniforms[8], cmd->dest->colorbits, This->ext);
 3151+ if (cmd->flags & DDBLT_KEYDESTOVERRIDE)
 3152+ {
 3153+ SetColorKeyUniform(cmd->bltfx.ddckDestColorkey.dwColorSpaceLowValue, cmd->dest->colorsizes,
 3154+ cmd->dest->colororder, shader->shader.uniforms[6], cmd->dest->colorbits, This->ext);
 3155+ if (cmd->flags & 0x40000000) SetColorKeyUniform(cmd->bltfx.ddckDestColorkey.dwColorSpaceHighValue, cmd->dest->colorsizes,
 3156+ cmd->dest->colororder, shader->shader.uniforms[8], cmd->dest->colorbits, This->ext);
 3157+ }
 3158+ else
 3159+ {
 3160+ SetColorKeyUniform(cmd->dest->levels[cmd->destlevel].ddsd.ddckCKDestBlt.dwColorSpaceLowValue, cmd->dest->colorsizes,
 3161+ cmd->dest->colororder, shader->shader.uniforms[6], cmd->dest->colorbits, This->ext);
 3162+ if (cmd->flags & 0x40000000) SetColorKeyUniform(cmd->dest->levels[cmd->destlevel].ddsd.ddckCKDestBlt.dwColorSpaceHighValue, cmd->dest->colorsizes,
 3163+ cmd->dest->colororder, shader->shader.uniforms[8], cmd->dest->colorbits, This->ext);
 3164+ }
31433165 }
31443166 if (usedest && (shader->shader.uniforms[2] != -1))
31453167 {
Index: ddraw/struct.h
@@ -385,6 +385,8 @@
386386 GLint alphadestlevel;
387387 GLint alphasrclevel;
388388 GLint patternlevel;
 389+ DDCOLORKEY srckey;
 390+ DDCOLORKEY destkey;
389391 }BltCommand;
390392
391393 typedef struct ClearCommand
Index: dxgltest/surfacegen.cpp
@@ -1456,7 +1456,7 @@
14571457 {
14581458 for (int x = 0; x < 16; x++)
14591459 {
1460 - i = ((x + ((15 - y) << 4)) + 128) & 255;
 1460+ i = 255 - (x + ((15 - y) << 4));
14611461 buffer[x + (ddsd.lPitch*y)] = i;
14621462 }
14631463 }