gpt4 book ai didi

c++ - 在帧缓冲区内渲染多采样和单采样纹理

转载 作者:行者123 更新时间:2023-11-30 05:27:22 25 4
gpt4 key购买 nike

我正在尝试同时渲染多重采样和单采样纹理(drawcall)。我为什么要那个?因为多采样纹理使用抗锯齿,而单采样纹理用于颜色选择。两个纹理(nRenderTargetTexture 和 nColorPickingTexture)具有相同的大小。如果我运行下面的代码,它会在 GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 情况下失败。是否可以同时渲染成多重采样和单采样纹理?

顺便说一句:我也在使用 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;
}

非常感谢!

最佳答案

Is it posible to render into multisampled and singlesampled textures at the same time?

没有。附加到帧缓冲区的所有图像必须具有相同的样本数。否则,您将得到 GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE

关于c++ - 在帧缓冲区内渲染多采样和单采样纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37433497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com