为什么OpenGL使用float而不是double? [英] Why does OpenGL use float rather than double?

查看:691
本文介绍了为什么OpenGL使用float而不是double?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么OpenGL在功能上使用float而不是double. Double应该比float更准确.

I am wondering why OpenGL makes use of float rather than double in its functions. Double should be much more accurate than float.

推荐答案

过去,许多OpenGL函数确实具有double变体.例如, glMultMatrix 具有d变体.其中大多数不再存在,但这与floatdouble无关. glMultMatrixd glMultMatrixf在核心GL 3.1及更高版本中均已消失.

In the past, many OpenGL functions did have a double variant. glMultMatrix for example has f and d variations. Most of these don't exist anymore, but that has nothing to do with float vs. double. glMultMatrixd and glMultMatrixf are gone in core GL 3.1 and above.

核心OpenGL 中,仍然存在具有double变体的函数.尽管有float版本(主要是为了与GL ES兼容引入的),但glDepthRange需要double.有些功能具有double变体,例如glBlendColor.

In core OpenGL, there are still functions that have double variants. glDepthRange takes double, though there is a float version (introduced mainly for GL ES compatibility). There are some functions that don't have double variants, like glBlendColor.

有时,OpenGL只是不一致.在其他时候,它只是遵循一个合理的原则:不对用户说谎.

Sometimes, OpenGL is just being inconsistent. Other times, it is simply following a reasonable principle: not lying to the user.

采用 glBlendColor .如果您可以将其传递为双精度值,则意味着浮点混合是以双精度精度进行的.由于它肯定不(在存在的任何硬件上)不存在,因此提供一种提供这种准确性的API对用户来说是一个默认的谎言.您正在将高精度值用于低精度操作.尽管glDepthRange的逻辑相同(没有双精度深度缓冲区不可用),但它需要doubles.同样,不一致.

Take glBlendColor. If you could pass it double-precision values, that would imply that floating-point blending took place with double-precision accuracy. Since it most certainly does not (on any hardware that exists), providing an API that offers that accuracy is a tacit lie to the user. You're taking high-precision values to a low-precision operation. Though the same logic is true of glDepthRange (no double-precision depth buffers are not available), yet it takes doubles. So again, inconsistency.

glUniform* 函数集是一个更好的例子.他们将状态设置为当前程序对象.在GL 4.0之前,不存在double版本.为什么?因为那本来是谎言. GLSL 4.0之前的版本不允许您声明double,原因很简单,显而易见的原因是4.0之前的硬件无法实现它..如果硬件无法处理,则不允许用户创建double.

The glUniform* suite of functions is a much better example. They set state into the current program object. Until GL 4.0, the double versions did not exist. Why? Because that would have been a lie. GLSL pre-4.0 did not allow you to declare a double, for the simple and obvious reason that no pre-4.0 hardware could implement it. There's no point in allowing the user to create a double if the hardware couldn't handle it.

这篇关于为什么OpenGL使用float而不是double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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