写FBO时可以省去的变量为:
- render buffer id
- color buffer id
需要留一个texture id对外接口,作为材质贴在图元上。由于是材质,我们可以通过shader进行后处理(post render processing)。
这个后处理好啊,可以描边、采样、模糊啥的,这个后处理才算的上是民间所传的“渲染”,即润色。
本文给出一些GLAD的API,并选择重点翻译了一手,语拙望谅。
glCheckFramebufferStatus
1 | GLenum glCheckFramebufferStatus(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 ofGL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
isGL_NONE
for any color attachment point(s) named byGL_DRAW_BUFFERi
.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
is returned ifGL_READ_BUFFER
is notGL_NONE
and the value ofGL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
isGL_NONE
for the color attachment point named byGL_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 ofGL_RENDERBUFFER_SAMPLES
is not the same for all attached renderbuffers; if the value ofGL_TEXTURE_SAMPLES
is the not same for all attached textures; or, if the attached images are a mix of renderbuffers and textures, the value ofGL_RENDERBUFFER_SAMPLES
does not match the value ofGL_TEXTURE_SAMPLES
.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
is also returned if the value ofGL_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 ofGL_TEXTURE_FIXED_SAMPLE_LOCATIONS
is notGL_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。