我正在實現一個仿真層。除了模板材料(我的陰影重疊)之外,其他所有東西都可以工作。DirectX和OpenGL之間的模板選項
我只是想知道如果我做的事情在邏輯 - 如果我正在做正確的結論/假設:
case D3DRS_STENCILENABLE:
glAble(GL_STENCIL_TEST, value);
break;
case D3DRS_STENCILFAIL:
sStencilFail = glFromD3DSTENCILOP((D3DSTENCILOP)value);
AssertGL(glStencilOp(sStencilFail, sStencilPassDepthFail, sStencilPassDepthPass));
break;
case D3DRS_STENCILZFAIL:
sStencilPassDepthFail = glFromD3DSTENCILOP((D3DSTENCILOP)value);
AssertGL(glStencilOp(sStencilFail, sStencilPassDepthFail, sStencilPassDepthPass));
break;
case D3DRS_STENCILPASS:
sStencilPassDepthPass = glFromD3DSTENCILOP((D3DSTENCILOP)value);
AssertGL(glStencilOp(sStencilFail, sStencilPassDepthFail, sStencilPassDepthPass));
break;
case D3DRS_STENCILFUNC:
sStencilFunc = glFromD3DCMPFUNC((D3DCMPFUNC)value);
AssertGL(glStencilFunc(sStencilFunc, sStencilRef, sStencilValueMask));
break;
case D3DRS_STENCILREF:
sStencilRef = value;
AssertGL(glStencilFunc(sStencilFunc, sStencilRef, sStencilValueMask));
break;
case D3DRS_STENCILMASK:
sStencilValueMask = value;
AssertGL(glStencilFunc(sStencilFunc, sStencilRef, sStencilValueMask));
break;
case D3DRS_STENCILWRITEMASK:
AssertGL(glStencilMask(value));
break;
下面是上面使用。 glAble()只是glEnable/glDisable的包裝器。
static GLenum glFromD3DCMPFUNC(D3DCMPFUNC value) {
return(GL_NEVER + value - 1);
}
static GLenum glFromD3DSTENCILOP(D3DSTENCILOP value) {
switch (value) {
case D3DSTENCILOP_KEEP: return(GL_KEEP);
case D3DSTENCILOP_ZERO: return(GL_ZERO);
case D3DSTENCILOP_REPLACE: return(GL_REPLACE);
case D3DSTENCILOP_INVERT: return(GL_INVERT);
case D3DSTENCILOP_INCRSAT:
case D3DSTENCILOP_INCR:
return(GL_INCR);
case D3DSTENCILOP_DECRSAT:
case D3DSTENCILOP_DECR:
return(GL_DECR);
default: Assert(!"Unsupported!"); return(0);
}
}
哪個D3D和GL的版本,你定位?在2.0以前版本的GL中實現D3D9模版時可能會遇到困難,這些版本只能通過擴展來暴露雙面模板操作。我希望在你的模擬器中看到一些處理'D3DRS_Two_Sided_StencilMODE'的東西,然後恰當地將'D3DRS_CCW_STENCILFAIL'這樣的東西分派給'glStencilFuncSeparate(...)'。它增加了相當多的複雜性,但處理前/後模板測試的常見用例有所不同。 –
DirectX 8 - 不做雙面。 OpenGL 3. –