I spent a lot more time on this and EGLImage
's in general after running into this issue. alonorbach's hypothesis was correct.
If for any reason, the driver cannot create a texture sibling from the supplied EGLImage
, then a rather ambiguous GL_INVALID_OPERATION
is returned. I was under the impression that if I was able to create a valid EGLImage
(i.e., not an EGL_NO_IMAGE_KHR
) and the appropriate extensions were supported, I would be able to bind to the same using either a rendebuffer or texture sibling (in GL_OES_EGL_image
). This is certainly not the case. It also seems to vary a lot from device to device. I was able to get this working on NVidia Tegra
units but not on the Adreno 320
.
Does this mean it is impossible to reliably use EGLImages on Android
? Not quite. Specifically for the issue I was running into, I was able to bind a texture sibling to an EGLImage
created using a renderbuffer source by specifying GL_RGBA8_OES
in extension GL_OES_rgb8_rgba8
as the internal format of the source renderbuffer (argument 2 to glRenderbufferStorage
). This is less than ideal but proves the point that somehow the internal formats of the source and target siblings must match, and, in case of a mismatch, the driver is under no obligation to accomodate the variation and is free to give up.
Another source of entropy when trying to use EGLImage
s successfully (at least generically on Android
) is the way in which the EGLImage
s themselves are created. I found that it was far more reliable to create an EGLImage
using the EGL_NATIVE_BUFFER_ANDROID
target specified in the EGL_ANDROID_image_native_buffer
extension. If such extensions are available for your platform, it is highly advisable to use them in a fallback manner.
In summary, the solution that seems to work reliably for me seems to be to first try and create a valid EGLImage
using any and all available extensions in a fallback manner. Then using that EGLImage
try binding to the target sibling kind. If this pair of operations yields no errors, then that EGLImage/TargetKind pair is supported on that device and can be used for subsequent operations. If either operation fails, the next item in the fallback chain is checked. If all else fails, a solution that does not use EGLImage
s should likely be present. I have not encountered such an Android device yet (fingers crossed)
I am still discovering corner cases and optimizations and will keep this answer updated with findings.