GLES2.0: Use GL_TEXTURE_EXTERNAL_OES via glEGLImageTargetTexture2DOES

abergmeier picture abergmeier · Dec 31, 2012 · Viewed 7.4k times · Source

I would like to render an image buffer in Java (NDK is no option in this case) and pass it to shaders via GL_TEXTURE_EXTERNAL_OES.

glTexImage2D does not work, as mentioned in the spec. But the function glEGLImageTargetTexture2DOES is only available via the GLES11Ext class, which seems kind of wrong to use.

Anyway, I tried and it gives me GL_INVALID_OPERATION, which should happen if:

If the GL is unable to specify a texture object using the supplied eglImageOES (if, for example, refers to a multisampled eglImageOES), the error INVALID_OPERATION is generated.

Sadly I cannot make heads or tails from this description, especially since the Android Java API doesn't seem to give me access to eglImageOES functions. Neither have I found a Java example for the usage of this function.

Attached a small example:

// Bind the texture unit 0
GLES20.glActiveTexture( GLES20.GL_TEXTURE0 );
throwOnError( "glActiveTexture" );

GLES20.glBindTexture( GL_TEXTURE_EXTERNAL_OES, _samplerLocation );
throwOnError( "glBindTexture" );

// _output is ByteBuffer.allocateDirect(pixels * Integer.SIZE / Byte.SIZE).order(ByteOrder.nativeOrder()).asIntBuffer()
_output.rewind();
_output.limit( pixels );
GLES11Ext.glEGLImageTargetTexture2DOES( GL_TEXTURE_EXTERNAL_OES, _output );
throwOnError( "glEGLImageTargetTexture2DOES" ); // <-- throws

GLES20.glDrawArrays( GLES20.GL_TRIANGLE_STRIP, 0, 4 );
throwOnError( "glDrawArrays" );

Did anyone do that before or know whether this is possible or not?

EDIT:

I had a look at glEGLImageTargetTexture2DOES implementation and it seems that I have to correctly setup the buffer. Added that, but still same error.

Answer

Adrian picture Adrian · Oct 20, 2014

There are some comments in this page which might help: http://developer.android.com/reference/android/graphics/SurfaceTexture.html