Added DISABLE_DEPTH_MASK/ENABLE_DEPTH_MASK hint

This commit is contained in:
codeanticode
2010-07-08 05:05:54 +00:00
parent fc29036cf3
commit 92d4fecb4f
3 changed files with 45 additions and 37 deletions
@@ -491,6 +491,9 @@ public interface PConstants {
static final int ENABLE_ACCURATE_TEXTURES = 7;
static final int DISABLE_ACCURATE_TEXTURES = -7;
static final int DISABLE_DEPTH_MASK = 8;
static final int ENABLE_DEPTH_MASK = -8;
static final int HINT_COUNT = 10;
@@ -60,9 +60,8 @@ import processing.core.PShape3D.VertexGroup;
*/
public class PGraphicsAndroid3D extends PGraphics {
public SurfaceHolder holder;
A3DRenderer renderer;
A3DConfigChooser configChooser;
protected A3DRenderer renderer;
protected A3DConfigChooser configChooser;
public GL10 gl;
public GL11 gl11;
@@ -325,11 +324,6 @@ public class PGraphicsAndroid3D extends PGraphics {
boolean blend;
int blendMode;
// ........................................................
// TODO: implement API for enabing/disabling of depth masking.
boolean depthMask;
// ........................................................
// Extensions support.
@@ -543,8 +537,14 @@ public class PGraphicsAndroid3D extends PGraphics {
// with the current fill color.
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
gl.glDisable(texture.getGLTarget());
gl.glDepthMask(true);
gl.glDisable(texture.getGLTarget());
if (hints[DISABLE_DEPTH_MASK]) {
gl.glDepthMask(false);
} else {
gl.glDepthMask(true);
}
if (blend) {
blend(blendMode);
} else {
@@ -651,8 +651,14 @@ public class PGraphicsAndroid3D extends PGraphics {
// with the current fill color.
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
gl.glDisable(tex.getGLTarget());
gl.glDepthMask(true);
gl.glDisable(tex.getGLTarget());
if (hints[DISABLE_DEPTH_MASK]) {
gl.glDepthMask(false);
} else {
gl.glDepthMask(true);
}
if (blend) {
blend(blendMode);
} else {
@@ -694,6 +700,11 @@ public class PGraphicsAndroid3D extends PGraphics {
} else {
gl.glEnable(GL10.GL_DEPTH_TEST);
}
if (hints[DISABLE_DEPTH_MASK]) {
gl.glDepthMask(false);
} else {
gl.glDepthMask(true);
}
// Restoring blending.
if (blend) {
@@ -840,6 +851,12 @@ public class PGraphicsAndroid3D extends PGraphics {
// use <= since that's what processing.core does
gl.glDepthFunc(GL10.GL_LEQUAL);
if (hints[DISABLE_DEPTH_MASK]) {
gl.glDepthMask(false);
} else {
gl.glDepthMask(true);
}
// because y is flipped
gl.glFrontFace(GL10.GL_CW);
@@ -1088,6 +1105,12 @@ public class PGraphicsAndroid3D extends PGraphics {
} else if (which == ENABLE_DEPTH_TEST) {
gl.glEnable(GL10.GL_DEPTH_TEST);
} else if (which == DISABLE_DEPTH_MASK) {
gl.glDepthMask(false);
} else if (which == ENABLE_DEPTH_MASK) {
gl.glDepthMask(true);
} else if (which == DISABLE_OPENGL_2X_SMOOTH) {
// TODO throw an error?
@@ -4809,7 +4832,12 @@ public class PGraphicsAndroid3D extends PGraphics {
gl.glDisable(tex.getGLTarget());
gl.glDepthMask(true);
if (hints[DISABLE_DEPTH_MASK]) {
gl.glDepthMask(false);
} else {
gl.glDepthMask(true);
}
if (blend) {
blend(blendMode);
} else {
+1 -24
View File
@@ -89,10 +89,6 @@ public class PShape3D extends PShape implements PConstants {
protected boolean texCoordSet = false;
protected boolean vertexColor = true;
// TODO: consider implementing simple depth sorting for particle systems,
// and a more intutive way to implement the api for enabling/disabling depth masking.
protected boolean depthMaskEnabled = true;
protected static final int SIZEOF_FLOAT = Float.SIZE / 8;
@@ -1491,16 +1487,8 @@ public class PShape3D extends PShape implements PConstants {
////////////////////////////////////////////////////////////
// Parameters
// Parameters
public void noDepthMask() {
depthMaskEnabled = false;
}
public void depthMask() {
depthMaskEnabled = true;
}
public void setDrawMode(int mode) {
pointSprites = false;
@@ -1886,13 +1874,6 @@ public class PShape3D extends PShape implements PConstants {
pointSize = PApplet.min(g.strokeWeight, PGraphicsAndroid3D.maxPointSize);
gl.glPointSize(pointSize);
if (!depthMaskEnabled) {
// Disabling writing to depth mask. This is useful to avoid artifacts when rendering particle systems.
// Proper rendering of a particle system with particles that have transparency involves depth-sorting,
// but it is expensive. In most cases, doing this is good enough.
gl.glDepthMask(false);
}
gl.glEnableClientState(GL11.GL_NORMAL_ARRAY);
gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, glNormalBufferID[0]);
gl.glNormalPointer(GL11.GL_FLOAT, 0, 0);
@@ -1996,10 +1977,6 @@ public class PShape3D extends PShape implements PConstants {
}
}
if (!depthMaskEnabled) {
gl.glDepthMask(true);
}
gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
gl.glDisableClientState(GL11.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL11.GL_COLOR_ARRAY);