al_attach_shader_source(3)
π NAME π
okay so this is al_attach_shader_source(3) from the Allegro reference manual, and it's literally the attach + compile a shader source page bestie β¨
al_attach_shader_source β Allegro 5 API.
β¨ SYNOPSIS β¨
#include <allegro5/allegro.h>
bool al_attach_shader_source(ALLEGRO_SHADER *shader, ALLEGRO_SHADER_TYPE type,
const char *source)
π¦ DESCRIPTION π¦
Okay so what this function does: it attaches the shader's source code to the shader object and compiles it. Slay. π
If you pass NULL, it deletes the underlying (OpenGL or DirectX) shader. Also, if you'd rather grab your shader source from an external file, see al_attach_shader_source_file(3) β that's the file-based bestie.
If you do not use ALLEGRO_PROGRAMMABLE_PIPELINE, Allegro's graphics functions will not use any shader specific functions themselves. And in case of a system with no fixed function pipeline (like OpenGL ES 2 or OpenGL 3 or 4), this means Allegro's drawing functions cannot be used. Like... cannot. π
TODO: Is ALLEGRO_PROGRAMMABLE_PIPELINE set automatically in this case?
π«Ά the uniform situation when ALLEGRO_PROGRAMMABLE_PIPELINE is on
When ALLEGRO_PROGRAMMABLE_PIPELINE is used, the following shader uniforms are provided by Allegro and can be accessed in your shaders:
al_projview_matrixβ matrix for Allegro's orthographic projection multiplied by theal_use_transform(3)matrix. The type ismat4in GLSL, andfloat4x4in HLSL.al_use_texβ whether or not to use the bound texture. The type isboolin both GLSL and HLSL.al_texβ the texture if one is bound. The type issampler2Din GLSL andtexturein HLSL.al_use_tex_matrixβ whether or not to use a texture matrix (used by the primitives addon). The type isboolin both GLSL and HLSL.al_tex_matrixβ the texture matrix (used by the primitives addon). Your shader should multiply the texture coordinates by this matrix. The type ismat4in GLSL, andfloat4x4in HLSL.
πΈ GLSL alpha testing extras
With GLSL, alpha testing is done in the shader and uses these additional uniforms:
al_alpha_testβ Whether to do any alpha testing. Iffalse, the shader should render the pixel, otherwise it should interpret the values ofal_alpha_funcandal_alpha_test_val.al_alpha_funcβ The alpha testing function used. One of theALLEGRO_RENDER_FUNCTION(3)values. The default isALLEGRO_RENDER_ALWAYSwhich means all pixels (even completely transparent ones) are rendered. The type isint. SeeALLEGRO_RENDER_STATE(3).al_alpha_test_valβ If alpha testing is notALLEGRO_RENDER_NEVERorALLEGRO_RENDER_ALWAYS, the alpha value to compare to for alpha testing. The type isfloat.
π GLSL vertex attributes
For GLSL shaders, the vertex attributes are passed using the following variables:
al_posβ vertex position attribute. Type isvec4.al_texcoordβ vertex texture coordinate attribute. Type isvec2.al_colorβ vertex color attribute. Type isvec4.al_user_attr_0β The vertex attribute declared asALLEGRO_PRIM_USER_ATTRal_user_attr_1, ...,al_user_attr_9β The vertex attribute declared asALLEGRO_PRIM_USER_ATTR + XwhereXis an integer from 1 to 9
π§ HLSL vertex attributes
For HLSL shaders, the vertex attributes are passed using the following semantics:
POSITION0β vertex position attribute. Type isfloat4.TEXCOORD0β vertex texture coordinate attribute. Type isfloat2.TEXCOORD1β vertex color attribute. Type isfloat4.
π macro name cheat sheet
Also, each shader variable has a corresponding macro name that can be used when defining the shaders using string literals. Do not use these macros with the other shader functions β that will lead to undefined behavior. Not cute. π
ALLEGRO_SHADER_VAR_PROJVIEW_MATRIXfor"al_projview_matrix"ALLEGRO_SHADER_VAR_POSfor"al_pos"ALLEGRO_SHADER_VAR_COLORfor"al_color"ALLEGRO_SHADER_VAR_TEXCOORDfor"al_texcoord"ALLEGRO_SHADER_VAR_USE_TEXfor"al_use_tex"ALLEGRO_SHADER_VAR_TEXfor"al_tex"ALLEGRO_SHADER_VAR_USE_TEX_MATRIXfor"al_use_tex_matrix"ALLEGRO_SHADER_VAR_TEX_MATRIXfor"al_tex_matrix"ALLEGRO_SHADER_VAR_ALPHA_FUNCTIONfor"al_alpha_func"ALLEGRO_SHADER_VAR_ALPHA_TEST_VALUEfor"al_alpha_test_val"
Examine the output of al_get_default_shader_source(3) for an example of how to use the above uniforms and attributes. Fr fr, it's the reference example. π
It returns true on success and false on error, in which case the error log is updated. The error log can be retrieved with al_get_shader_log(3). So if it fails, go check the log bestie. π«Ά
π SINCE π
5.1.0 β iconic since then. β
π SEE ALSO π
al_attach_shader_source_file(3)al_build_shader(3)al_get_default_shader_source(3)al_get_shader_log(3)ALLEGRO_PRIM_ATTR(3)
source/version: Allegro reference manual Β· date: not printed on this page β bye bestie! π«Άπ
π¦ where this page comes from
- arch rolling: allegro 5.2.11.3-2 Β· Zlib AND BSD-3-Clause AND OFL-1.1 AND LicenseRef-Custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms