Reputation: 3941
I'm working with a codebase that supports OpenGL and OpenGL ES.
Is there any GLES define I can use to write conditional code in C? Something like:
#include <GLES/gl.h>
#ifdef __GLES
//
#else
//
#endif
Upvotes: 2
Views: 893
Reputation: 5797
For conditional compilation of GLSL shaders, there is GL_ES
. The GLSL ES 1.00 specification defines under section 3.4 "Preprocessor":
The following predefined macros are available
__LINE__
__FILE__
__VERSION__
GL_ES
GL_ES
will be defined and set to 1. This is not true for the non-ES OpenGL Shading Language, so it can be used to do a compile time test to see whether a shader is running on ES.
So you can check for GL_ES
in shaders.
If you want to know whether any particular C file is being compiled in a project for a particular version of OpenGL ES, then you can use the defines from GLES/gl.h
, GLES2/gl2.h
, GLES3/gl3.h
, GLES3/gl31.h
or GLES3/gl32.h
, which are: GL_VERSION_ES_CM_1_0
, GL_ES_VERSION_2_0
, GL_ES_VERSION_3_0
, GL_ES_VERSION_3_1
and GL_ES_VERSION_3_2
, respectively. Starting with GLES2/gl2.h
and anything above, you will always have the defines of the previous versions (up to GLES 2.0) also defined. So when you include GLES3/gl31.h
then you will find GL_ES_VERSION_2_0
, GL_ES_VERSION_3_0
and GL_ES_VERSION_3_1
to be defined.
However, you make the decision in your application whether to include the OpenGL Desktop header files or the OpenGL ES header files and you could use that same condition for conditionally compiling code that relies on you compiling for either OpenGL Desktop or OpenGL ES. So, you really don't need any pre-defined defines because you make the decision yourself earlier in the program about which header you include.
Upvotes: 3