Re: [AD] shader deferred sets

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


On 03/01/2013 05:51 PM, Peter Wang wrote:
So, in all, would al_set_shader_* implicitly changing the current
program object cause trouble for anyone?

I'm not clear on what the motivation to remove this feature is. On the face of it (and just looking at the API) is seems convenient and intuitive to be able to set uniforms without affecting the value of the current shader.

If the concern is the memory allocation then there can be a trivial (and ultimately necessary) optimization to bypass the deferred sets when the relevant shader is in use. It is necessary because currently deferred sets do not function when the shader is in use (in the sense that they don't apply until you call al_use_shader again). The solution is to not defer the sets when the shader is in use, which coincidentally takes care the memory allocation issue.

If we want to remove this feature, then I would alter the API to remove any sort of intuition that you can modify the shader uniforms without using the shader. I'd introduce a global value of the current shader (we already have it for HLSL and OpenGL will also need one to fix the issues current API/functionality). Then the al_set_shader_* API will lose it's shader parameter, and al_use_shader (as it exists today) will be gone. I.e. you'd use the shaders like this:

al_use_shader(shader_A);
al_set_shader_int("my_uniform", 5);
al_use_shader(shader_B);
al_set_shader_int("my_uniform", 5);

This way the global state changes are explicit and it's absolutely clear that you cannot change uniforms without first changing the current shader. I find it better than these two pieces of code (with the current API but no deferred sets) yielding different effects:

al_set_shader_int(shader_A, "my_uniform", 5);
al_set_shader_int(shader_B, "my_uniform", 5);
al_draw_bitmap(bmp, 0, 0, 0);

vs

al_set_shader_int(shader_B, "my_uniform", 5);
al_set_shader_int(shader_A, "my_uniform", 5);
al_draw_bitmap(bmp, 0, 0, 0);

Personally, though, I find deferred sets to result in the best API of the 3 alternatives.

-SL





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