From 05b94676d12471aa7354f926b75f51ab6e4b6e30 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 19 Sep 2010 07:34:06 +0000 Subject: [PATCH] Taking care of glBlendEquation in 2.1 --- .../processing/core/PGraphicsAndroid3D.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/android/core/src/processing/core/PGraphicsAndroid3D.java b/android/core/src/processing/core/PGraphicsAndroid3D.java index 6157147e2..7b4ae13c9 100644 --- a/android/core/src/processing/core/PGraphicsAndroid3D.java +++ b/android/core/src/processing/core/PGraphicsAndroid3D.java @@ -345,6 +345,7 @@ public class PGraphicsAndroid3D extends PGraphics { static protected boolean matrixGetSupported; static protected boolean vboSupported; static protected boolean fboSupported; + static protected boolean blendEqSupported; static protected int maxTextureSize; static protected float maxPointSize; static protected float maxLineWidth; @@ -2551,7 +2552,7 @@ public class PGraphicsAndroid3D extends PGraphics { if (!blend || blendMode != BLEND) { gl.glEnable(GL10.GL_BLEND); - if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); + if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); } @@ -4988,37 +4989,36 @@ public class PGraphicsAndroid3D extends PGraphics { blendMode = mode; gl.glEnable(GL10.GL_BLEND); if (mode == REPLACE) { - if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); + if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ZERO); } else if (mode == BLEND) { - if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); + if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); } else if (mode == ADD) { - if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); + if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); } else if (mode == MULTIPLY) { - if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); + if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); gl.glBlendFunc(GL10.GL_DST_COLOR, GL10.GL_SRC_COLOR); } else if (mode == SUBTRACT) { - if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); + if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); gl.glBlendFunc(GL10.GL_ONE_MINUS_DST_COLOR, GL10.GL_ZERO); } else if (mode == DARKEST) { - if (gl11xp != null) { + if (blendEqSupported) { gl11xp.glBlendEquation(GL_MIN_EXT); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_DST_ALPHA); } else { PGraphics.showWarning("A3D: This blend mode is currently unsupported."); } } else if (mode == LIGHTEST) { - if (gl11xp != null) { + if (blendEqSupported) { gl11xp.glBlendEquation(GL_MAX_EXT); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_DST_ALPHA); } else { PGraphics.showWarning("A3D: This blend mode is currently unsupported."); } - } else if (mode == DIFFERENCE) { - if (gl11xp != null) { + if (blendEqSupported) { gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_REVERSE_SUBTRACT); gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE); } else { @@ -5189,7 +5189,20 @@ public class PGraphicsAndroid3D extends PGraphics { fboSupported = false; } } - + + if (gl11xp != null) { + try { + gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD); + blendEqSupported = true; + } catch (UnsupportedOperationException e) { + // This takes care of Android 2.1 and older where the glBlendEquation is present in the API, + // but any call to it will result in an error. + blendEqSupported = false; + } + } else { + blendEqSupported = false; + } + usingModelviewStack = gl11 == null || !matrixGetSupported; int temp[] = new int[2];