1

PBO用来截屏。但是,结果图像全黑。没有PBO. 在这样做之前我需要注意什么吗?

我什至尝试渲染到 aFBO然后使用GLES30.glReadBuffer(GLES30.GL_COLOR_ATTACHMENT0),没有希望

public void SetupPBO(){ 
    GLES30.glGenBuffers(1, pbuffers, 0);        
    GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, pbuffers[0]);
    int size = (int)this.mScreenHeight *  (int)this.mScreenWidth * 4;
    GLES30.glBufferData(GLES30.GL_PIXEL_PACK_BUFFER, size, null, GLES30.GL_DYNAMIC_READ);
    checkGlError("glReadBuffer");
    GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, 0);
}

private void Render(float[] m) {
    .......//Normal render logic
    exportBitmap();
}

 private void exportBitmap() {
    int screenshotSize = (int)this.mScreenWidth * (int)this.mScreenHeight;
    ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize * 4);
    bb.order(ByteOrder.nativeOrder());

    // set the target framebuffer to read
    GLES30.glReadBuffer(GLES30.GL_FRONT);
    checkGlError("glReadBuffer");
    GLES30.glBindBuffer(GLES30.GL_PIXEL_PACK_BUFFER, pbuffers[0]);
    GLES30.glReadPixels(0, 0, (int)mScreenWidth, (int)mScreenHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);  //<------ not working ?????

    int pixelsBuffer[] = new int[screenshotSize];
    bb.asIntBuffer().get(pixelsBuffer);
    bb = null;

    for (int i = 0; i < screenshotSize; ++i) {
        // The alpha and green channels' positions are preserved while the
        // red and blue are swapped
        pixelsBuffer[i] = ((pixelsBuffer[i] & 0xff00ff00))
                    | ((pixelsBuffer[i] & 0x000000ff) << 16)
                    | ((pixelsBuffer[i] & 0x00ff0000) >> 16);
    }

    Bitmap bitmap = Bitmap.createBitmap((int)mScreenWidth, (int)mScreenHeight, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixelsBuffer, screenshotSize - (int)mScreenWidth, -(int)mScreenWidth, 0, 0, (int)mScreenWidth, (int)mScreenHeight);
    SaveBitmap(bitmap);
}
4

1 回答 1

1
GLES30.glReadPixels(0, 0, (int)mScreenWidth, (int)mScreenHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);

bb 被解释为您的 PBO 中的偏移量。因此,您正在写出缓冲区(在某些驱动程序上,此代码会导致崩溃)。你应该传递 0 而不是 bb。要从 PBO 中检索数据,请使用 glMapBuffer。

于 2014-08-24T16:38:12.257 回答