OpenGL ES的着色器和64位的iPhone 5S着色器、ES、OpenGL、iPhone

2023-09-07 23:30:41 作者:把星星偷给你.

我刚开始用iPhone 5S和一个OpenGL ES应用程序的64位架构的测试。我看到的问题是,(CGFloat的)值的方式错了,当他们到达着色器。我通过在0.8和它改变-1.58819e-23当我调试的着色器。我使用glUniform4fv()来传递的价值。我是否需要使用不同的数据类型或?或不同的方法传递的价值观?该值经过很好,当我测试的32位

I just started testing with the iPhone 5S and the 64bit architecture on an OpenGL ES app. The problem I'm seeing is that (CGFloat) values are way wrong when they get to the shaders. I pass in 0.8 and it changes to -1.58819e-23 when I debug the shader. I am using glUniform4fv() to pass in the value. Do I need to use a different data type or? or a different method to pass in the values? The value goes through fine when I test on 32bit

CGFloat brushColor[4];

brushColor[0] = 0.8;
brushColor[1] = 0.1;
brushColor[2] = 0.1;
brushColor[3] = 0.3;

glUniform4fv(program[PROGRAM_POINT].uniform[UNIFORM_VERTEX_COLOR], 1, brushColor);

(有些人可能会注意到,这是从GLPaint演示...)

(some of you may notice this is from the GLPaint demo...)

感谢

奥斯汀

推荐答案

CGFloat的是一个变量类型定义。在32位版本的环境中,单precision,64位是双precision。通常情况下,这将不会是一个大问题,但使用的是 glUniform4fv ,这需要一个 GLfloat *

CGFloat is a variable typedef. On a 32-bit build environment it is single-precision, on 64-bit it is double-precision. Normally this would not be a huge issue, but you are using glUniform4fv, which takes a GLfloat *.

              

OpenGL的规定, GLfloat 始终是一个单precision浮点值和编译器可以与双precision型降级单幅$处理当您使用此功能的非指针版本p $ pcision。当您使用指针,此行为不会发生 - OpenGL的期望传递的单precision浮标阵列,但传递给它的双precision数组花车,没有类型转换

OpenGL stipulates that GLfloat is always a single-precision floating point value and compilers can deal with type demotion from double-precision to single-precision when you use the non-pointer version of this function. When you use pointers, this behavior does not occur - OpenGL expects to be passed an array of single-precision floats, but you pass it an array of double-precision floats with no type conversion.

您需要做的是停止使用 CGFloat的。相反,使用 GLfloat 。提供了OpenGL的类型定义,以确保这样的事情不会发生。

What you need to do is stop using CGFloat. Instead, use GLfloat. OpenGL typedefs are provided to ensure this sort of thing never happens.