From ed0db3e4be3b2ac3ad4224e06435f7c52cd42788 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Thu, 21 Feb 2013 20:46:29 -0500 Subject: [PATCH] check number of max number of samples in addition to availability of multisampling extension to make sure that no MSAA renderbuffer is created, fixes #1644 --- android/core/src/processing/opengl/PGL.java | 35 ++++++++++++--------- core/src/processing/opengl/PGL.java | 35 ++++++++++++--------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/android/core/src/processing/opengl/PGL.java b/android/core/src/processing/opengl/PGL.java index 7907c0eab..6d4064e59 100644 --- a/android/core/src/processing/opengl/PGL.java +++ b/android/core/src/processing/opengl/PGL.java @@ -118,6 +118,10 @@ public class PGL { protected static final int SIZEOF_INDEX = SIZEOF_SHORT; protected static final int INDEX_TYPE = GLES20.GL_UNSIGNED_SHORT; + /** Error string from framebuffer errors **/ + protected static final String FRAMEBUFFER_ERROR_MESSAGE = + "Framebuffer error (%1$s), rendering will probably not work as expected"; + /** Machine Epsilon for float precision. **/ protected static float FLOAT_EPS = Float.MIN_VALUE; // Calculation of the Machine Epsilon for float precision. From: @@ -482,7 +486,9 @@ public class PGL { fboHeight = nextPowerOfTwo(pg.height); } - if (-1 < ext.indexOf("_framebuffer_multisample")) { + getIntegerv(MAX_SAMPLES, intBuffer); + if (-1 < ext.indexOf("_framebuffer_multisample") && + 1 < intBuffer.get(0)) { numSamples = reqNumSamples; } else { numSamples = 1; @@ -2198,26 +2204,25 @@ public class PGL { if (status == FRAMEBUFFER_COMPLETE) { return true; } else if (status == FRAMEBUFFER_INCOMPLETE_ATTACHMENT) { - throw new RuntimeException( - "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "incomplete attachment")); } else if (status == FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) { - throw new RuntimeException( - "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "incomplete missing attachment")); } else if (status == FRAMEBUFFER_INCOMPLETE_DIMENSIONS) { - throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "incomplete dimensions")); } else if (status == FRAMEBUFFER_INCOMPLETE_FORMATS) { - throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_FORMATS (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "incomplete formats")); } else if (status == FRAMEBUFFER_UNSUPPORTED) { - throw new RuntimeException("GL_FRAMEBUFFER_UNSUPPORTED" + - Integer.toHexString(status)); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "framebuffer unsupported")); } else { - throw new RuntimeException("unknown framebuffer error (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "unknown error")); } + return false; } diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 8b66c26d9..2c5dd136a 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -167,6 +167,10 @@ public class PGL { protected static final int SIZEOF_INDEX = SIZEOF_SHORT; protected static final int INDEX_TYPE = GL.GL_UNSIGNED_SHORT; + /** Error string from framebuffer errors **/ + protected static final String FRAMEBUFFER_ERROR_MESSAGE = + "Framebuffer error (%1$s), rendering will probably not work as expected"; + /** Machine Epsilon for float precision. **/ protected static float FLOAT_EPS = Float.MIN_VALUE; // Calculation of the Machine Epsilon for float precision. From: @@ -711,7 +715,9 @@ public class PGL { fboHeight = nextPowerOfTwo(pg.height); } - if (-1 < ext.indexOf("_framebuffer_multisample")) { + getIntegerv(MAX_SAMPLES, intBuffer); + if (-1 < ext.indexOf("_framebuffer_multisample") && + 1 < intBuffer.get(0)) { numSamples = reqNumSamples; } else { numSamples = 1; @@ -2757,26 +2763,25 @@ public class PGL { if (status == FRAMEBUFFER_COMPLETE) { return true; } else if (status == FRAMEBUFFER_INCOMPLETE_ATTACHMENT) { - throw new RuntimeException( - "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "incomplete attachment")); } else if (status == FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) { - throw new RuntimeException( - "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "incomplete missing attachment")); } else if (status == FRAMEBUFFER_INCOMPLETE_DIMENSIONS) { - throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "incomplete dimensions")); } else if (status == FRAMEBUFFER_INCOMPLETE_FORMATS) { - throw new RuntimeException("GL_FRAMEBUFFER_INCOMPLETE_FORMATS (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "incomplete formats")); } else if (status == FRAMEBUFFER_UNSUPPORTED) { - throw new RuntimeException("GL_FRAMEBUFFER_UNSUPPORTED" + - Integer.toHexString(status)); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "framebuffer unsupported")); } else { - throw new RuntimeException("unknown framebuffer error (" + - Integer.toHexString(status) + ")"); + System.err.println(String.format(FRAMEBUFFER_ERROR_MESSAGE, + "unknown error")); } + return false; }