万众瞩目的FBO

写FBO时可以省去的变量为:

  • render buffer id
  • color buffer id

需要留一个texture id对外接口,作为材质贴在图元上。由于是材质,我们可以通过shader进行后处理(post render processing)。

这个后处理好啊,可以描边、采样、模糊啥的,这个后处理才算的上是民间所传的“渲染”,即润色。

本文给出一些GLAD的API,并选择重点翻译了一手,语拙望谅。

glCheckFramebufferStatus

1
2
GLenum glCheckFramebufferStatus(GLenum target);
GLenum glCheckNamedFramebufferStatus(GLuint framebuffer,GLenum target);

当且仅当返回值为GL_FRAMEBUFFER_COMPLETE 时,可以认定该FBO组件完整。否则将会据情况返回以下值:

  • GL_FRAMEBUFFER_UNDEFINED 使用了未定义的默认帧缓存
  • GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 组件不完整
  • GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 帧缓存需要至少一个图像缓存,而实际上并没有
  • GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER is returned if the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for any color attachment point(s) named by GL_DRAW_BUFFERi.
  • GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER is returned if GL_READ_BUFFER is not GL_NONE and the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment point named by GL_READ_BUFFER.
  • GL_FRAMEBUFFER_UNSUPPORTED is returned if the combination of internal formats of the attached images violates an implementation-dependent set of restrictions.
  • GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE is returned if the value of GL_RENDERBUFFER_SAMPLES is not the same for all attached renderbuffers; if the value of GL_TEXTURE_SAMPLES is the not same for all attached textures; or, if the attached images are a mix of renderbuffers and textures, the value of GL_RENDERBUFFER_SAMPLES does not match the value of GL_TEXTURE_SAMPLES.
  • GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE is also returned if the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not the same for all attached textures; or, if the attached images are a mix of renderbuffers and textures, the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not GL_TRUE for all attached textures.
  • GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS is returned if any framebuffer attachment is layered, and any populated attachment is not layered, or if all populated color attachments are not from textures of the same target.

glFramebufferTexture2D

1
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);

glFrameBufferTexture2D有以下的参数:

  • target:帧缓冲的目标(绘制、读取或者两者皆有)
  • attachment:我们想要附加的附件类型。当前我们正在附加一个颜色附件。注意最后的0意味着我们可以附加多个颜色附件。我们将在之后的教程中提到。
  • textarget:你希望附加的纹理类型
  • texture:要附加的纹理本身
  • level:多级渐远纹理的级别。我们将它保留为0。
Share