0
\$\begingroup\$

How far up do I have to push openGLs typedefs?

If I have GLfloat everywhere in my code, I have to include openGL libraries pretty much everywhere. Should I use glm:tmat4x4 or will regular glm::mat4x4 be fine? When coding transformations, can I use regular float to define position vector in transformation and then construct glm:tmat4x4 with it and be sure that openGL won't get surprised?

These are just some of many questions.

Does the compilers float get cast the properly to GLfloat when passing it to a function that injects the data into openGL?

This applies to any openGL typedef.

The main question is, is there a way to make a clean cut between float and GLfloat (or any other compiler-openGL type pair) and safely use the regular type in my code and then cast it into openGL type right before it gets introduced to openGL?

How can I use regular one in most of my code and the openGL one in the core parts that personally deal with openGL, while having the guarantee that behavior will be consistent on different platforms, regardless of their float implementation (or any other type)?

\$\endgroup\$
1
\$\begingroup\$

The reason why the GL types exist is for portability across different hardware architectures; table 2.2 of the GL 4.5 core profile specification (it's likely the same table number in other versions) describes the data types, their names and their sizes (in bits). The gl.h that comes with your platform(s) contains the actual typedefs.

GL types are not C types. Thus, for example, GL type int is referred to as GLint outside this document, and is not necessarily equivalent to the C type int. An implementation must use exactly the number of bits indicated in the table to represent a GL type.

In this way, wherever you see for example GLint you know that the data type being used is a 32-bit "Signed two’s complement binary integer"; likewise for other types.

What this means for your code is that so long as you use the correct equivalent data type, you don't need to worry about percolating the OpenGL types further up your code.

For the GLint example, if you know that you're only going to run on platforms where int is equivalent, then you can use int. Otherwise you should use a more explicit type, such as int32_t.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.