[英]OpenGL ES Shaders and 64-bit iPhone 5S
I just started testing with the iPhone 5S and the 64bit architecture on an OpenGL ES app. 我刚开始在OpenGL ES应用程序上使用iPhone 5S和64位架构进行测试。 The problem I'm seeing is that (CGFloat) values are way wrong when they get to the shaders.
我看到的问题是(CGFloat)值到达着色器时出错了。 I pass in 0.8 and it changes to -1.58819e-23 when I debug the shader.
我传入0.8并在调试着色器时更改为-1.58819e-23。 I am using glUniform4fv() to pass in the value.
我正在使用glUniform4fv()来传递值。 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
当我在32位上测试时,该值很好
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);
(some of you may notice this is from the GLPaint demo...) (有些人可能会注意到这是来自GLPaint演示......)
thanks, 谢谢,
austin 奥斯汀
CGFloat
is a variable typedef. CGFloat
是一个变量typedef。 On a 32-bit build environment it is single-precision, on 64-bit it is double-precision. 在32位构建环境中,它是单精度的,在64位上是双精度。 Normally this would not be a huge issue, but you are using
glUniform4fv
, which takes a GLfloat *
. 通常情况下这不是一个大问题,但你使用的是
glUniform4fv
,它需要一个GLfloat *
。
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. OpenGL规定
GLfloat
始终是单精度浮点值,当您使用此函数的非指针版本时,编译器可以处理从双精度到单精度的类型降级。 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. 当您使用指针时,不会发生此行为 - OpenGL期望传递一个单精度浮点数组,但是您传递一个双精度浮点数组而没有类型转换。
What you need to do is stop using CGFloat
. 你需要做的是停止使用
CGFloat
。 Instead, use GLfloat
. 相反,使用
GLfloat
。 OpenGL typedefs are provided to ensure this sort of thing never happens. 提供OpenGL typedef以确保从未发生过这种事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.