use FetchTexelf() in GetTexImage() to return float textures correctly
[mesa.git] / src / mesa / shader / slang_vertex_builtin.gc
1
2 //
3 // TODO:
4 // - what to do with ftransform? can it stay in the current form?
5 // - implement texture1DLod, texture2DLod, texture3DLod, textureCubeLod,
6 // - implement shadow1DLod, shadow2DLod,
7 //
8
9 //
10 // From Shader Spec, ver. 1.051
11 //
12 // Some OpenGL operations still continue to occur in fixed functionality in between the vertex
13 // processor and the fragment processor. Other OpenGL operations continue to occur in fixed
14 // functionality after the fragment processor. Shaders communicate with the fixed functionality
15 // of OpenGL through the use of built-in variables.
16 //
17 // The variable gl_Position is available only in the vertex language and is intended for writing
18 // the homogeneous vertex position. All executions of a well-formed vertex shader must write
19 // a value into this variable. It can be written at any time during shader execution. It may also
20 // be read back by the shader after being written. This value will be used by primitive assembly,
21 // clipping, culling, and other fixed functionality operations that operate on primitives after
22 // vertex processing has occurred. Compilers may generate a diagnostic message if they detect
23 // gl_Position is not written, or read before being written, but not all such cases are detectable.
24 // Results are undefined if a vertex shader is executed and does not write gl_Position.
25 //
26 // The variable gl_PointSize is available only in the vertex language and is intended for a vertex
27 // shader to write the size of the point to be rasterized. It is measured in pixels.
28 //
29 // The variable gl_ClipVertex is available only in the vertex language and provides a place for
30 // vertex shaders to write the coordinate to be used with the user clipping planes. The user must
31 // ensure the clip vertex and user clipping planes are defined in the same coordinate space. User
32 // clip planes work properly only under linear transform. It is undefined what happens under
33 // non-linear transform.
34 //
35 // These built-in vertex shader variables for communicating with fixed functionality are
36 // intrinsically declared with the following types:
37 //
38
39 vec4 gl_Position; // must be written to
40 float gl_PointSize; // may be written to
41 vec4 gl_ClipVertex; // may be written to
42
43 //
44 // If gl_PointSize or gl_ClipVertex are not written to, their values are undefined. Any of these
45 // variables can be read back by the shader after writing to them, to retrieve what was written.
46 // Reading them before writing them results in undefined behavior. If they are written more than
47 // once, it is the last value written that is consumed by the subsequent operations.
48 //
49 // These built-in variables have global scope.
50 //
51
52 //
53 // The following attribute names are built into the OpenGL vertex language and can be used from
54 // within a vertex shader to access the current values of attributes declared by OpenGL. All page
55 // numbers and notations are references to the OpenGL 1.4 specification.
56 //
57
58 //
59 // Vertex Attributes, p. 19.
60 //
61
62 attribute vec4 gl_Color;
63 attribute vec4 gl_SecondaryColor;
64 attribute vec3 gl_Normal;
65 attribute vec4 gl_Vertex;
66 attribute vec4 gl_MultiTexCoord0;
67 attribute vec4 gl_MultiTexCoord1;
68 attribute vec4 gl_MultiTexCoord2;
69 attribute vec4 gl_MultiTexCoord3;
70 attribute vec4 gl_MultiTexCoord4;
71 attribute vec4 gl_MultiTexCoord5;
72 attribute vec4 gl_MultiTexCoord6;
73 attribute vec4 gl_MultiTexCoord7;
74 attribute float gl_FogCoord;
75
76 //
77 // Unlike user-defined varying variables, the built-in varying variables don\92t have a strict
78 // one-to-one correspondence between the vertex language and the fragment language. Two sets are
79 // provided, one for each language. Their relationship is described below.
80 //
81 // The following built-in varying variables are available to write to in a vertex shader.
82 // A particular one should be written to if any functionality in a corresponding fragment shader
83 // or fixed pipeline uses it or state derived from it. Otherwise, behavior is undefined.
84 //
85
86 varying vec4 gl_FrontColor;
87 varying vec4 gl_BackColor;
88 varying vec4 gl_FrontSecondaryColor;
89 varying vec4 gl_BackSecondaryColor;
90 varying vec4 gl_TexCoord[]; // at most will be gl_MaxTextureCoordsARB
91 varying float gl_FogFragCoord;
92
93 //
94 // For gl_FogFragCoord, the value written will be used as the \93c\94 value on page 160 of the
95 // OpenGL 1.4 Specification by the fixed functionality pipeline. For example, if the z-coordinate
96 // of the fragment in eye space is desired as \93c\94, then that's what the vertex shader should write
97 // into gl_FogFragCoord.
98 //
99 // As with all arrays, indices used to subscript gl_TexCoord must either be integral constant
100 // expressions, or this array must be re-declared by the shader with a size. The size can be
101 // at most gl_MaxTextureCoordsARB. Using indexes close to 0 may aid the implementation
102 // in preserving varying resources.
103 //
104
105 //
106 // The OpenGL Shading Language defines an assortment of built-in convenience functions for scalar
107 // and vector operations. Many of these built-in functions can be used in more than one type
108 // of shader, but some are intended to provide a direct mapping to hardware and so are available
109 // only for a specific type of shader.
110 //
111 // The built-in functions basically fall into three categories:
112 //
113 // \95 They expose some necessary hardware functionality in a convenient way such as accessing
114 // a texture map. There is no way in the language for these functions to be emulated by a shader.
115 //
116 // \95 They represent a trivial operation (clamp, mix, etc.) that is very simple for the user
117 // to write, but they are very common and may have direct hardware support. It is a very hard
118 // problem for the compiler to map expressions to complex assembler instructions.
119 //
120 // \95 They represent an operation graphics hardware is likely to accelerate at some point. The
121 // trigonometry functions fall into this category.
122 //
123 // Many of the functions are similar to the same named ones in common C libraries, but they support
124 // vector input as well as the more traditional scalar input.
125 //
126 // Applications should be encouraged to use the built-in functions rather than do the equivalent
127 // computations in their own shader code since the built-in functions are assumed to be optimal
128 // (e.g., perhaps supported directly in hardware).
129 //
130 // User code can replace built-in functions with their own if they choose, by simply re-declaring
131 // and defining the same name and argument list.
132 //
133
134 //
135 // Geometric Functions
136 //
137 // These operate on vectors as vectors, not component-wise.
138 //
139
140 //
141 // For vertex shaders only. This function will ensure that the incoming vertex value will be
142 // transformed in a way that produces exactly the same result as would be produced by OpenGL\92s
143 // fixed functionality transform. It is intended to be used to compute gl_Position, e.g.,
144 // gl_Position = ftransform()
145 // This function should be used, for example, when an application is rendering the same geometry in
146 // separate passes, and one pass uses the fixed functionality path to render and another pass uses
147 // programmable shaders.
148 //
149
150 vec4 ftransform () {
151 return gl_ModelViewProjectionMatrix * gl_Vertex;
152 }
153
154 //
155 // Texture Lookup Functions
156 //
157 // Texture lookup functions are available to both vertex and fragment shaders. However, level
158 // of detail is not computed by fixed functionality for vertex shaders, so there are some
159 // differences in operation between vertex and fragment texture lookups. The functions in the table
160 // below provide access to textures through samplers, as set up through the OpenGL API. Texture
161 // properties such as size, pixel format, number of dimensions, filtering method, number of mip-map
162 // levels, depth comparison, and so on are also defined by OpenGL API calls. Such properties are
163 // taken into account as the texture is accessed via the built-in functions defined below.
164 //
165 // If a non-shadow texture call is made to a sampler whose texture has depth comparisons enabled,
166 // then results are undefined. If a shadow texture call is made to a sampler whose texture does not
167 // have depth comparisions enabled, the results are also undefined.
168 //
169 // In all functions below, the bias parameter is optional for fragment shaders. The bias parameter
170 // is not accepted in a vertex shader. For a fragment shader, if bias is present, it is added to
171 // the calculated level of detail prior to performing the texture access operation. If the bias
172 // parameter is not provided, then the implementation automatically selects level of detail:
173 // For a texture that is not mip-mapped, the texture is used directly. If it is mip-mapped and
174 // running in a fragment shader, the LOD computed by the implementation is used to do the texture
175 // lookup. If it is mip-mapped and running on the vertex shader, then the base texture is used.
176 //
177 // The built-ins suffixed with \93Lod\94 are allowed only in a vertex shader. For the \93Lod\94 functions,
178 // lod is directly used as the level of detail.
179 //
180
181 //
182 // Use the texture coordinate coord to do a texture lookup in the 1D texture currently bound
183 // to sampler. For the projective (\93Proj\94) versions, the texture coordinate coord.s is divided by
184 // the last component of coord.
185 //
186 // XXX
187 vec4 texture1DLod (sampler1D sampler, float coord, float lod) {
188 return vec4 (0.0);
189 }
190 vec4 texture1DProjLod (sampler1D sampler, vec2 coord, float lod) {
191 return texture1DLod (sampler, coord.s / coord.t, lod);
192 }
193 vec4 texture1DProjLod (sampler1D sampler, vec4 coord, float lod) {
194 return texture1DLod (sampler, coord.s / coord.q, lod);
195 }
196
197 //
198 // Use the texture coordinate coord to do a texture lookup in the 2D texture currently bound
199 // to sampler. For the projective (\93Proj\94) versions, the texture coordinate (coord.s, coord.t) is
200 // divided by the last component of coord. The third component of coord is ignored for the vec4
201 // coord variant.
202 //
203 // XXX
204 vec4 texture2DLod (sampler2D sampler, vec2 coord, float lod) {
205 return vec4 (0.0);
206 }
207 vec4 texture2DProjLod (sampler2D sampler, vec3 coord, float lod) {
208 return texture2DLod (sampler, vec2 (coord.s / coord.p, coord.t / coord.p), lod);
209 }
210 vec4 texture2DProjLod (sampler2D sampler, vec4 coord, float lod) {
211 return texture2DLod (sampler, vec2 (coord.s / coord.q, coord.t / coord.q), lod);
212 }
213
214 //
215 // Use the texture coordinate coord to do a texture lookup in the 3D texture currently bound
216 // to sampler. For the projective (\93Proj\94) versions, the texture coordinate is divided by coord.q.
217 //
218 // XXX
219 vec4 texture3DLod (sampler3D sampler, vec3 coord, float lod) {
220 return vec4 (0.0);
221 }
222 vec4 texture3DProjLod (sampler3D sampler, vec4 coord, float lod) {
223 return texture3DLod (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.s / coord.q),
224 lod);
225 }
226
227 //
228 // Use the texture coordinate coord to do a texture lookup in the cube map texture currently bound
229 // to sampler. The direction of coord is used to select which face to do a 2-dimensional texture
230 // lookup in, as described in section 3.8.6 in version 1.4 of the OpenGL specification.
231 //
232 // XXX
233 vec4 textureCubeLod (samplerCube sampler, vec3 coord, float lod) {
234 return vec4 (0.0);
235 }
236
237 //
238 // Use texture coordinate coord to do a depth comparison lookup on the depth texture bound
239 // to sampler, as described in section 3.8.14 of version 1.4 of the OpenGL specification. The 3rd
240 // component of coord (coord.p) is used as the R value. The texture bound to sampler must be a
241 // depth texture, or results are undefined. For the projective (\93Proj\94) version of each built-in,
242 // the texture coordinate is divide by coord.q, giving a depth value R of coord.p/coord.q. The
243 // second component of coord is ignored for the \931D\94 variants.
244 //
245 // XXX
246 vec4 shadow1DLod (sampler1DShadow sampler, vec3 coord, float lod) {
247 return vec4 (0.0);
248 }
249 // XXX
250 vec4 shadow2DLod (sampler2DShadow sampler, vec3 coord, float lod) {
251 return vec4 (0.0);
252 }
253 vec4 shadow1DProjLod(sampler1DShadow sampler, vec4 coord, float lod) {
254 return shadow1DLod (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q), lod);
255 }
256 vec4 shadow2DProjLod(sampler2DShadow sampler, vec4 coord, float lod) {
257 return shadow2DLod (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q),
258 lod);
259 }
260