Helper class for ARCore apps to read camera image from an OpenGL OES texture.
This class provides two methods for reading pixels from a texture:
(A) All-in-one method: this method utilizes two frame buffers. It does not block the caller
thread. Instead it submits a reading request to read pixel to back buffer from the current
texture, and returns pixels from the front buffer bund to texture supplied to the previous call
to this function. This can be done by calling submitAndAcquire() function.
(B) Asychronous method: this method utilizes multiple frame buffers and it does not block the
caller thread. This method allows you to read a texture in a lower frequency than rendering
frequency(Calling submitAndAcquire() in a lower frequency will result in an "old" image buffer
that was submitted a few frames ago). This method contains three routines: submitFrame(),
acquireFrame() and releaseFrame().
First, you call submitFrame() to submit a frame reading request. GPU will start the reading
process in background:
bufferIndex = submitFrame(textureId, textureWidth, textureHeight);
Second, you call acquireFrame() to get the actual image frame:
imageBuffer = acquireFrame(bufferIndex);
Last, when you finish using of the imageBuffer retured from acquireFrame(), you need to
release the associated frame buffer so that you can reuse it in later frame:
releaseFrame(bufferIndex);
Note: To use any of the above two methods, you need to call create() routine to initialize the
reader before calling any of the reading routine. You will also need to call destroy() method to
release the internal resource when you are done with the reader.