3630ad0eeb7e67499cfb13a6b442405e6b6353ab
[mesa.git] / src / mesa / main / uniforms.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010 VMware, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25 #ifndef UNIFORMS_H
26 #define UNIFORMS_H
27
28 #include "glheader.h"
29 #include "program/prog_parameter.h"
30
31 struct gl_program;
32 struct _glapi_table;
33
34 extern void GLAPIENTRY
35 _mesa_Uniform1fARB(GLint, GLfloat);
36
37 extern void GLAPIENTRY
38 _mesa_Uniform2fARB(GLint, GLfloat, GLfloat);
39
40 extern void GLAPIENTRY
41 _mesa_Uniform3fARB(GLint, GLfloat, GLfloat, GLfloat);
42
43 extern void GLAPIENTRY
44 _mesa_Uniform4fARB(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
45
46 extern void GLAPIENTRY
47 _mesa_Uniform1iARB(GLint, GLint);
48
49 extern void GLAPIENTRY
50 _mesa_Uniform2iARB(GLint, GLint, GLint);
51
52 extern void GLAPIENTRY
53 _mesa_Uniform3iARB(GLint, GLint, GLint, GLint);
54
55 extern void GLAPIENTRY
56 _mesa_Uniform4iARB(GLint, GLint, GLint, GLint, GLint);
57
58 extern void GLAPIENTRY
59 _mesa_Uniform1fvARB(GLint, GLsizei, const GLfloat *);
60
61 extern void GLAPIENTRY
62 _mesa_Uniform2fvARB(GLint, GLsizei, const GLfloat *);
63
64 extern void GLAPIENTRY
65 _mesa_Uniform3fvARB(GLint, GLsizei, const GLfloat *);
66
67 extern void GLAPIENTRY
68 _mesa_Uniform4fvARB(GLint, GLsizei, const GLfloat *);
69
70 extern void GLAPIENTRY
71 _mesa_Uniform1ivARB(GLint, GLsizei, const GLint *);
72
73 extern void GLAPIENTRY
74 _mesa_Uniform2ivARB(GLint, GLsizei, const GLint *);
75
76 extern void GLAPIENTRY
77 _mesa_Uniform3ivARB(GLint, GLsizei, const GLint *);
78
79 extern void GLAPIENTRY
80 _mesa_Uniform4ivARB(GLint, GLsizei, const GLint *);
81
82 extern void GLAPIENTRY
83 _mesa_Uniform1ui(GLint location, GLuint v0);
84
85 extern void GLAPIENTRY
86 _mesa_Uniform2ui(GLint location, GLuint v0, GLuint v1);
87
88 extern void GLAPIENTRY
89 _mesa_Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2);
90
91 extern void GLAPIENTRY
92 _mesa_Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
93
94 extern void GLAPIENTRY
95 _mesa_Uniform1uiv(GLint location, GLsizei count, const GLuint *value);
96
97 extern void GLAPIENTRY
98 _mesa_Uniform2uiv(GLint location, GLsizei count, const GLuint *value);
99
100 extern void GLAPIENTRY
101 _mesa_Uniform3uiv(GLint location, GLsizei count, const GLuint *value);
102
103 extern void GLAPIENTRY
104 _mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value);
105
106
107 extern void GLAPIENTRY
108 _mesa_UniformMatrix2fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
109
110 extern void GLAPIENTRY
111 _mesa_UniformMatrix3fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
112
113 extern void GLAPIENTRY
114 _mesa_UniformMatrix4fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
115
116 extern void GLAPIENTRY
117 _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
118 const GLfloat *value);
119
120 extern void GLAPIENTRY
121 _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
122 const GLfloat *value);
123
124 extern void GLAPIENTRY
125 _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
126 const GLfloat *value);
127
128 extern void GLAPIENTRY
129 _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
130 const GLfloat *value);
131
132 extern void GLAPIENTRY
133 _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
134 const GLfloat *value);
135
136 extern void GLAPIENTRY
137 _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
138 const GLfloat *value);
139
140
141 extern void GLAPIENTRY
142 _mesa_GetActiveUniformARB(GLhandleARB, GLuint, GLsizei, GLsizei *,
143 GLint *, GLenum *, GLcharARB *);
144
145 extern void GLAPIENTRY
146 _mesa_GetUniformfvARB(GLhandleARB, GLint, GLfloat *);
147
148 extern void GLAPIENTRY
149 _mesa_GetnUniformfvARB(GLhandleARB, GLint, GLsizei, GLfloat *);
150
151 extern void GLAPIENTRY
152 _mesa_GetUniformivARB(GLhandleARB, GLint, GLint *);
153
154 extern void GLAPIENTRY
155 _mesa_GetnUniformivARB(GLhandleARB, GLint, GLsizei, GLint *);
156
157 extern void GLAPIENTRY
158 _mesa_GetUniformuiv(GLhandleARB, GLint, GLuint *);
159
160 extern void GLAPIENTRY
161 _mesa_GetnUniformuivARB(GLhandleARB, GLint, GLsizei, GLuint *);
162
163 extern void GLAPIENTRY
164 _mesa_GetUniformdv(GLhandleARB, GLint, GLdouble *);
165
166 extern void GLAPIENTRY
167 _mesa_GetnUniformdvARB(GLhandleARB, GLint, GLsizei, GLdouble *);
168
169 extern GLint GLAPIENTRY
170 _mesa_GetUniformLocationARB(GLhandleARB, const GLcharARB *);
171
172 GLint
173 _mesa_get_uniform_location(struct gl_context *ctx, struct gl_shader_program *shProg,
174 const GLchar *name);
175
176 void
177 _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shader_program,
178 GLint location, GLsizei count,
179 const GLvoid *values, GLenum type);
180
181 void
182 _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
183 GLint cols, GLint rows,
184 GLint location, GLsizei count,
185 GLboolean transpose, const GLfloat *values);
186
187 void
188 _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
189 GLsizei bufSize, GLenum returnType, GLvoid *paramsOut);
190
191 extern void
192 _mesa_update_shader_textures_used(struct gl_program *prog);
193
194
195 extern void
196 _mesa_init_shader_uniform_dispatch(struct _glapi_table *exec);
197
198 extern const struct gl_program_parameter *
199 get_uniform_parameter(struct gl_shader_program *shProg, GLint index);
200
201 struct gl_builtin_uniform_element {
202 const char *field;
203 int tokens[STATE_LENGTH];
204 int swizzle;
205 };
206
207 struct gl_builtin_uniform_desc {
208 const char *name;
209 struct gl_builtin_uniform_element *elements;
210 unsigned int num_elements;
211 };
212
213 extern const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[];
214
215 /**
216 * \name GLSL uniform arrays and structs require special handling.
217 *
218 * The GL_ARB_shader_objects spec says that if you use
219 * glGetUniformLocation to get the location of an array, you CANNOT
220 * access other elements of the array by adding an offset to the
221 * returned location. For example, you must call
222 * glGetUniformLocation("foo[16]") if you want to set the 16th element
223 * of the array with glUniform().
224 *
225 * HOWEVER, some other OpenGL drivers allow accessing array elements
226 * by adding an offset to the returned array location. And some apps
227 * seem to depend on that behaviour.
228 *
229 * Mesa's gl_uniform_list doesn't directly support this since each
230 * entry in the list describes one uniform variable, not one uniform
231 * element. We could insert dummy entries in the list for each array
232 * element after [0] but that causes complications elsewhere.
233 *
234 * We solve this problem by encoding two values in the location that's
235 * returned by glGetUniformLocation():
236 * a) index into gl_uniform_list::Uniforms[] for the uniform
237 * b) an array/field offset (0 for simple types)
238 *
239 * These two values are encoded in the high and low halves of a GLint.
240 * By putting the uniform number in the high part and the offset in the
241 * low part, we can support the unofficial ability to index into arrays
242 * by adding offsets to the location value.
243 */
244 /*@{*/
245 /**
246 * Combine the uniform's base location and the offset
247 */
248 static inline GLint
249 _mesa_uniform_merge_location_offset(unsigned base_location, unsigned offset)
250 {
251 return (base_location << 16) | offset;
252 }
253
254 /**
255 * Separate the uniform base location and parameter offset
256 */
257 static inline void
258 _mesa_uniform_split_location_offset(GLint location, unsigned *base_location,
259 unsigned *offset)
260 {
261 *offset = location & 0xffff;
262 *base_location = location >> 16;
263 }
264 /*@}*/
265
266 #endif /* UNIFORMS_H */