现在,我正在尝试将当前场景渲染为绑定在FBO上的2个纹理,分别为GL_COLOR_ATTACHMENT(0和1)。
在初始化状态下,我附加了2个纹理并调用glDrawBuffers为着色器指定2个输出位置。
glBindFramebuffer(GL_FRAMEBUFFER, m_RendererID);
unsigned m_ColorBufferTexture;
glGenTextures(1, &m_ColorBufferTexture);
//...
unsigned m_AddtionalColorBufferTexture;
glGenTextures(1, &m_AdditionalColorBufferTexture);
//...
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, m_ColorBufferTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
GL_TEXTURE_2D, m_AdditionalColorBufferTexture, 0);
uint32_t drawBuffers[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
glDrawBuffers(2, (GLenum*)drawBuffers);
在片段着色器中,我只需指定
layout(location = 0) out vec4 color;
layout(location = 1) out vec4 pseudo_color;
问题是当我尝试通过在屏幕上渲染此纹理来检查m_AdditionalColorBufferTexture是否成功写入时,它失败了并且出现黑屏。 (现在m_ColorBufferTexture可以很好地呈现了。)
但是,如果我在drawBuffers中切换了COLOR_ATTACHMENTs的顺序,并且还在着色器中切换了color和pseudo_color的输出位置,则可以在屏幕上呈现m_AdditionalColorBufferTexture。
看来glDrawBuffers对我不起作用。那么drawBuffers列表中的哪个先行者只能接收片段着色器的输出?
我的代码怎么了?