本文介绍了是否可以在opengl中使用深度缓冲区渲染3D纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一些程序并使用以下经典代码:

I'm trying to implement some program and using this classic code:

glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

绑定深度缓冲区.

glGenRenderbuffers(1, &depthbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width,
 height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_RENDERBUFFER, depthbuffer);

绑定几种 3D 纹理:

glGenTextures(targets.size(), textures);
for (auto &target : targets) {
  glBindTexture(GL_TEXTURE_3D, textures[ix]);
  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F, width, height, depth, 0, GL_RGBA, GL_FLOAT, NULL);
}
  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + ix, textures[ix], 0);
  buffers[ix] = GL_COLOR_ATTACHMENT0 + ix;
  ++ix;
}
glDrawBuffers(targets.size(), buffers);

它不起作用,表明 GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS 错误.我以为,由于我的纹理是分层的,因此可能存在未分层的深度缓冲区的问题.我以与3D纹理相同的方式创建了它,因此我删除了深度缓冲区.解决了这一任务,现在我的帧缓冲区正在工作,渲染完成等等.

And it do not work, indicating GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS error. I supposed, that, since my textures are layered, there could be a problem with not layered depth buffer. I have created it in the same way as I did it for 3D textures, so I removed depth buffer. This solved task, now my framebuffer is working, rendering completes and so on.

但是如果我需要渲染每个图层并附加深度缓冲区怎么办?是否支持此功能,很少有API调用来实现?

But what if I need to render each layer, having depth buffer attached? Is this functionality supported, are there some seldom api calls to achieve that?

推荐答案

如果将一个附加图像分层,则必须将所有个附加图像分层.因此,如果要使用深度缓冲区进行分层渲染,则必须 对深度图像进行分层.

If one attached image is layered, then all attached images must be layered. So if you want to do layered rendering with a depth buffer, the depth image must also be layered.

因此,应该使用深度格式的2D阵列纹理,而不是使用渲染缓冲区.

So instead of using a renderbuffer, you should use a 2D array texture with a depth format.

这篇关于是否可以在opengl中使用深度缓冲区渲染3D纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 15:26