我正在使用帧缓冲区在视频渲染器上进行一些后期处理着色器。其中一个着色器的查找非常密集,因此我想更改为仅亮度的帧缓冲区以加快速度。我尝试在初始化时将 glTexImage2D 调用从 RGBA 更改为 LUMINANCE,但是当我尝试在“onDrawFrame”中附加缓冲区时出现错误。
问题是我已经从示例中破解了代码并且不太了解它所做的一切。一方面,我还创建了一个深度附件,因为我正在渲染视频,所以我不需要任何深度信息,但我不知道我是否可以禁用它。无论如何,这是我在 onSurfaceCreated 中对 FBO 的初始化:
GLES20.glGenTextures(1, renTex, 0);
// generate
GLES20.glGenFramebuffers(1, fb2, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE4);
// generate color texture
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renTex[0]);
// parameters
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
// create it
// create an empty intbuffer first?
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, texW, texH, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, texBuffer);
//**THIS WORKS AS IS, CHANGING FROM RGBA TO LUMINANCE BREAKS IT**
// create render buffer and bind 16-bit depth buffer
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRb[0]);
GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, texW, texH);
这是在 onDrawFrame 中附加缓冲区的代码:
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb[0]);
// specify texture as color attachment
GLES20.glViewport(0, 0, w, h);
Matrix.frustumM(mProjMatrix, 0, -.30f, .30f, -.30f, .30f, 3, 7);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renTex[0], 0);
// attach render buffer as depth buffer
GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRb[0]);
int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
if (status != GLES20.GL_FRAMEBUFFER_COMPLETE)
System.out.println("Frame buffer not obtained :(");
//This works for RGBA but returns an error for LUMINANCE
有人有什么建议吗?我也可以放弃深度缓冲区组件还是强制性的