FBO深度纹理附件的最佳设置 [英] Optimial settings for FBO depth texture attachment

查看:133
本文介绍了FBO深度纹理附件的最佳设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,在对自定义FBO进行深度测试时,我一直在使用渲染缓冲区.现在我需要用深度纹理替换它们(因为我需要在着色器中阅读它).我正在寻找不同的资源,例如

I have been using render buffers till now when using depth test with custom FBOs. Now I need to replace those with depth texture (as I need to read it in a shader).I am looking at different sources like here and see that GL_FLOAT is used as data type.In other examples GL_UNSIGNED_BYTE is used and sometime even GL_INT.Also internal format can be GL_DEPTH_COMPONENT16 , GL_DEPTH_COMPONENT24 , GL_DEPTH_COMPONENT32.

我的问题是,在性能和质量方面哪种变化最好?我确定使用32位深度组件时,深度测试应该更精确,但数据类型又如何?通常应使用哪种?

My question is which variation is best in terms of performance and quality?I am sure that with depth component of 32bit the depth test should be more precise but what about the data type?Which one should be usually used?

推荐答案

您所描述的GL_UNSIGNED_BYTEGL_FLOAT等的使用实际上是

The use of GL_UNSIGNED_BYTE, GL_FLOAT, etc. as you described is actually the Pixel Transfer type. This is the type that OpenGL uses when it reads/writes pixel data from/into a buffer, in OpenGL the driver will do data type conversion to ensure that the read / written values are compatible. In OpenGL ES this was completely removed, but in all cases the internal format of a depth renderbuffer has to be one of GL_DEPTH_COMPONENT<X>{F} or GL_DEPTH<X>_STENCIL<Y>. These formats define both the data type and the format used internally.

为获得最佳性能,请将组件类型与像素传输类型匹配,以避免驱动程序像素转换. (例如,用于像素传输的GL_FLOATGL_DEPTH_COMPONENT32F很好匹配).但是,这仅在您要使用深度/模板缓冲区的内容在OpenGL之外执行某些操作(例如,使用PBO读取或写入缓冲区)时才适用.

For best performance, match the component type to the pixel transfer type to avoid driver pixel conversion. (e.g. GL_FLOAT for pixel transfer is a good match for GL_DEPTH_COMPONENT32F). However, this really only applies when you want to use the contents of the depth/stencil buffer to do something outside of OpenGL (e.g. reading or writing the buffer using a PBO).

大多数情况下,分配深度纹理时,您可以忽略像素传输格式和类型(除了确保它们是给定内部格式的合法值).您可能不会在OpenGL之外读取它,也不会从客户端内存中获取数据,这是唯一适用的情况.

The majority of the time, you can ignore the pixel transfer format and type when you allocate a depth texture (besides ensuring that they are legal values for the given internal format). You probably are not going to read it outside of OpenGL or feed it data from client memory, which is the only time this applies.

这篇关于FBO深度纹理附件的最佳设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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