From d319a907da13b127971aec547022a7dce8cb9c05 Mon Sep 17 00:00:00 2001 From: Kevin Rushforth Date: Mon, 26 Mar 2007 22:58:59 +0000 Subject: Issue 239: Stencil buffer should be cleared at the start of each frame This partial fix adds a new "j3d.stencilClear" boolean property that specifies whether the stencil buffer is cleared every frame by default. Note that this is the first part of the partial fix. We still need to finish the D3D code, and we need to verify whether the stencil mask needs to be saved/forced to all 1s/restored git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@802 ba19aa83-45c5-6ac9-afd3-db810772062c --- src/native/ogl/Canvas3D.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'src/native/ogl/Canvas3D.c') diff --git a/src/native/ogl/Canvas3D.c b/src/native/ogl/Canvas3D.c index 37c8b9f..e70b0c3 100644 --- a/src/native/ogl/Canvas3D.c +++ b/src/native/ogl/Canvas3D.c @@ -682,7 +682,6 @@ getPropertiesFromCurrentContext( ctxInfo->multi_draw_arrays_sun = JNI_TRUE; } - if (isExtensionSupported(tmpExtensionStr, "GL_EXT_compiled_vertex_array") && getJavaBoolEnv(env, "isCompiledVertexArray")) { ctxInfo->compiled_vertex_array_ext = JNI_TRUE; @@ -1461,19 +1460,21 @@ void JNICALL Java_javax_media_j3d_NativePipeline_texturemapping( } JNIEXPORT -void JNICALL Java_javax_media_j3d_NativePipeline_clear(JNIEnv *env, - jobject obj, - jlong ctxInfo, - jfloat r, - jfloat g, - jfloat b) +void JNICALL Java_javax_media_j3d_NativePipeline_clear( + JNIEnv *env, + jobject obj, + jlong ctxInfo, + jfloat r, + jfloat g, + jfloat b, + jboolean clearStencil) { GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; jlong ctx = ctxProperties->context; - #ifdef VERBOSE - fprintf(stderr, "Canvas3D.clear()\n"); + fprintf(stderr, "Canvas3D.clear(%g, %g, %g, %s)\n", + r, g, b, (stencilClear ? "true" : "false")); #endif glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); @@ -1484,18 +1485,33 @@ void JNICALL Java_javax_media_j3d_NativePipeline_clear(JNIEnv *env, glDepthMask(GL_TRUE); glClear(GL_DEPTH_BUFFER_BIT); glPopAttrib(); - + + /* Issue 239 - clear stencil if specified */ + /* + * TODO KCR : Issue 239 - should we also set stencil mask? If so, we + * may need to save/restore like we do for depth mask + */ + if (clearStencil) { + glClearStencil(0); + glClear(GL_STENCIL_BUFFER_BIT); + } + +/* TODO: we should be able to do the following, which should perform better... */ #if 0 - - /* Java 3D always clears the Z-buffer */ + int clearMask = GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT; + + if (clearStencil) { + glClearStencil(0); + clearMask |= GL_STENCIL_BUFFER_BIT; + } + glPushAttrib(GL_DEPTH_BUFFER_BIT); glDepthMask(GL_TRUE); glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue); - glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + glClear(clearMask); glPopAttrib(); #endif - } JNIEXPORT -- cgit v1.2.3