uniforms.h revision 9516182e80d5a21ab402c9b2cbe9e6c46e5bb1d8
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
31struct gl_program;
32struct _glapi_table;
33
34extern void GLAPIENTRY
35_mesa_Uniform1fARB(GLint, GLfloat);
36
37extern void GLAPIENTRY
38_mesa_Uniform2fARB(GLint, GLfloat, GLfloat);
39
40extern void GLAPIENTRY
41_mesa_Uniform3fARB(GLint, GLfloat, GLfloat, GLfloat);
42
43extern void GLAPIENTRY
44_mesa_Uniform4fARB(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
45
46extern void GLAPIENTRY
47_mesa_Uniform1iARB(GLint, GLint);
48
49extern void GLAPIENTRY
50_mesa_Uniform2iARB(GLint, GLint, GLint);
51
52extern void GLAPIENTRY
53_mesa_Uniform3iARB(GLint, GLint, GLint, GLint);
54
55extern void GLAPIENTRY
56_mesa_Uniform4iARB(GLint, GLint, GLint, GLint, GLint);
57
58extern void GLAPIENTRY
59_mesa_Uniform1fvARB(GLint, GLsizei, const GLfloat *);
60
61extern void GLAPIENTRY
62_mesa_Uniform2fvARB(GLint, GLsizei, const GLfloat *);
63
64extern void GLAPIENTRY
65_mesa_Uniform3fvARB(GLint, GLsizei, const GLfloat *);
66
67extern void GLAPIENTRY
68_mesa_Uniform4fvARB(GLint, GLsizei, const GLfloat *);
69
70extern void GLAPIENTRY
71_mesa_Uniform1ivARB(GLint, GLsizei, const GLint *);
72
73extern void GLAPIENTRY
74_mesa_Uniform2ivARB(GLint, GLsizei, const GLint *);
75
76extern void GLAPIENTRY
77_mesa_Uniform3ivARB(GLint, GLsizei, const GLint *);
78
79extern void GLAPIENTRY
80_mesa_Uniform4ivARB(GLint, GLsizei, const GLint *);
81
82extern void GLAPIENTRY
83_mesa_Uniform1ui(GLint location, GLuint v0);
84
85extern void GLAPIENTRY
86_mesa_Uniform2ui(GLint location, GLuint v0, GLuint v1);
87
88extern void GLAPIENTRY
89_mesa_Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2);
90
91extern void GLAPIENTRY
92_mesa_Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
93
94extern void GLAPIENTRY
95_mesa_Uniform1uiv(GLint location, GLsizei count, const GLuint *value);
96
97extern void GLAPIENTRY
98_mesa_Uniform2uiv(GLint location, GLsizei count, const GLuint *value);
99
100extern void GLAPIENTRY
101_mesa_Uniform3uiv(GLint location, GLsizei count, const GLuint *value);
102
103extern void GLAPIENTRY
104_mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value);
105
106
107extern void GLAPIENTRY
108_mesa_UniformMatrix2fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
109
110extern void GLAPIENTRY
111_mesa_UniformMatrix3fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
112
113extern void GLAPIENTRY
114_mesa_UniformMatrix4fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
115
116extern void GLAPIENTRY
117_mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
118                         const GLfloat *value);
119
120extern void GLAPIENTRY
121_mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
122                         const GLfloat *value);
123
124extern void GLAPIENTRY
125_mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
126                         const GLfloat *value);
127
128extern void GLAPIENTRY
129_mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
130                         const GLfloat *value);
131
132extern void GLAPIENTRY
133_mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
134                         const GLfloat *value);
135
136extern void GLAPIENTRY
137_mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
138                         const GLfloat *value);
139
140
141extern void GLAPIENTRY
142_mesa_GetActiveUniformARB(GLhandleARB, GLuint, GLsizei, GLsizei *,
143                          GLint *, GLenum *, GLcharARB *);
144
145extern void GLAPIENTRY
146_mesa_GetUniformfvARB(GLhandleARB, GLint, GLfloat *);
147
148extern void GLAPIENTRY
149_mesa_GetnUniformfvARB(GLhandleARB, GLint, GLsizei, GLfloat *);
150
151extern void GLAPIENTRY
152_mesa_GetUniformivARB(GLhandleARB, GLint, GLint *);
153
154extern void GLAPIENTRY
155_mesa_GetnUniformivARB(GLhandleARB, GLint, GLsizei, GLint *);
156
157extern void GLAPIENTRY
158_mesa_GetUniformuiv(GLhandleARB, GLint, GLuint *);
159
160extern void GLAPIENTRY
161_mesa_GetnUniformuivARB(GLhandleARB, GLint, GLsizei, GLuint *);
162
163extern void GLAPIENTRY
164_mesa_GetUniformdv(GLhandleARB, GLint, GLdouble *);
165
166extern void GLAPIENTRY
167_mesa_GetnUniformdvARB(GLhandleARB, GLint, GLsizei, GLdouble *);
168
169extern GLint GLAPIENTRY
170_mesa_GetUniformLocationARB(GLhandleARB, const GLcharARB *);
171
172GLint
173_mesa_get_uniform_location(struct gl_context *ctx, struct gl_shader_program *shProg,
174			   const GLchar *name);
175
176void
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
181void
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
187void
188_mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
189		  GLsizei bufSize, GLenum returnType, GLvoid *paramsOut);
190
191extern void
192_mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage *uni,
193					   unsigned array_index,
194					   unsigned count);
195
196extern void
197_mesa_update_shader_textures_used(struct gl_program *prog);
198
199
200extern void
201_mesa_init_shader_uniform_dispatch(struct _glapi_table *exec);
202
203extern const struct gl_program_parameter *
204get_uniform_parameter(struct gl_shader_program *shProg, GLint index);
205
206struct gl_builtin_uniform_element {
207   const char *field;
208   int tokens[STATE_LENGTH];
209   int swizzle;
210};
211
212struct gl_builtin_uniform_desc {
213   const char *name;
214   struct gl_builtin_uniform_element *elements;
215   unsigned int num_elements;
216};
217
218extern const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[];
219
220/**
221 * \name GLSL uniform arrays and structs require special handling.
222 *
223 * The GL_ARB_shader_objects spec says that if you use
224 * glGetUniformLocation to get the location of an array, you CANNOT
225 * access other elements of the array by adding an offset to the
226 * returned location.  For example, you must call
227 * glGetUniformLocation("foo[16]") if you want to set the 16th element
228 * of the array with glUniform().
229 *
230 * HOWEVER, some other OpenGL drivers allow accessing array elements
231 * by adding an offset to the returned array location.  And some apps
232 * seem to depend on that behaviour.
233 *
234 * Mesa's gl_uniform_list doesn't directly support this since each
235 * entry in the list describes one uniform variable, not one uniform
236 * element.  We could insert dummy entries in the list for each array
237 * element after [0] but that causes complications elsewhere.
238 *
239 * We solve this problem by encoding two values in the location that's
240 * returned by glGetUniformLocation():
241 *  a) index into gl_uniform_list::Uniforms[] for the uniform
242 *  b) an array/field offset (0 for simple types)
243 *
244 * These two values are encoded in the high and low halves of a GLint.
245 * By putting the uniform number in the high part and the offset in the
246 * low part, we can support the unofficial ability to index into arrays
247 * by adding offsets to the location value.
248 */
249/*@{*/
250/**
251 * Combine the uniform's base location and the offset
252 */
253static inline GLint
254_mesa_uniform_merge_location_offset(unsigned base_location, unsigned offset)
255{
256   return (base_location << 16) | offset;
257}
258
259/**
260 * Separate the uniform base location and parameter offset
261 */
262static inline void
263_mesa_uniform_split_location_offset(GLint location, unsigned *base_location,
264				    unsigned *offset)
265{
266   *offset = location & 0xffff;
267   *base_location = location >> 16;
268}
269/*@}*/
270
271#endif /* UNIFORMS_H */
272