帧缓冲区:FBO - MartinRGB/GLES30_ProgrammingGuide_NDK GitHub Wiki
简单流程如下
生成材质时:
// Setup FBO
glGenFramebuffers ( 1, &userData->fbo );
glBindFramebuffer ( GL_FRAMEBUFFER, userData->fbo );
// Gen Texture2D and attach to FBO
userData->textureHeight = userData->textureWidth = 400;
glGenTextures ( 4, &userData->textureID );
glBindTexture ( GL_TEXTURE_2D, userData->textureID );
glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA,userData->textureWidth, userData->textureHeight,
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
// Set the filtering mode
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glFramebufferTexture2D ( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, userData->colorTexId[i], 0 );
glDrawBuffers ( 4, attachments );
// Restore the original framebuffer
glBindFramebuffer ( GL_FRAMEBUFFER, 0 );
绘制时:
// FIRST: use MRTs to output four colors to four buffers
glBindFramebuffer ( GL_FRAMEBUFFER, userData->fbo );
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//not necessary ,only in this snippets
glDrawBuffers ( 4, attachments );
//Draw something here;
....
// Restore the default framebuffer
glBindFramebuffer ( GL_DRAW_FRAMEBUFFER, 0 );
关闭后:
...
glDeleteFramebuffers ( 1, &userData->fbo );