diff --git a/android/core/src/processing/opengl/PGL.java b/android/core/src/processing/opengl/PGL.java index ce2d74609..b42dce582 100644 --- a/android/core/src/processing/opengl/PGL.java +++ b/android/core/src/processing/opengl/PGL.java @@ -2111,6 +2111,33 @@ public class PGL { } + protected int[] getGLVersion() { + String version = GLES20.glGetString(GLES20.GL_VERSION).trim(); + int[] res = {0, 0, 0}; + String[] parts = version.split(" "); + for (int i = 0; i < parts.length; i++) { + if (0 < parts[i].indexOf(".")) { + String nums[] = parts[i].split("\\."); + try { + res[0] = Integer.parseInt(nums[0]); + } catch (NumberFormatException e) { } + if (1 < nums.length) { + try { + res[1] = Integer.parseInt(nums[1]); + } catch (NumberFormatException e) { } + } + if (2 < nums.length) { + try { + res[2] = Integer.parseInt(nums[2]); + } catch (NumberFormatException e) { } + } + break; + } + } + return res; + } + + /////////////////////////////////////////////////////////// // Android specific stuff diff --git a/android/core/src/processing/opengl/PGraphicsOpenGL.java b/android/core/src/processing/opengl/PGraphicsOpenGL.java index cc82f6d10..1138e3474 100644 --- a/android/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/android/core/src/processing/opengl/PGraphicsOpenGL.java @@ -6084,6 +6084,23 @@ public class PGraphicsOpenGL extends PGraphics { OPENGL_EXTENSIONS = pgl.getString(PGL.EXTENSIONS); GLSL_VERSION = pgl.getString(PGL.SHADING_LANGUAGE_VERSION); + int major = pgl.getGLVersion()[0]; + System.err.println("OpenGL version " + OPENGL_VERSION + " " + major); + if (major < 2) { + // There might be problems... + PGraphics.showWarning("The OpenGL version in this is less than 2.0 so " + + "Processing might not draw things properly"); + // ... but GLSL might still be available through extensions. + if (OPENGL_EXTENSIONS.indexOf("_fragment_shader") == -1 || + OPENGL_EXTENSIONS.indexOf("_vertex_shader") == -1 || + OPENGL_EXTENSIONS.indexOf("_shader_objects") == -1 || + OPENGL_EXTENSIONS.indexOf("_shading_language") == -1) { + // GLSL extensions are not present, we cannot do anything else here. + throw new RuntimeException("GLSL shaders are not supported by this " + + "video card"); + } + } + npotTexSupported = -1 < OPENGL_EXTENSIONS.indexOf("_texture_non_power_of_two"); autoMipmapGenSupported = diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 0c2bb3e66..dc99c724a 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -2545,6 +2545,33 @@ public class PGL { } + protected int[] getGLVersion() { + String version = gl.glGetString(GL.GL_VERSION).trim(); + int[] res = {0, 0, 0}; + String[] parts = version.split(" "); + for (int i = 0; i < parts.length; i++) { + if (0 < parts[i].indexOf(".")) { + String nums[] = parts[i].split("\\."); + try { + res[0] = Integer.parseInt(nums[0]); + } catch (NumberFormatException e) { } + if (1 < nums.length) { + try { + res[1] = Integer.parseInt(nums[1]); + } catch (NumberFormatException e) { } + } + if (2 < nums.length) { + try { + res[2] = Integer.parseInt(nums[2]); + } catch (NumberFormatException e) { } + } + break; + } + } + return res; + } + + /////////////////////////////////////////////////////////// // Java specific stuff diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index cc82f6d10..1138e3474 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -6084,6 +6084,23 @@ public class PGraphicsOpenGL extends PGraphics { OPENGL_EXTENSIONS = pgl.getString(PGL.EXTENSIONS); GLSL_VERSION = pgl.getString(PGL.SHADING_LANGUAGE_VERSION); + int major = pgl.getGLVersion()[0]; + System.err.println("OpenGL version " + OPENGL_VERSION + " " + major); + if (major < 2) { + // There might be problems... + PGraphics.showWarning("The OpenGL version in this is less than 2.0 so " + + "Processing might not draw things properly"); + // ... but GLSL might still be available through extensions. + if (OPENGL_EXTENSIONS.indexOf("_fragment_shader") == -1 || + OPENGL_EXTENSIONS.indexOf("_vertex_shader") == -1 || + OPENGL_EXTENSIONS.indexOf("_shader_objects") == -1 || + OPENGL_EXTENSIONS.indexOf("_shading_language") == -1) { + // GLSL extensions are not present, we cannot do anything else here. + throw new RuntimeException("GLSL shaders are not supported by this " + + "video card"); + } + } + npotTexSupported = -1 < OPENGL_EXTENSIONS.indexOf("_texture_non_power_of_two"); autoMipmapGenSupported =