我正在尝试将图像渲染到OpenGL ES中的纹理,以实现屏幕外的Sobel滤镜。在此链接http://www.songho.ca/opengl/gl_fbo.html之后,我创建了一个名为 sobelTexture 的结果纹理和一个名为 depthBuffer 的渲染帧缓冲区,然后分别将它们附加到新创建的GL_COLOR_ATTACHMENT0和GL_DEPTH_ATTACHMENT帧缓冲区。代码如下所示。
// Create a texture associated with the frame buffer to render image into
GLuint sobelTexture;
glGenTextures(1, &sobelTexture);
glBindTexture(GL_TEXTURE_2D, sobelTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
GLuint depthBuffer;
glGenRenderbuffers(1, &depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
// Create frame buffer
GLuint frameBuffer;
glGenFramebuffers(1, &frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sobelTexture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer);
但是,当我使用波纹管代码检查帧缓冲区状态时,它会返回与GL_FRAMEBUFFER_COMPLETE不同的内容。
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
NSLog(@"! ERROR: frame buffer is not completed\n");
exit(1);
}
此外,如果我将glTexImage2D()函数中的数据类型GL_FLOAT更改为GL_UNSIGNED_BYTE,则帧缓冲区将标记为完成。但我不能使用它,因为在我的片段着色器中,输出颜色组件是浮点类型。
我该如何解决这个问题? 提前感谢您的帮助。