Take the 2-minute tour ×

After allocating a VBO using OpenGL I create an OpenCL buffer from it using clCreateFromGLBuffer.

I use the VBO as an array of GLfloat and the OpenCL buffer as an array of cl_float. It works perfectly on my machine. Indeed, GLfloat and cl_float (and float) have the same size.

I am wondering if this would work anywhere flawlessly. In other words, is sizeof(GLfloat) == sizeof(cl_float) always true?* And if not, how does one usually deal with this?

* and is there documentation proving this

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Yes, if you check out the CL and GL headers, you get:

typedef float cl_float;          // @cl_platform.h
typedef float GLfloat;           // @gl.h

Note in some GL implementations you get intermediary typedef's like khronos_float_t but ultimately it all boils down to the float type. So both types are identical to your native float type. Furthermore, the equivalent data types in OpenCL kernels and OpenGL shaders are both guaranteed to be IEEE754-conformant.

Links to relevant headers: cl_platform.h, and the GL header depends on where you got it (they are slightly different from OS to OS and from vendor to vendor), have a look at yours. Examples: gl.h (GLES version), gl.h (FreeBSD nVidia version), gl.h (some random version).

share|improve this answer
Which gl.h did you pull that from? –  Nicol Bolas Aug 9 '12 at 4:34
@NicolBolas good point I was looking at the wrong header, I will edit. –  Thomas Aug 9 '12 at 4:50
@NicolBolas added some links. –  Thomas Aug 9 '12 at 4:57
add comment

Your Answer


