[AD] shader deferred sets

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


I just ran into an issue where I tried to pass a local float[] to al_set_shader_float_vector and then later call al_use_shader(). Luckily (?) my program didn't crash but the shader got garbage data for the uniform I was trying to set. Whats the point of deferred sets again? I can't see it at the moment, but if there is one then can there also be an API that has an immediate affect. Right now I just call al_set_shader_float_vector immediately followed by al_use_shader and that works.

void draw(){
  setup_shader_vec4(my_shader, "x", 1, 1, 1, 1);
  al_use_shader(my_shader);
  al_draw();
}

void setup_shader_vec4(ALLEGRO_SHADER * shader, char * name, float v1, float v2, float v3, float v4){
  float vector[4] = {v1, v2, v3, v4};
  al_set_shader_float_vector(shader, name, 4, &vector[0], 1);
  // al_use_shader(shader); // to have an immediate affect
}

The reason this code doesn't work of course is that the deferred set gets the pointer &vector[0] without copying its contents.




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