FBO深度纹理附件的最佳设置

编程入门 行业动态 更新时间:2024-10-26 16:32:42
本文介绍了FBO深度纹理附件的最佳设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

到目前为止,在对自定义FBO进行深度测试时,我一直在使用渲染缓冲区.现在我需要用深度纹理替换它们(因为我需要在着色器中阅读它).我正在寻找不同的资源,例如此处,然后看到GL_FLOAT被用作数据类型.在其他示例使用GL_UNSIGNED_BYTE,有时甚至使用GL_INT.内部格式也可以是GL_DEPTH_COMPONENT16,GL_DEPTH_COMPONENT24,GL_DEPTH_COMPONENT32.

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_BYTE,GL_FLOAT等的使用实际上是 Pixel Transfer 类型.这是OpenGL在将像素数据从缓冲区读取/写入缓冲区时使用的类型,在OpenGL中,驱动程序将进行数据类型转换以确保读取/写入的值兼容.在OpenGL ES中,这已完全删除,但在所有情况下,深度渲染缓冲区的内部格式必须为GL_DEPTH_COMPONENT<X>{F}或GL_DEPTH<X>_STENCIL<Y>之一.这些格式定义了数据类型和内部使用的格式.

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_FLOAT与GL_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深度纹理附件的最佳设置

本文发布于:2023-06-01 10:54:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/413467.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:纹理   深度   附件   FBO

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!