OpenGL ES Shaders and 64-bit iPhone 5S

I just started testing iPhone 5S and 64-bit architecture in the OpenGL ES application. The problem I see is that the values ​​(CGFloat) are incorrect when they fall into the shaders. I go through 0.8 and change -1.58819e-23 when I debug the shader. I use glUniform4fv () to pass the value. Do I need to use a different data type or? or another method for passing values? The value goes through a penalty when I test 32-bit

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 that this is from a GLPaint demo ...)

thanks,

Austin

+7
ios iphone 64bit opengl-es shader
source share
1 answer

CGFloat is a typedef variable. In a 32-bit build environment, this is single-point, on a 64-bit one, double precision. This will usually not be a big problem, but you are using glUniform4fv , which accepts GLfloat * .

; ; <http://www.khronos.org/registry/gles/specs/2.0/es_full_spec_2.0.25.pdf#page=22 "rel =" noreferrer "> OpenGL ES 2.0 Specification - GL Basic Operation - p. 12

Specification sample

OpenGL stipulates that GLfloat always a floating point value with a single precision, and compilers can deal with a double-precision downgrade to one precision when using a version that does not contain pointers to this function. When you use pointers, this behavior does not happen - OpenGL expects to transmit an array of single-point floats, but you pass it an array of floats with double precision without type conversion.

You need to stop using CGFloat . Use GLfloat . OpenGL typedefs are provided to ensure this kind of thing never happens.

+12
source share

All Articles