一、添加目标纹理为 FBO 的颜色附着(颜色缓冲区) ,绑定源纹理渲染到目标纹理。
二、添加源纹理为 FBO 的颜色附着(颜色缓冲区) , 使用 glCopyTexImage2D 拷贝当前 FBO 的颜色缓冲区到目标纹理。
代码语言:javascript复制 glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, srcTextureId, 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, dstTextureId);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
三、glBlitFramebuffer 一般用于帧缓冲区(颜色缓冲区)间高性能数据拷贝(OpenGL ES 3.0)参考:OpenGL ES 多目标渲染(MRT)
代码语言:javascript复制glGenFramebuffers(1, &fbo); // 源texture和目标texture共用一个FBO即可
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, srcTextureId, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
GL_TEXTURE_2D, dstTextureId, 0);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glDrawBuffer(GL_COLOR_ATTACHMENT1);
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
参考整理自:https://www.jianshu.com/p/9e5e7e62e466
-- END --