.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "al_attach_shader_source" "3alleg5" "" "Allegro reference manual" "" .hy .SH NAME .PP al_attach_shader_source - Allegro 5 API .SH SYNOPSIS .IP .nf \f[C] #include bool al_attach_shader_source(ALLEGRO_SHADER *shader, ALLEGRO_SHADER_TYPE type, const char *source) \f[R] .fi .SH DESCRIPTION .PP Attaches the shader\[cq]s source code to the shader object and compiles it. Passing NULL deletes the underlying (OpenGL or DirectX) shader. See also al_attach_shader_source_file(3alleg5) if you prefer to obtain your shader source from an external file. .PP If you do not use ALLEGRO_PROGRAMMABLE_PIPELINE Allegro\[cq]s graphics functions will not use any shader specific functions themselves. In case of a system with no fixed function pipeline (like OpenGL ES 2 or OpenGL 3 or 4) this means Allegro\[cq]s drawing functions cannot be used. .PP TODO: Is ALLEGRO_PROGRAMMABLE_PIPELINE set automatically in this case? .PP When ALLEGRO_PROGRAMMABLE_PIPELINE is used the following shader uniforms are provided by Allegro and can be accessed in your shaders: .TP al_projview_matrix matrix for Allegro\[cq]s orthographic projection multiplied by the al_use_transform(3alleg5) matrix. The type is \f[C]mat4\f[R] in GLSL, and \f[C]float4x4\f[R] in HLSL. .TP al_use_tex whether or not to use the bound texture. The type is \f[C]bool\f[R] in both GLSL and HLSL. .TP al_tex the texture if one is bound. The type is \f[C]sampler2D\f[R] in GLSL and \f[C]texture\f[R] in HLSL. .TP al_use_tex_matrix whether or not to use a texture matrix (used by the primitives addon). The type is \f[C]bool\f[R] in both GLSL and HLSL. .TP al_tex_matrix the texture matrix (used by the primitives addon). Your shader should multiply the texture coordinates by this matrix. The type is \f[C]mat4\f[R] in GLSL, and \f[C]float4x4\f[R] in HLSL. .PP With GLSL alpha testing is done in the shader and uses these additional uniforms: .TP al_alpha_test Whether to do any alpha testing. If false, the shader should render the pixel, otherwise it should interpret the values of \f[C]al_alpha_func\f[R] and \f[C]al_alpha_test_val\f[R]. .TP al_alpha_func The alpha testing function used. One of the ALLEGRO_RENDER_FUNCTION(3alleg5) values. The default is ALLEGRO_RENDER_ALWAYS which means all pixels (even completely transparent ones) are rendered. The type is \f[C]int\f[R]. See ALLEGRO_RENDER_STATE(3alleg5). .TP al_alpha_test_val If alpha testing is not ALLEGRO_RENDER_NEVER or ALLEGRO_RENDER_ALWAYS the alpha value to compare to for alpha testing. The type is \f[C]float\f[R]. .PP For GLSL shaders the vertex attributes are passed using the following variables: .TP al_pos vertex position attribute. Type is \f[C]vec4\f[R]. .TP al_texcoord vertex texture coordinate attribute. Type is \f[C]vec2\f[R]. .TP al_color vertex color attribute. Type is \f[C]vec4\f[R]. .TP al_user_attr_0 The vertex attribute declared as ALLEGRO_PRIM_USER_ATTR .TP al_user_attr_1, \&..., al_user_attr_9 The vertex attribute declared as ALLEGRO_PRIM_USER_ATTR + X where X is an integer from 1 to 9 .PP For HLSL shaders the vertex attributes are passed using the following semantics: .TP POSITION0 vertex position attribute. Type is \f[C]float4\f[R]. .TP TEXCOORD0 vertex texture coordinate attribute. Type is \f[C]float2\f[R]. .TP TEXCOORD1 vertex color attribute. Type is \f[C]float4\f[R]. .PP Also, each shader variable has a corresponding macro name that can be used when defining the shaders using string literals. Don\[cq]t use these macros with the other shader functions as that will lead to undefined behavior. .IP \[bu] 2 ALLEGRO_SHADER_VAR_PROJVIEW_MATRIX for \[lq]al_projview_matrix\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_POS for \[lq]al_pos\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_COLOR for \[lq]al_color\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_TEXCOORD for \[lq]al_texcoord\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_USE_TEX for \[lq]al_use_tex\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_TEX for \[lq]al_tex\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_USE_TEX_MATRIX for \[lq]al_use_tex_matrix\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_TEX_MATRIX for \[lq]al_tex_matrix\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_ALPHA_FUNCTION for \[lq]al_alpha_func\[rq] .IP \[bu] 2 ALLEGRO_SHADER_VAR_ALPHA_TEST_VALUE for \[lq]al_alpha_test_val\[rq] .PP Examine the output of al_get_default_shader_source(3alleg5) for an example of how to use the above uniforms and attributes. .PP 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(3alleg5). .SH SINCE .PP 5.1.0 .SH SEE ALSO .PP al_attach_shader_source_file(3alleg5), al_build_shader(3alleg5), al_get_default_shader_source(3alleg5), al_get_shader_log(3alleg5), ALLEGRO_PRIM_ATTR(3alleg5)