OpenGL ES 着色器和 64 位 iPhone 5S [英] OpenGL ES Shaders and 64-bit iPhone 5S

查看:23
本文介绍了OpenGL ES 着色器和 64 位 iPhone 5S的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始在 OpenGL ES 应用程序上使用 iPhone 5S 和 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 是一个变量 typedef.在 32 位构建环境中它是单精度的,在 64 位它是双精度的.通常这不会是一个大问题,但您使用的是 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 始终是单精度浮点值,当您使用该函数的非指针版本时,编译器可以处理从双精度到单精度的类型降级.当您使用指针时,不会发生这种行为 - OpenGL 希望传递一个单精度浮点数数组,但您传递给它的是一个双精度浮点数数组,而没有进行类型转换.

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 typedef 以确保此类事情永远不会发生.

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

这篇关于OpenGL ES 着色器和 64 位 iPhone 5S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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