1

I am using OpenGL ES to run some shaders on Android.

On some older/cheap devices they do not support highp precision so the shader output is incorrect.

I need to know when the app starts if the device can support high precision. That way I can tell the user "forget it, your device does not support high precision floats" rather than have it output garbage for them.

I found this query code online, but it seems to only be for WebGL

var highp = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
var highpSupported = highp.precision != 0;

Does anyone have a way I can query an android device (KitKat or higher) to see what precision the GLES shaders will support?

This is the final code I now use, but contents of range and precision are always -999 no matter where I run the code in my app. Before, during or after the GLSurfaceView has been created and GLES output has run.

IntBuffer range = IntBuffer.allocate(2);
IntBuffer precision = IntBuffer.allocate(1);
range.put(0,-999);
range.put(1,-999);
precision.put(0,-999);
android.opengl.GLES20.glGetShaderPrecisionFormat(android.opengl.GLES20.GL_FRAGMENT_SHADER, android.opengl.GLES20.GL_HIGH_FLOAT,range,precision);
String toastText="Range[0]="+String.valueOf(range.get(0))+" Range[1]="+String.valueOf(range.get(1))+" Precision[0]="+String.valueOf(precision.get(0));
Toast.makeText(getApplicationContext(),toastText, Toast.LENGTH_SHORT).show();

The above code always returns -999 for all 3 values, and the kronos doco states if an error occurs then the values will be unchanged. So it looks like there is an error or I am not calling it at the right time.

Some1Else
  • 715
  • 11
  • 26
  • Related: http://stackoverflow.com/questions/28540290/why-it-is-necessary-to-set-precision-for-the-fragment-shader – Morrison Chang Jul 20 '16 at 21:37
  • Thanks, but that is not related. That is about not having a default precision specified within shader code. I want to query precision before I even run shader code. I have already set highp within my shaders. – Some1Else Jul 20 '16 at 21:39
  • You weren't able to find this: https://developer.android.com/reference/android/opengl/GLES20.html#glGetShaderPrecisionFormat(int, int, java.nio.IntBuffer, java.nio.IntBuffer) – Morrison Chang Jul 20 '16 at 21:47
  • OK, that helped me get the syntax. I modified my question. But how do I extract the precision and check for highp support from that code? – Some1Else Jul 20 '16 at 22:30
  • Did you read the Khronos doc for that function: https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetShaderPrecisionFormat.xml – Morrison Chang Jul 20 '16 at 22:36
  • And to confirm if you call the function with GL_VERTEX_SHADER you also get no valid results? My only other suggestion is try the version that uses int[] rather than IntBuffer. – Morrison Chang Jul 20 '16 at 23:18
  • 1
    Where exactly are you calling this? In `onSurfaceCreated()` of your Renderer implementation? – Reto Koradi Jul 21 '16 at 03:14
  • Thanks! That was the trick. I had to call the above code inside onSurfaceCreated. – Some1Else Jul 21 '16 at 03:43

0 Answers0