1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
.\" Automatically generated by Pandoc 1.19.2.4
.\"
.TH "al_attach_shader_source" "3" "" "Allegro reference manual" ""
.hy
.SH NAME
.PP
al_attach_shader_source \- Allegro 5 API
.SH SYNOPSIS
.IP
.nf
\f[C]
#include\ <allegro5/allegro.h>
bool\ al_attach_shader_source(ALLEGRO_SHADER\ *shader,\ ALLEGRO_SHADER_TYPE\ type,
\ \ \ \ const\ char\ *source)
\f[]
.fi
.SH DESCRIPTION
.PP
Attaches the shader\[aq]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(3) if you prefer to obtain your
shader source from an external file.
.PP
If you do not use ALLEGRO_PROGRAMMABLE_PIPELINE Allegro\[aq]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\[aq]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
.B al_projview_matrix
matrix for Allegro\[aq]s orthographic projection multiplied by the
al_use_transform(3) matrix.
The type is \f[C]mat4\f[] in GLSL, and \f[C]float4x4\f[] in HLSL.
.RS
.RE
.TP
.B al_use_tex
whether or not to use the bound texture.
The type is \f[C]bool\f[] in both GLSL and HLSL.
.RS
.RE
.TP
.B al_tex
the texture if one is bound.
The type is \f[C]sampler2D\f[] in GLSL and \f[C]texture\f[] in HLSL.
.RS
.RE
.TP
.B al_use_tex_matrix
whether or not to use a texture matrix (used by the primitives addon).
The type is \f[C]bool\f[] in both GLSL and HLSL.
.RS
.RE
.TP
.B 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[] in GLSL, and \f[C]float4x4\f[] in HLSL.
.RS
.RE
.PP
With GLSL alpha testing is done in the shader and uses these additional
uniforms:
.TP
.B 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[] and
\f[C]al_alpha_test_val\f[].
.RS
.RE
.TP
.B al_alpha_func
The alpha testing function used.
One of the ALLEGRO_RENDER_FUNCTION(3) values.
The default is ALLEGRO_RENDER_ALWAYS which means all pixels (even
completely transparent ones) are rendered.
The type is \f[C]int\f[].
See ALLEGRO_RENDER_STATE(3).
.RS
.RE
.TP
.B 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[].
.RS
.RE
.PP
For GLSL shaders the vertex attributes are passed using the following
variables:
.TP
.B al_pos
vertex position attribute.
Type is \f[C]vec4\f[].
.RS
.RE
.TP
.B al_texcoord
vertex texture coordinate attribute.
Type is \f[C]vec2\f[].
.RS
.RE
.TP
.B al_color
vertex color attribute.
Type is \f[C]vec4\f[].
.RS
.RE
.TP
.B al_user_attr_0
The vertex attribute declared as ALLEGRO_PRIM_USER_ATTR
.RS
.RE
.TP
.B 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
.RS
.RE
.PP
For HLSL shaders the vertex attributes are passed using the following
semantics:
.TP
.B POSITION0
vertex position attribute.
Type is \f[C]float4\f[].
.RS
.RE
.TP
.B TEXCOORD0
vertex texture coordinate attribute.
Type is \f[C]float2\f[].
.RS
.RE
.TP
.B TEXCOORD1
vertex color attribute.
Type is \f[C]float4\f[].
.RS
.RE
.PP
Also, each shader variable has a corresponding macro name that can be
used when defining the shaders using string literals.
Don\[aq]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 "al_projview_matrix"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_POS for "al_pos"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_COLOR for "al_color"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_TEXCOORD for "al_texcoord"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_USE_TEX for "al_use_tex"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_TEX for "al_tex"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_USE_TEX_MATRIX for "al_use_tex_matrix"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_TEX_MATRIX for "al_tex_matrix"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_ALPHA_FUNCTION for "al_alpha_func"
.IP \[bu] 2
ALLEGRO_SHADER_VAR_ALPHA_TEST_VALUE for "al_alpha_test_val"
.PP
Examine the output of al_get_default_shader_source(3) 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(3).
.SH SINCE
.PP
5.1.0
.SH SEE ALSO
.PP
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)
|