我試圖在同一時間渲染多采樣和單採樣紋理(drawcall)。 我爲什麼要這樣?因爲多重採樣紋理使用抗鋸齒,而單採樣紋理用於選色。 兩個紋理(nRenderTargetTexture和nColorPickingTexture)具有相同的大小。 如果我運行下面的代碼,它在GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE的情況下失敗。 可以同時渲染多重採樣和單採樣紋理嗎?在framebuffer中渲染多重採樣和單採樣紋理
順便說一句:我還使用glGetError(),但它返回GL_NO_ERROR
// Enable multisampling
glEnable(GL_MULTISAMPLE);
glGenFramebuffers(1, pFramebufferID);
glBindFramebuffer(GL_FRAMEBUFFER, *pFramebufferID);
// Create color render buffer
glGenRenderbuffers(1, &nColorBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, nColorBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, nWidth, nHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, nColorBuffer);
// Create depth render buffer
glGenRenderbuffers(1, &nDepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, nDepthBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, nWidth, nHeight);
//Attach the multisampled textures
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, nDepthBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, nDepthBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, nRenderTargetTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, nColorPickingTexture, 0);
const GLenum draw_buffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
glDrawBuffers(2, draw_buffers);
GLenum eFramebufferOk = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
bool bResult = false;
switch (eFramebufferOk)
{
case GL_FRAMEBUFFER_UNDEFINED:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
case GL_FRAMEBUFFER_COMPLETE:
{
bResult = true;
}
break;
default:
{
DebugAssertOnce(CREATE_FRAME_BUFFER_FAILED);
}
break;
}
非常感謝!