aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/native/d3d/Canvas3D.cpp59
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