Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对自己的QML类使用float或double 我用C++和Qt创建了一些组件和帮助方法,用于我的QML GUI中。其中一些方法计算GUI元素(大小、转换、场景图项创建)。目标是使用OpenGl/Eglfs渲染输出的ARM 32位_Qt_Opengl_Opengl Es_Qml_Qtquick2 - Fatal编程技术网

对自己的QML类使用float或double 我用C++和Qt创建了一些组件和帮助方法,用于我的QML GUI中。其中一些方法计算GUI元素(大小、转换、场景图项创建)。目标是使用OpenGl/Eglfs渲染输出的ARM 32位

对自己的QML类使用float或double 我用C++和Qt创建了一些组件和帮助方法,用于我的QML GUI中。其中一些方法计算GUI元素(大小、转换、场景图项创建)。目标是使用OpenGl/Eglfs渲染输出的ARM 32位,qt,opengl,opengl-es,qml,qtquick2,Qt,Opengl,Opengl Es,Qml,Qtquick2,OpenGl使用的是float,QML使用的是real(定义为double) 我在C++中应该用什么来不丢失任何精度?< p>如果你使用 qReals(双< /代码>),那么你就不应该失去任何精度。如果在qtbase.git中git grep float,您可以找到更多信息: dist/changes-5.2.0-**************************************************************************** dist/changes-5.

OpenGl使用的是
float
,QML使用的是
real
(定义为
double


<>我在C++中应该用什么来不丢失任何精度?

< p>如果你使用<代码> qReals(<代码>双< /代码>),那么你就不应该失去任何精度。如果在
qtbase.git
git grep float
,您可以找到更多信息:

dist/changes-5.2.0-****************************************************************************
dist/changes-5.2.0-*                   Important Behavior Changes                             *
dist/changes-5.2.0-****************************************************************************
dist/changes-5.2.0-
dist/changes-5.2.0- - Qt is now compiled with qreal typedef'ed to double on all
dist/changes-5.2.0:   platforms. qreal was a float on ARM chipsets before. This guarantees more
dist/changes-5.2.0-   consistent behavior between all platforms Qt supports, but is binary
dist/changes-5.2.0-   incompatible to Qt 5.1 on ARM. The old behavior can be restored by
dist/changes-5.2.0:   passing -qreal float to configure.
有趣的是,在Qt中,有大量代码已切换为仅使用浮点:

commit 51d40d7e9bdfc63c5109aef5b732aa2ba10f985a
Author: Sean Harmer <sean.harmer@kdab.com>
Date:   Mon Aug 20 20:55:40 2012 +0100

    Make gui/math3d classes use float rather than qreal

    This corrects the mismatch between using floats for internal storage
    and qreal in the API of QVector*D which leads to lots of implicit
    casts between double and float.

    This change also stops users from being surprised by the loss of
    precision when using these classes on desktop platforms and removes
    the need for the private constructors taking a dummy int as the final
    argument.

    The QMatrix4x4 and QQuaternion classes have been changed to use float
    for their internal storage since these are meant to be used in
    conjunction with the QVector*D classes. This is to prevent unexpected
    loss of precision and to improve performance.

    The on-disk format has also been changed from double to float thereby
    reducing the storage required when streaming vectors and matrices. This
    is potentially a large saving when working with complex 3D meshes etc.

    This also has a significant performance improvement when passing
    matrices to QOpenGLShaderProgram (and QGLShaderProgram) as we no
    longer have to iterate and convert the data to floats. This is
    an operation that could easily be needed many times per frame.

    This change also opens the door for further optimisations of these
    classes to be implemented by using SIMD intrinsics.
提交51D40D7E9BDFC63C5109AEF5B732AA2AB10F985A
作者:肖恩·哈默
日期:周一至八月20日20:55:40 2012+0100
使gui/math3d类使用float而不是qreal
这纠正了将浮动用于内部存储之间的不匹配
QVector*D的API中的qreal导致了大量的隐式
在double和float之间转换。
这一变化也避免了用户对数据丢失感到惊讶
在桌面平台上使用这些类时的精度,并删除
私有构造函数需要以伪int作为最终值
论点
QMatrix4x4和QQuaternion类已更改为使用float
用于其内部存储,因为这些是用于
与QVector*D类结合使用。这是为了防止意外
降低精度并提高性能。
磁盘格式也从双精度更改为浮点格式
减少流化向量和矩阵时所需的存储。这
在处理复杂的3D网格等时,可能会节省大量资源。
这在通过测试时也有显著的性能改进
矩阵到QOpenGLShaderProgram(和QGLShaderProgram),因为我们没有
不再需要迭代并将数据转换为浮点数。这是
每帧可能需要多次的操作。
这一变化也为这些系统的进一步优化打开了大门
要使用SIMD内部函数实现的类。
正如它所说的,这是为了避免精度的意外损失,因为函数使用
qreal
double
),但将其数据存储为
float
。如果您在自己的代码中的任何地方都使用
qreal
,则不会出现此问题

另一个原因是性能。对此我不能作太多评论,但我要说的是,与大多数Qt用户相比,Qt在这些方面进行优化更为重要。

您可以找到描述