DirectX和OpenGL之间的模板选项

时间:2013-10-14 16:01:51

标签: opengl directx stencil-buffer zbuffer

我正在实现一个仿真层。除了模板材料(我的阴影重叠)之外,其他所有工作都可以。

我只是想知道我是否在逻辑上做事 - 如果我做出正确的结论/假设:

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);
    }
}

2 个答案:

答案 0 :(得分:1)

有几件事可能会出错。

  • 您对incr和incr_sat执行相同的操作。测试代码是否使用它? G1需要扩展才能饱和。这不是一回事。
  • 使用旧的d3d代码仔细检查模板参考是否为0..255。参数> 255或< 0如何处理(钳位与和)
  • 可能有所不同
  • 仔细检查d3d是不是双面的。并记住剔除是翻转。
  • 仔细检查模板清除代码!

好消息是,这应该适用于基本的表格翻译。没有基本的API问题(我之前做过)。它只需要大量的测试,因为参数空间很大。

答案 1 :(得分:1)

想出来,我忘了设置我的PIXELFORMATDESCRIPTOR:

pfd.cStencilBits = 8;