2 * Mesa 3-D graphics library
4 * Copyright (C) 2010 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
29 #include "program/prog_parameter.h"
30 #include "../glsl/ir_uniform.h"
35 extern void GLAPIENTRY
36 _mesa_Uniform1fARB(GLint
, GLfloat
);
38 extern void GLAPIENTRY
39 _mesa_Uniform2fARB(GLint
, GLfloat
, GLfloat
);
41 extern void GLAPIENTRY
42 _mesa_Uniform3fARB(GLint
, GLfloat
, GLfloat
, GLfloat
);
44 extern void GLAPIENTRY
45 _mesa_Uniform4fARB(GLint
, GLfloat
, GLfloat
, GLfloat
, GLfloat
);
47 extern void GLAPIENTRY
48 _mesa_Uniform1iARB(GLint
, GLint
);
50 extern void GLAPIENTRY
51 _mesa_Uniform2iARB(GLint
, GLint
, GLint
);
53 extern void GLAPIENTRY
54 _mesa_Uniform3iARB(GLint
, GLint
, GLint
, GLint
);
56 extern void GLAPIENTRY
57 _mesa_Uniform4iARB(GLint
, GLint
, GLint
, GLint
, GLint
);
59 extern void GLAPIENTRY
60 _mesa_Uniform1fvARB(GLint
, GLsizei
, const GLfloat
*);
62 extern void GLAPIENTRY
63 _mesa_Uniform2fvARB(GLint
, GLsizei
, const GLfloat
*);
65 extern void GLAPIENTRY
66 _mesa_Uniform3fvARB(GLint
, GLsizei
, const GLfloat
*);
68 extern void GLAPIENTRY
69 _mesa_Uniform4fvARB(GLint
, GLsizei
, const GLfloat
*);
71 extern void GLAPIENTRY
72 _mesa_Uniform1ivARB(GLint
, GLsizei
, const GLint
*);
74 extern void GLAPIENTRY
75 _mesa_Uniform2ivARB(GLint
, GLsizei
, const GLint
*);
77 extern void GLAPIENTRY
78 _mesa_Uniform3ivARB(GLint
, GLsizei
, const GLint
*);
80 extern void GLAPIENTRY
81 _mesa_Uniform4ivARB(GLint
, GLsizei
, const GLint
*);
83 extern void GLAPIENTRY
84 _mesa_Uniform1ui(GLint location
, GLuint v0
);
86 extern void GLAPIENTRY
87 _mesa_Uniform2ui(GLint location
, GLuint v0
, GLuint v1
);
89 extern void GLAPIENTRY
90 _mesa_Uniform3ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
);
92 extern void GLAPIENTRY
93 _mesa_Uniform4ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
, GLuint v3
);
95 extern void GLAPIENTRY
96 _mesa_Uniform1uiv(GLint location
, GLsizei count
, const GLuint
*value
);
98 extern void GLAPIENTRY
99 _mesa_Uniform2uiv(GLint location
, GLsizei count
, const GLuint
*value
);
101 extern void GLAPIENTRY
102 _mesa_Uniform3uiv(GLint location
, GLsizei count
, const GLuint
*value
);
104 extern void GLAPIENTRY
105 _mesa_Uniform4uiv(GLint location
, GLsizei count
, const GLuint
*value
);
108 extern void GLAPIENTRY
109 _mesa_UniformMatrix2fvARB(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
111 extern void GLAPIENTRY
112 _mesa_UniformMatrix3fvARB(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
114 extern void GLAPIENTRY
115 _mesa_UniformMatrix4fvARB(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
117 extern void GLAPIENTRY
118 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
119 const GLfloat
*value
);
121 extern void GLAPIENTRY
122 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
123 const GLfloat
*value
);
125 extern void GLAPIENTRY
126 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
127 const GLfloat
*value
);
129 extern void GLAPIENTRY
130 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
131 const GLfloat
*value
);
133 extern void GLAPIENTRY
134 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
135 const GLfloat
*value
);
137 extern void GLAPIENTRY
138 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
139 const GLfloat
*value
);
142 extern void GLAPIENTRY
143 _mesa_GetActiveUniformARB(GLhandleARB
, GLuint
, GLsizei
, GLsizei
*,
144 GLint
*, GLenum
*, GLcharARB
*);
146 extern void GLAPIENTRY
147 _mesa_GetUniformfvARB(GLhandleARB
, GLint
, GLfloat
*);
149 extern void GLAPIENTRY
150 _mesa_GetnUniformfvARB(GLhandleARB
, GLint
, GLsizei
, GLfloat
*);
152 extern void GLAPIENTRY
153 _mesa_GetUniformivARB(GLhandleARB
, GLint
, GLint
*);
155 extern void GLAPIENTRY
156 _mesa_GetnUniformivARB(GLhandleARB
, GLint
, GLsizei
, GLint
*);
158 extern void GLAPIENTRY
159 _mesa_GetUniformuiv(GLhandleARB
, GLint
, GLuint
*);
161 extern void GLAPIENTRY
162 _mesa_GetnUniformuivARB(GLhandleARB
, GLint
, GLsizei
, GLuint
*);
164 extern void GLAPIENTRY
165 _mesa_GetUniformdv(GLhandleARB
, GLint
, GLdouble
*);
167 extern void GLAPIENTRY
168 _mesa_GetnUniformdvARB(GLhandleARB
, GLint
, GLsizei
, GLdouble
*);
170 extern GLint GLAPIENTRY
171 _mesa_GetUniformLocationARB(GLhandleARB
, const GLcharARB
*);
174 _mesa_get_uniform_location(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
178 _mesa_uniform(struct gl_context
*ctx
, struct gl_shader_program
*shader_program
,
179 GLint location
, GLsizei count
,
180 const GLvoid
*values
, GLenum type
);
183 _mesa_uniform_matrix(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
184 GLint cols
, GLint rows
,
185 GLint location
, GLsizei count
,
186 GLboolean transpose
, const GLfloat
*values
);
189 _mesa_get_uniform(struct gl_context
*ctx
, GLuint program
, GLint location
,
190 GLsizei bufSize
, GLenum returnType
, GLvoid
*paramsOut
);
193 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage
*,
194 unsigned element_stride
,
195 unsigned vector_stride
,
196 enum gl_uniform_driver_format format
,
200 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage
*uni
);
203 _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage
*uni
,
204 unsigned array_index
,
208 _mesa_update_shader_textures_used(struct gl_program
*prog
);
212 _mesa_init_shader_uniform_dispatch(struct _glapi_table
*exec
);
214 extern const struct gl_program_parameter
*
215 get_uniform_parameter(struct gl_shader_program
*shProg
, GLint index
);
217 struct gl_builtin_uniform_element
{
219 int tokens
[STATE_LENGTH
];
223 struct gl_builtin_uniform_desc
{
225 struct gl_builtin_uniform_element
*elements
;
226 unsigned int num_elements
;
229 extern const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc
[];
232 * \name GLSL uniform arrays and structs require special handling.
234 * The GL_ARB_shader_objects spec says that if you use
235 * glGetUniformLocation to get the location of an array, you CANNOT
236 * access other elements of the array by adding an offset to the
237 * returned location. For example, you must call
238 * glGetUniformLocation("foo[16]") if you want to set the 16th element
239 * of the array with glUniform().
241 * HOWEVER, some other OpenGL drivers allow accessing array elements
242 * by adding an offset to the returned array location. And some apps
243 * seem to depend on that behaviour.
245 * Mesa's gl_uniform_list doesn't directly support this since each
246 * entry in the list describes one uniform variable, not one uniform
247 * element. We could insert dummy entries in the list for each array
248 * element after [0] but that causes complications elsewhere.
250 * We solve this problem by encoding two values in the location that's
251 * returned by glGetUniformLocation():
252 * a) index into gl_uniform_list::Uniforms[] for the uniform
253 * b) an array/field offset (0 for simple types)
255 * These two values are encoded in the high and low halves of a GLint.
256 * By putting the uniform number in the high part and the offset in the
257 * low part, we can support the unofficial ability to index into arrays
258 * by adding offsets to the location value.
262 * Combine the uniform's base location and the offset
265 _mesa_uniform_merge_location_offset(unsigned base_location
, unsigned offset
)
267 return (base_location
<< 16) | offset
;
271 * Separate the uniform base location and parameter offset
274 _mesa_uniform_split_location_offset(GLint location
, unsigned *base_location
,
277 *offset
= location
& 0xffff;
278 *base_location
= location
>> 16;
282 #endif /* UNIFORMS_H */