Can I safely mix OpenGL ES 3.1 and 3.0 in one app?

Hello,

I am developing an Android ‘graphics effects’ library. 95% of its functionality works just fine with OpenGL ES 3.0, but for one particular feature I need some parts of ES 3.1.

I thus wrote it in a way that mixes 3.0 and 3.1. When initializing my library, I first detect the supported OpenGL ES version, and if running on hardware that only supports 3.0, I switch off the part of API that makes use of 3.1 so that users of my library should hopefully never be able to make use of them.

I am however a bit worried that I have to import two versions of OpenGL ES java bindings

import android.opengl.GLES30;
import android.opengl.GLES31;
// ....
private void func1()  // plain 3.0 function
  {
  mNormalMVPMatrixH  = GLES30.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
  // ...
  }

private void func2()  // uses some 3.1 stuff
  {
  ByteBuffer atomicBuf = (ByteBuffer)GLES30.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
        GLES30.GL_MAP_WRITE_BIT | GLES30.GL_MAP_INVALIDATE_BUFFER_BIT);
  // 
  }

Is it safe to do this? I’ve tried on several target devices and everything seems to be running fine…

Yes.

It’s also safe to just replace GLES30 with GLES31, e.g.

private void func2()  // uses some 3.1 stuff
  {
  ByteBuffer atomicBuf = (ByteBuffer)GLES31.glMapBufferRange( GLES31.GL_ATOMIC_COUNTER_BUFFER, 0, 4,
        GLES31.GL_MAP_WRITE_BIT | GLES31.GL_MAP_INVALIDATE_BUFFER_BIT);
  // 
  }

GLES31 inherits from GLES30 which inherits from GLES20; any function or variable present in the base class will be present in classes which derive from it.