Merge pull request #6811 from unknownbrackets/d3d9

d3d: Add basic stencil mask handling
This commit is contained in:
Henrik Rydgård 2014-08-31 09:27:46 +02:00
commit afb31ef79a
4 changed files with 25 additions and 1 deletions

View File

@ -92,8 +92,11 @@ namespace DX9 {
} }
static void ClearBuffer() { static void ClearBuffer() {
dxstate.depthWrite.set(true); dxstate.scissorTest.disable();
dxstate.depthWrite.set(TRUE);
dxstate.colorMask.set(true, true, true, true); dxstate.colorMask.set(true, true, true, true);
dxstate.stencilFunc.set(D3DCMP_ALWAYS, 0, 0);
dxstate.stencilMask.set(0xFF);
pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 0, 0); pD3Ddevice->Clear(0, NULL, D3DCLEAR_STENCIL|D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 0, 0);
} }
@ -103,6 +106,8 @@ namespace DX9 {
dxstate.depthTest.disable(); dxstate.depthTest.disable();
dxstate.scissorTest.disable(); dxstate.scissorTest.disable();
dxstate.stencilTest.disable(); dxstate.stencilTest.disable();
dxstate.colorMask.set(true, true, true, true);
dxstate.stencilMask.set(0xFF);
} }

View File

@ -230,6 +230,7 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
dxstate.stencilTest.enable(); dxstate.stencilTest.enable();
dxstate.stencilOp.set(D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE); dxstate.stencilOp.set(D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE, D3DSTENCILOP_REPLACE);
dxstate.stencilFunc.set(D3DCMP_ALWAYS, 0, 0xFF); dxstate.stencilFunc.set(D3DCMP_ALWAYS, 0, 0xFF);
dxstate.stencilMask.set(0xFF);
} else { } else {
dxstate.stencilTest.disable(); dxstate.stencilTest.disable();
} }
@ -254,6 +255,21 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
bool gmask = ((gstate.pmskc >> 8) & 0xFF) < 128; bool gmask = ((gstate.pmskc >> 8) & 0xFF) < 128;
bool bmask = ((gstate.pmskc >> 16) & 0xFF) < 128; bool bmask = ((gstate.pmskc >> 16) & 0xFF) < 128;
bool amask = (gstate.pmska & 0xFF) < 128; bool amask = (gstate.pmska & 0xFF) < 128;
u8 abits = (gstate.pmska >> 0) & 0xFF;
#ifndef MOBILE_DEVICE
u8 rbits = (gstate.pmskc >> 0) & 0xFF;
u8 gbits = (gstate.pmskc >> 8) & 0xFF;
u8 bbits = (gstate.pmskc >> 16) & 0xFF;
if ((rbits != 0 && rbits != 0xFF) || (gbits != 0 && gbits != 0xFF) || (bbits != 0 && bbits != 0xFF)) {
WARN_LOG_REPORT_ONCE(rgbmask, G3D, "Unsupported RGB mask: r=%02x g=%02x b=%02x", rbits, gbits, bbits);
}
if (abits != 0 && abits != 0xFF) {
// The stencil part of the mask is supported.
WARN_LOG_REPORT_ONCE(amask, G3D, "Unsupported alpha/stencil mask: %02x", abits);
}
#endif
dxstate.colorMask.set(rmask, gmask, bmask, amask); dxstate.colorMask.set(rmask, gmask, bmask, amask);
// Stencil Test // Stencil Test
@ -265,6 +281,7 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) {
dxstate.stencilOp.set(stencilOps[gstate.getStencilOpSFail()], // stencil fail dxstate.stencilOp.set(stencilOps[gstate.getStencilOpSFail()], // stencil fail
stencilOps[gstate.getStencilOpZFail()], // depth fail stencilOps[gstate.getStencilOpZFail()], // depth fail
stencilOps[gstate.getStencilOpZPass()]); // depth pass stencilOps[gstate.getStencilOpZPass()]); // depth pass
dxstate.stencilMask.set(~abits);
} else { } else {
dxstate.stencilTest.disable(); dxstate.stencilTest.disable();
} }

View File

@ -48,6 +48,7 @@ void DirectxState::Restore() {
stencilTest.restore(); count++; stencilTest.restore(); count++;
stencilOp.restore(); count++; stencilOp.restore(); count++;
stencilFunc.restore(); count++; stencilFunc.restore(); count++;
stencilMask.restore(); count++;
dither.restore(); count++; dither.restore(); count++;

View File

@ -380,6 +380,7 @@ public:
DxState3<D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP, D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP, D3DRS_STENCILPASS, D3DSTENCILOP_KEEP> stencilOp; DxState3<D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP, D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP, D3DRS_STENCILPASS, D3DSTENCILOP_KEEP> stencilOp;
DxState3<D3DRS_STENCILFUNC, D3DCMP_ALWAYS, D3DRS_STENCILREF, 0, D3DRS_STENCILMASK, 0xFFFFFFFF> stencilFunc; DxState3<D3DRS_STENCILFUNC, D3DCMP_ALWAYS, D3DRS_STENCILREF, 0, D3DRS_STENCILMASK, 0xFFFFFFFF> stencilFunc;
DxState1<D3DRS_STENCILWRITEMASK, 0xFFFFFFFF> stencilMask;
DxSampler0State1<D3DSAMP_MINFILTER, D3DTEXF_POINT> texMinFilter; DxSampler0State1<D3DSAMP_MINFILTER, D3DTEXF_POINT> texMinFilter;
DxSampler0State1<D3DSAMP_MAGFILTER, D3DTEXF_POINT> texMagFilter; DxSampler0State1<D3DSAMP_MAGFILTER, D3DTEXF_POINT> texMagFilter;