瀏覽代碼

Fix glClear not working properly if the last rendered model disabled depth or color writing (fix issue #639 on google code)

shadowislord 11 年之前
父節點
當前提交
661053689d

+ 13 - 0
jme3-android/src/main/java/com/jme3/renderer/android/OGLESShaderRenderer.java

@@ -392,9 +392,22 @@ public class OGLESShaderRenderer implements Renderer {
     public void clearBuffers(boolean color, boolean depth, boolean stencil) {
         int bits = 0;
         if (color) {
+            //See explanations of the depth below, we must enable color write to be able to clear the color buffer
+            if (context.colorWriteEnabled == false) {
+                GLES20.glColorMask(true, true, true, true);
+                context.colorWriteEnabled = true;
+            }
             bits = GLES20.GL_COLOR_BUFFER_BIT;
         }
         if (depth) {
+            //glClear(GL_DEPTH_BUFFER_BIT) seems to not work when glDepthMask is false
+            //here s some link on openl board
+            //http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=257223
+            //if depth clear is requested, we enable the depthMask
+            if (context.depthWriteEnabled == false) {
+                GLES20.glDepthMask(true);
+                context.depthWriteEnabled = true;
+            }
             bits |= GLES20.GL_DEPTH_BUFFER_BIT;
         }
         if (stencil) {

+ 13 - 0
jme3-ios/src/main/java/com/jme3/renderer/ios/IGLESShaderRenderer.java

@@ -121,9 +121,22 @@ public class IGLESShaderRenderer implements Renderer {
         logger.log(Level.FINE, "IGLESShaderRenderer clearBuffers");
         int bits = 0;
         if (color) {
+            //See explanations of the depth below, we must enable color write to be able to clear the color buffer
+            if (context.colorWriteEnabled == false) {
+                JmeIosGLES.glColorMask(true, true, true, true);
+                context.colorWriteEnabled = true;
+            }
             bits = JmeIosGLES.GL_COLOR_BUFFER_BIT;
         }
         if (depth) {
+            //glClear(GL_DEPTH_BUFFER_BIT) seems to not work when glDepthMask is false
+            //here s some link on openl board
+            //http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=257223
+            //if depth clear is requested, we enable the depthMask
+            if (context.depthWriteEnabled == false) {
+                JmeIosGLES.glDepthMask(true);
+                context.depthWriteEnabled = true;
+            }
             bits |= JmeIosGLES.GL_DEPTH_BUFFER_BIT;
         }
         if (stencil) {