[AD] GLSL #version

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Right now we have a slight issue with our shader API. The root problem comes from the fact that GLSL and GLES SL are different languages... it is generally not the case that you can send use the same code for desktop OpenGL and for OpenGL ES. Many differences can be abstracted away via #ifdef GL_ES/#endif, but not all of them. In particular, the #version statement cannot be placed inside a pre-processor block, which means that it is impossible to use the same source file for both versions of OpenGL (they have different sets of valid #version numbers).

OpenGL API solves this by allowing you to specify multiple sources of code to send to the GPU. I.e. they solve the problem by requiring you to write something like this:

const char **gl_code = {"#version 110\n", shader_source};
const char **gles_code = {"#version 100\n", shader_source};
glShaderSource(handle, 2, use_gles ? gles_code : gl_code, NULL);

Our API does not allow that (the main culprit is al_attach_shader_source_file). I don't necessarily think we should take the same route (especially since these hacks are not needed for HLSL). I propose letting Allegro pre-process the shader source and expand a special macro:

#define ALLEGRO_GLSL_VERSION(gl_version, gles_version) \
#ifdef GL_ES \
	#version gles_version \
#else \
	#version gl_version \
#endif

The user would then place that macro at the top of their shader source file and it'd do the right thing.

-SL




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/