diff options
author | Alessandro Borges <[email protected]> | 2005-12-21 22:05:13 +0000 |
---|---|---|
committer | Alessandro Borges <[email protected]> | 2005-12-21 22:05:13 +0000 |
commit | b12e6ed6c1db2cf67c187fdc67cf85b33f08e516 (patch) | |
tree | c97fb8daba6b5f3043b8e356a0c0a287f5b948fd /src/native | |
parent | 13f19817dc36de51fe6fb55e8b01546d7862bb29 (diff) |
Added support for Stencil.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@482 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/native')
-rw-r--r-- | src/native/d3d/Canvas3D.cpp | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/src/native/d3d/Canvas3D.cpp b/src/native/d3d/Canvas3D.cpp index 6c49384..661c20d 100644 --- a/src/native/d3d/Canvas3D.cpp +++ b/src/native/d3d/Canvas3D.cpp @@ -29,7 +29,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_widSync( jobject obj, jint fd, jint numWindows) -{ +{ // This function is only used for Solaris OpenGL } @@ -147,8 +147,8 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_useCtx( jlong display, jint window) { - // D3D doesn't have notation of current context - return JNI_TRUE; + return JNI_TRUE; + // D3D doesn't have notation of current context } @@ -338,13 +338,24 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear( GetDevice(); /* Java 3D always clears the Z-buffer */ + /* @TODO check same operation for stencil */ if (!d3dCtx->zWriteEnable) { device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE); } - device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, - D3DCOLOR_COLORVALUE(r, g, b, 1.0f), 1.0, 0); + /* clear stencil, if in used */ + if (d3dCtx->stencilWriteEnable ) + {// clear stencil and ZBuffer + device->Clear(0, NULL, D3DCLEAR_STENCIL | D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, + D3DCOLOR_COLORVALUE(r, g, b, 1.0f), 1.0, 0); + } + else + { // clear ZBuffer only + device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, + D3DCOLOR_COLORVALUE(r, g, b, 1.0f), 1.0, 0); + } + if (pa2d) { jclass pa2d_class = env->GetObjectClass(pa2d); @@ -401,6 +412,8 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear( int scaleWidth, scaleHeight; float sw, sh; + DWORD stencilcmpfunc; + // sz can be any number since we already disable z buffer // However rhw can't be 0, otherwise texture will not shown screenCoord.sz = 0.999f; @@ -410,6 +423,15 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear( device->GetRenderState(D3DRS_ZFUNC, &zcmpfunc); device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); + + // must disable stencil ? I guess yes + if (d3dCtx->stencilEnable) + { + device->GetRenderState(D3DRS_STENCILFUNC, &stencilcmpfunc); + device->SetRenderState(D3DRS_STENCILENABLE, FALSE); + device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); + } + switch (imageScaleMode){ case javax_media_j3d_Background_SCALE_NONE: @@ -477,13 +499,25 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear( scaleWidth, scaleHeight, texModeRepeat); device->SetRenderState(D3DRS_ZFUNC, zcmpfunc); - device->SetRenderState(D3DRS_ZWRITEENABLE, - d3dCtx->zWriteEnable); - unlockBackground(); - } else { - if (!d3dCtx->zWriteEnable) { - device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); + device->SetRenderState(D3DRS_ZWRITEENABLE, d3dCtx->zWriteEnable); + + // reenable stencil ? yes + if (d3dCtx->stencilEnable) + { + device->SetRenderState(D3DRS_STENCILFUNC, stencilcmpfunc); + device->SetRenderState(D3DRS_STENCILENABLE, d3dCtx->stencilWriteEnable); } + unlockBackground(); + } + else + { + if (!d3dCtx->zWriteEnable) { + device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE); + } + // disable stencil + if (d3dCtx->stencilEnable && !d3dCtx->stencilWriteEnable) { + device->SetRenderState(D3DRS_STENCILENABLE, FALSE); + } } @@ -1033,5 +1067,4 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_validGraphicsMode( EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devMode); return (devMode.dmBitsPerPel > 8); -} - +}
\ No newline at end of file |