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
Yes, if you check out the CL and GL headers, you get:
Note in some GL implementations you get intermediary typedef’s like
khronos_float_tbut ultimately it all boils down to thefloattype. 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).