1al_attach_shader_source(3)                          al_attach_shader_source(3)
2
3
4

NAME

6       al_attach_shader_source - Allegro 5 API
7

SYNOPSIS

9              #include <allegro5/allegro.h>
10
11              bool al_attach_shader_source(ALLEGRO_SHADER *shader, ALLEGRO_SHADER_TYPE type,
12                  const char *source)
13

DESCRIPTION

15       Attaches the shader’s source code to the shader object and compiles it.
16       Passing NULL deletes the underlying (OpenGL or  DirectX)  shader.   See
17       also al_attach_shader_source_file(3) if you prefer to obtain your shad‐
18       er source from an external file.
19
20       If you do  not  use  ALLEGRO_PROGRAMMABLE_PIPELINE  Allegro’s  graphics
21       functions  will  not  use any shader specific functions themselves.  In
22       case of a system with no fixed function pipeline (like OpenGL ES  2  or
23       OpenGL 3 or 4) this means Allegro’s drawing functions cannot be used.
24
25       TODO: Is ALLEGRO_PROGRAMMABLE_PIPELINE set automatically in this case?
26
27       When  ALLEGRO_PROGRAMMABLE_PIPELINE  is  used the following shader uni‐
28       forms are provided by Allegro and can be accessed in your shaders:
29
30       al_projview_matrix
31              matrix for Allegro’s orthographic projection multiplied  by  the
32              al_use_transform(3)  matrix.   The  type  is  mat4  in GLSL, and
33              float4x4 in HLSL.
34
35       al_use_tex
36              whether or not to use the bound texture.  The type  is  bool  in
37              both GLSL and HLSL.
38
39       al_tex the  texture if one is bound.  The type is sampler2D in GLSL and
40              texture in HLSL.
41
42       al_use_tex_matrix
43              whether or not to use a texture matrix (used by  the  primitives
44              addon).  The type is bool in both GLSL and HLSL.
45
46       al_tex_matrix
47              the  texture matrix (used by the primitives addon).  Your shader
48              should multiply the texture coordinates  by  this  matrix.   The
49              type is mat4 in GLSL, and float4x4 in HLSL.
50
51       With GLSL alpha testing is done in the shader and uses these additional
52       uniforms:
53
54       al_alpha_test
55              Whether to do any alpha testing.  If false,  the  shader  should
56              render  the  pixel,  otherwise it should interpret the values of
57              al_alpha_func and al_alpha_test_val.
58
59       al_alpha_func
60              The alpha  testing  function  used.   One  of  the  ALLEGRO_REN‐
61              DER_FUNCTION(3)  values.   The  default is ALLEGRO_RENDER_ALWAYS
62              which means all pixels (even completely  transparent  ones)  are
63              rendered.  The type is int.  See ALLEGRO_RENDER_STATE(3).
64
65       al_alpha_test_val
66              If  alpha  testing  is  not ALLEGRO_RENDER_NEVER or ALLEGRO_REN‐
67              DER_ALWAYS the alpha value to compare to for alpha testing.  The
68              type is float.
69
70       For  GLSL  shaders the vertex attributes are passed using the following
71       variables:
72
73       al_pos vertex position attribute.  Type is vec4.
74
75       al_texcoord
76              vertex texture coordinate attribute.  Type is vec2.
77
78       al_color
79              vertex color attribute.  Type is vec4.
80
81       al_user_attr_0
82              The vertex attribute declared as ALLEGRO_PRIM_USER_ATTR
83
84       al_user_attr_1, ..., al_user_attr_9
85              The vertex attribute  declared  as  ALLEGRO_PRIM_USER_ATTR  +  X
86              where X is an integer from 1 to 9
87
88       For  HLSL  shaders the vertex attributes are passed using the following
89       semantics:
90
91       POSITION0
92              vertex position attribute.  Type is float4.
93
94       TEXCOORD0
95              vertex texture coordinate attribute.  Type is float2.
96
97       TEXCOORD1
98              vertex color attribute.  Type is float4.
99
100       Also, each shader variable has a corresponding macro name that  can  be
101       used  when defining the shaders using string literals.  Don’t use these
102       macros with the other shader functions as that will lead  to  undefined
103       behavior.
104
105       • ALLEGRO_SHADER_VAR_PROJVIEW_MATRIX for “al_projview_matrix”
106
107       • ALLEGRO_SHADER_VAR_POS for “al_pos”
108
109       • ALLEGRO_SHADER_VAR_COLOR for “al_color”
110
111       • ALLEGRO_SHADER_VAR_TEXCOORD for “al_texcoord”
112
113       • ALLEGRO_SHADER_VAR_USE_TEX for “al_use_tex”
114
115       • ALLEGRO_SHADER_VAR_TEX for “al_tex”
116
117       • ALLEGRO_SHADER_VAR_USE_TEX_MATRIX for “al_use_tex_matrix”
118
119       • ALLEGRO_SHADER_VAR_TEX_MATRIX for “al_tex_matrix”
120
121       • ALLEGRO_SHADER_VAR_ALPHA_FUNCTION for “al_alpha_func”
122
123       • ALLEGRO_SHADER_VAR_ALPHA_TEST_VALUE for “al_alpha_test_val”
124
125       Examine the output of al_get_default_shader_source(3) for an example of
126       how to use the above uniforms and attributes.
127
128       Returns true on success and false on error, in which case the error log
129       is updated.  The error log can be retrieved with al_get_shader_log(3).
130

SINCE

132       5.1.0
133

SEE ALSO

135       al_attach_shader_source_file(3),     al_build_shader(3),     al_get_de‐
136       fault_shader_source(3), al_get_shader_log(3), ALLEGRO_PRIM_ATTR(3)
137
138
139
140Allegro reference manual                            al_attach_shader_source(3)
Impressum