是否可以在opengl中使用深度缓冲区渲染3D纹理 [英] Is it possible to render 3D texture with depth buffer in opengl

查看:34
本文介绍了是否可以在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.

因此,您应该使用具有深度格式的二维数组纹理,而不是使用渲染缓冲区.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆