OpenGL DSA 和 FBO

OpenGL DSA and FBO

我升级了我的 FBO 代码以使用 OpenGL 4.5 中的 DSA(直接访问状态)功能。

一切都很好,但我仍然需要在绘制之前使用 glBindFramebuffer()。我错过了什么吗?

在联系我的 FBO 之前,我正在考虑这个电话。

glNamedFramebufferDrawBuffer(m_FBO, GL_COLOR_ATTACHMENT0);

然后使用这个恢复默认帧缓冲区。

glDrawBuffer(GL_BACK);

但是没用。我还应该使用 glBindFramebuffer() 吗?最后,如果是这样,glNamedFramebufferDrawBuffer() 的用途是什么?

我几乎找不到关于这个的明确主题。

glNamedFramebufferDrawBuffer 不将 frambuffer 绑定到目标。它仅为命名的帧缓冲区对象指定颜色缓冲区。

OpenGL 4.6 core profile specification - 17.4.1 Selecting Buffers for Writing, p. 513:

17.4.1 Selecting Buffers for Writing

The first such operation is controlling the color buffers into which each of the fragment color values is written. This is accomplished with either DrawBuffer or DrawBuffers commands described below. The set of buffers of a framebuffer object to which fragment color zero is written is controlled with the commands

void DrawBuffer( enum buf );
void NamedFramebufferDrawBuffer( uint framebuffer, enum buf );

For DrawBuffer, the framebuffer object is that bound to the DRAW_FRAMEBUFFER binding. For NamedFramebufferDrawBuffer, framebuffer is zero or the name of a framebuffer object. If framebuffer is zero, then the default draw framebuffer is affected.

OpenGL 4.6 core profile specification - 9.2 Binding and Managing Framebuffer Objects, p. 297:

A framebuffer object is created by binding a name returned by GenFramebuffers (see below) to DRAW_FRAMEBUFFER or READ_FRAMEBUFFER. The binding is effected by calling

void BindFramebuffer( enum target, uint framebuffer );

目标设置为所需的帧缓冲区目标,帧缓冲区设置为帧缓冲区对象名称。生成的帧缓冲区对象是一个新的状态向量 ...