Android : Using FBO to record screen in Android

on Thursday, July 31, 2014




I'm developing the Android plugin that record Unity gameplay screen.To achieve this, I used OpenGL FBO. Pseudo Code is so simple like this below :



// Bind frame buffer as a render target
mFrameBuffer.bind();

// Render scene to frame buffer
renderScene();

// Restore rendering target, unbind FBO
mFrameBuffer.unbind();

// Draw texture into display
mTexture.draw(mFrameBuffer.getTexture());

// Make video surface a rendering target
videoCapture.captureFrame(mFrameBuffer.getTexture());


The output video is ok but i had a problem when render to window display using offscreen texture that get from FBO. I checked my code and recognize that the calls to glDrawArray fails with GL_INVALID_OPERATION error code

.


My render code



public void draw(int textureId) {
this.shader.use();

GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
Log.getPossibleGLError("active texture0");
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
Log.getPossibleGLError("bind texture when redraw");

int uOrientationM = this.shader.getAttributeLocation("uOrientationM");
Log.getPossibleGLError("get orientation matrix");
int uTransformM = this.shader.getAttributeLocation("uTransformM");
Log.getPossibleGLError("get transform matrix");

GLES20.glUniformMatrix4fv(uOrientationM, 1, false, this.orientationMatrix, 0);

Log.getPossibleGLError("set orientation matrix when redraw");

GLES20.glUniformMatrix4fv(uTransformM, 1, false, this.transformMatrix, 0);

Log.getPossibleGLError("set uniform matrix when redraw");

renderQuad(this.shader.getAttributeLocation("aPosition"));

Log.getPossibleGLError("render quad when redraw");

this.shader.unUse();
}

private void renderQuad(int aPosition) {
GLES20.glVertexAttribPointer(aPosition, 2, GLES20.GL_BYTE, false, 0, this.fullQuadVertices);
Log.getPossibleGLError("get vertex attrib pointer");
GLES20.glEnableVertexAttribArray(aPosition);
Log.getPossibleGLError("enable vertex array");
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
// error occurs after execute glDrawArrays
Log.getPossibleGLError("draw array ");
}


This code worked fine when render to videoSurface but failed when render to window display.

Any solutions for my issue?

Any help will be greatly appreciated!


0 comments:

Post a Comment