简体   繁体   English

OpenGL浮点精度

[英]OpenGL floating point precision

I am working on a project to migrate from legacy/immediate OpenGL to modern OpenGL (core profile).我正在开发一个项目,从旧版/直接 OpenGL 迁移到现代 OpenGL(核心配置文件)。 In the legacy OpenGL implementation, we used double precision, ie we made use of GL_DOUBLE in glVertexPointer and we used glLoadMatrixd , etc. However, in modern OpenGL, only OpenGL/GLSL 4.0+ supports double precision.在传统OpenGL实现,我们使用双精度,也就是说,我们利用了GL_DOUBLEglVertexPointer和我们使用glLoadMatrixd等。然而,在现代的OpenGL,Op​​enGL的只/ GLSL 4.0 +支持双精度。

How does old OpenGL support double precision while newer OpenGL doesn't?旧的 OpenGL 如何支持双精度而新的 OpenGL 不支持? How does legacy OpenGL handle double precision while most graphics cards don't even support double precision?传统 OpenGL 如何处理双精度,而大多数显卡甚至不支持双精度?

I couldn't find any information on the internet or some answers were too old.我在互联网上找不到任何信息或一些答案太旧了。

Do current graphics cards support double precision?现在的显卡支持双精度吗? Should I use OpenGL 4.0?我应该使用 OpenGL 4.0 吗?

How does old OpenGL support double precision while newer OpenGL doesn't?旧的 OpenGL 如何支持双精度而新的 OpenGL 不支持? How does legacy OpenGL handle double precision while most graphics cards don't even support double precision?传统 OpenGL 如何处理双精度,而大多数显卡甚至不支持双精度?

It doesn't what you think it does.它不是你认为的那样。 That you can use doubles as vertex attributes does not imply (and never did) that the GL implementation will do calculations with that precisions - GPUs never did that.您可以使用双精度作为顶点属性并不意味着(并且从来没有)GL 实现将使用该精度进行计算 - GPU 从未这样做过。 The data is converted to single precision in any case.在任何情况下,数据都会转换为单精度。 Same for the matrices - the matrices which were sent to the GPU were never double precision in legacy GL, no matter if you used d or f suffix when specifying the data CPU-side.矩阵也是如此——在传统 GL 中,发送到 GPU 的矩阵从来都不是双精度的,无论您在指定 CPU 端数据时是否使用df后缀。

Just with more recent GPUs, double precision became available in the shader cores, and modern GL 4.x allows you to use that for the first time .只是在更新的 GPU 中,着色器内核中可以使用双精度,而现代 GL 4.x 允许您第一次使用它。

Also note that lots of real-world consumer GPUs have some insane low double precison ratio like 1/32 of the FP32 performance, so you better think twice before using that.另请注意,许多现实世界的消费级 GPU 都有一些疯狂的低双精度比,例如 FP32 性能的 1/32,因此在使用之前最好三思而后行。 For graphics, you seldom will need that.对于图形,您很少需要它。 And the fact that your previous code worked with legacy GL proved that you did not need the precision.您之前的代码与遗留 GL 一起工作的事实证明您不需要精度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM