Skip to content

Commit 05b9467

Browse files
committed
Taking care of glBlendEquation in 2.1
1 parent 8531983 commit 05b9467

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

android/core/src/processing/core/PGraphicsAndroid3D.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ public class PGraphicsAndroid3D extends PGraphics {
345345
static protected boolean matrixGetSupported;
346346
static protected boolean vboSupported;
347347
static protected boolean fboSupported;
348+
static protected boolean blendEqSupported;
348349
static protected int maxTextureSize;
349350
static protected float maxPointSize;
350351
static protected float maxLineWidth;
@@ -2551,7 +2552,7 @@ protected void textLineImpl(char buffer[], int start, int stop, float x, float y
25512552

25522553
if (!blend || blendMode != BLEND) {
25532554
gl.glEnable(GL10.GL_BLEND);
2554-
if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
2555+
if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
25552556
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
25562557
}
25572558

@@ -4988,37 +4989,36 @@ public void blend(int mode) {
49884989
blendMode = mode;
49894990
gl.glEnable(GL10.GL_BLEND);
49904991
if (mode == REPLACE) {
4991-
if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
4992+
if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
49924993
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ZERO);
49934994
} else if (mode == BLEND) {
4994-
if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
4995+
if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
49954996
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
49964997
} else if (mode == ADD) {
4997-
if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
4998+
if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
49984999
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
49995000
} else if (mode == MULTIPLY) {
5000-
if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
5001+
if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
50015002
gl.glBlendFunc(GL10.GL_DST_COLOR, GL10.GL_SRC_COLOR);
50025003
} else if (mode == SUBTRACT) {
5003-
if (gl11xp != null) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
5004+
if (blendEqSupported) gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
50045005
gl.glBlendFunc(GL10.GL_ONE_MINUS_DST_COLOR, GL10.GL_ZERO);
50055006
} else if (mode == DARKEST) {
5006-
if (gl11xp != null) {
5007+
if (blendEqSupported) {
50075008
gl11xp.glBlendEquation(GL_MIN_EXT);
50085009
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_DST_ALPHA);
50095010
} else {
50105011
PGraphics.showWarning("A3D: This blend mode is currently unsupported.");
50115012
}
50125013
} else if (mode == LIGHTEST) {
5013-
if (gl11xp != null) {
5014+
if (blendEqSupported) {
50145015
gl11xp.glBlendEquation(GL_MAX_EXT);
50155016
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_DST_ALPHA);
50165017
} else {
50175018
PGraphics.showWarning("A3D: This blend mode is currently unsupported.");
50185019
}
5019-
50205020
} else if (mode == DIFFERENCE) {
5021-
if (gl11xp != null) {
5021+
if (blendEqSupported) {
50225022
gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_REVERSE_SUBTRACT);
50235023
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
50245024
} else {
@@ -5189,7 +5189,20 @@ public void onSurfaceCreated(GL10 igl, EGLConfig config) {
51895189
fboSupported = false;
51905190
}
51915191
}
5192-
5192+
5193+
if (gl11xp != null) {
5194+
try {
5195+
gl11xp.glBlendEquation(GL11ExtensionPack.GL_FUNC_ADD);
5196+
blendEqSupported = true;
5197+
} catch (UnsupportedOperationException e) {
5198+
// This takes care of Android 2.1 and older where the glBlendEquation is present in the API,
5199+
// but any call to it will result in an error.
5200+
blendEqSupported = false;
5201+
}
5202+
} else {
5203+
blendEqSupported = false;
5204+
}
5205+
51935206
usingModelviewStack = gl11 == null || !matrixGetSupported;
51945207

51955208
int temp[] = new int[2];

0 commit comments

Comments
 (0)