/** * Acquires the frame requested earlier. This routine returns a TextureReaderImage object that * contains the pixels mapped to the frame buffer requested previously through submitFrame(). * * <p>If input buffer index is invalid, an exception will be thrown. * * @param bufferIndex the index to the frame buffer to be acquired. It has to be a frame index * returned from submitFrame(). * @return a TextureReaderImage object if succeed. Null otherwise. */ public TextureReaderImage acquireFrame(int bufferIndex) { if (bufferIndex < 0 || bufferIndex >= bufferCount || !bufferUsed[bufferIndex]) { throw new RuntimeException("Invalid buffer index."); } // Bind the current PB and acquire the pixel buffer. GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, pbo[bufferIndex]); ByteBuffer mapped = (ByteBuffer) GLES30.glMapBufferRange( GLES30.GL_PIXEL_PACK_BUFFER, 0, pixelBufferSize, GLES30.GL_MAP_READ_BIT); // Wrap the mapped buffer into TextureReaderImage object. TextureReaderImage buffer = new TextureReaderImage(imageWidth, imageHeight, imageFormat, mapped); return buffer; }