[AD] Some more thoughts on the shader API

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


So after trying to use the current API some more while working on the examples I had some other ideas about simplifying it. One thing I noticed was that the default shaders were just very verbose to use. Firstly, you had to include both allegro_hlsl.h and allegro_glsl.h. Then you had to switch based on the shader platform so you could use the appropriate functions. I really didn't see a point behind making it this annoying to use the default shaders, so how about this API instead:

No more allegro_glsl.h and allegro_hlsl.h, instead these two functions are added to shader.h:

const char* al_get_default_vertex_shader(ALLEGRO_SHADER_PLATFORM platform);
const char* al_get_default_pixel_shader(ALLEGRO_SHADER_PLATFORM platform);

The relevant code is then simplified from this:

#include <allegro5/allegro_glsl.h>
#include <allegro5/allegro_hlsl.h>

...

al_attach_shader_source(shader, ALLEGRO_VERTEX_SHADER, al_get_shader_platform(shader) == ALLEGRO_SHADER_GLSL ? al_get_default_glsl_vertex_shader() : al_get_default_hlsl_vertex_shader());

al_attach_shader_source(shader, ALLEGRO_PIXEL_SHADER, al_get_shader_platform(shader) == ALLEGRO_SHADER_GLSL ? al_get_default_glsl_pixel_shader() : al_get_default_hlsl_pixel_shader());

to this:

al_attach_shader_source(shader, ALLEGRO_VERTEX_SHADER, al_get_default_vertex_shader(al_get_shader_platform(shader))); al_attach_shader_source(shader, ALLEGRO_PIXEL_SHADER, al_get_default_pixel_shader(al_get_shader_platform(shader)));

This is not including the pre-processor macros possibly involved in this (I looked into modifying the test driver to use shaders and I just balked at the mess the current API would require to support all configurations).

I think this is a worthwhile change as even if the usual use case includes people using their own shaders. Much of the time the vertex shader is unchanged and the main effect is obtained through the pixel shader only.

Also... if I'm changing this, any issues with the name of that function? No confusion with it actually returning the shader source vs the shader itself? I don't know how likely a newbie user using C would try to assign the output of those functions directly to ALLEGRO_SHADER*...

-SL




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