al_set_shader_sampler(3alleg5)

πŸ“¦
version 5.2.11.3 Β· 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

al_set_shader_sampler πŸ’…βœ¨

okay bestie, we're in the Allegro 5 API manual, page al_set_shader_sampler(3alleg5), and honestly? this one is short but it's giving powerful. πŸŽ€


✨ SYNOPSIS ✨

#include <allegro5/allegro.h>

bool al_set_shader_sampler(const char *name,
   ALLEGRO_BITMAP *bitmap, int unit)

πŸ¦‹ DESCRIPTION πŸ¦‹

So basically: this function sets a texture sampler uniform and a texture unit for the shader that's currently on your target bitmap. πŸ‘‘

⚠️ Heads up queen: the bitmap you pass in must be a video bitmap. No exceptions, no shortcuts, no "but it worked that one time". πŸ’€

Now for the part that actually matters β€” different samplers should use different units. That's the rule. And here's why, because it's lowkey crucial:

The bitmap that gets passed to Allegro's drawing functions uses the 0th unit. So if you're planning on using the al_tex variable in your pixel shader and you've got another sampler in the mix, you gotta set that other sampler to use a unit different from 0. Periodt. 🫢

But wait, there's more (there's always more, and it's kinda iconic):

With the primitives addon, you can actually free up the 0th unit by passing NULL as the texture argument to the relevant drawing functions. 🌈 And in that case? You may set a sampler to use the 0th unit, and thus not use al_tex β€” because the al_use_tex variable will be set to false. Easy math, bestie. πŸ’–


πŸ’€ What it returns

Returns true on success. Otherwise it returns false β€” for example, if the uniform by that name does not exist in the shader. Not me getting a false back and spiralling... 😭


⭐ SINCE ⭐

5.1.0 β€” she's been here a minute, respect her legacy πŸ‘‘


πŸ‘€ SEE ALSO πŸ‘€


okay so that's the whole page, you ate it, I'm obsessed πŸ’…βœ¨ this was page al_set_shader_sampler(3alleg5) from the Allegro reference manual, and if you ever forget where you read it... that's the source, that's the version, that's the date on the tin, no cap πŸŽ€πŸ¦‹ bye bestie, go write some shaders πŸ’œ

πŸ“¦ where this page comes from