File: al_attach_shader_source.3

package info (click to toggle)
allegro5 2%3A5.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 23,032 kB
  • sloc: ansic: 120,340; cpp: 15,707; objc: 4,805; python: 2,915; java: 2,195; sh: 887; xml: 86; makefile: 49; perl: 37; pascal: 24
file content (141 lines) | stat: -rw-r--r-- 3,611 bytes parent folder | download
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
.TH "al_attach_shader_source" "3" "" "Allegro reference manual" ""
.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
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
.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"
.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)