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