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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
30 #include "program/prog_parameter.h"
31 #include "../glsl/glsl_types.h"
32 #include "../glsl/ir_uniform.h"
43 _mesa_Uniform1f(GLint
, GLfloat
);
45 _mesa_Uniform2f(GLint
, GLfloat
, GLfloat
);
47 _mesa_Uniform3f(GLint
, GLfloat
, GLfloat
, GLfloat
);
49 _mesa_Uniform4f(GLint
, GLfloat
, GLfloat
, GLfloat
, GLfloat
);
51 _mesa_Uniform1i(GLint
, GLint
);
53 _mesa_Uniform2i(GLint
, GLint
, GLint
);
55 _mesa_Uniform3i(GLint
, GLint
, GLint
, GLint
);
57 _mesa_Uniform4i(GLint
, GLint
, GLint
, GLint
, GLint
);
59 _mesa_Uniform1fv(GLint
, GLsizei
, const GLfloat
*);
61 _mesa_Uniform2fv(GLint
, GLsizei
, const GLfloat
*);
63 _mesa_Uniform3fv(GLint
, GLsizei
, const GLfloat
*);
65 _mesa_Uniform4fv(GLint
, GLsizei
, const GLfloat
*);
67 _mesa_Uniform1iv(GLint
, GLsizei
, const GLint
*);
69 _mesa_Uniform2iv(GLint
, GLsizei
, const GLint
*);
71 _mesa_Uniform3iv(GLint
, GLsizei
, const GLint
*);
73 _mesa_Uniform4iv(GLint
, GLsizei
, const GLint
*);
75 _mesa_Uniform1ui(GLint location
, GLuint v0
);
77 _mesa_Uniform2ui(GLint location
, GLuint v0
, GLuint v1
);
79 _mesa_Uniform3ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
);
81 _mesa_Uniform4ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
, GLuint v3
);
83 _mesa_Uniform1uiv(GLint location
, GLsizei count
, const GLuint
*value
);
85 _mesa_Uniform2uiv(GLint location
, GLsizei count
, const GLuint
*value
);
87 _mesa_Uniform3uiv(GLint location
, GLsizei count
, const GLuint
*value
);
89 _mesa_Uniform4uiv(GLint location
, GLsizei count
, const GLuint
*value
);
91 _mesa_UniformMatrix2fv(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
93 _mesa_UniformMatrix3fv(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
95 _mesa_UniformMatrix4fv(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
97 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
98 const GLfloat
*value
);
100 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
101 const GLfloat
*value
);
103 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
104 const GLfloat
*value
);
106 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
107 const GLfloat
*value
);
109 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
110 const GLfloat
*value
);
112 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
113 const GLfloat
*value
);
115 _mesa_GetnUniformfvARB(GLhandleARB
, GLint
, GLsizei
, GLfloat
*);
117 _mesa_GetUniformfv(GLhandleARB
, GLint
, GLfloat
*);
119 _mesa_GetnUniformivARB(GLhandleARB
, GLint
, GLsizei
, GLint
*);
121 _mesa_GetUniformuiv(GLhandleARB
, GLint
, GLuint
*);
123 _mesa_GetnUniformuivARB(GLhandleARB
, GLint
, GLsizei
, GLuint
*);
125 _mesa_GetUniformuiv(GLhandleARB program
, GLint location
, GLuint
*params
);
127 _mesa_GetnUniformdvARB(GLhandleARB
, GLint
, GLsizei
, GLdouble
*);
129 _mesa_GetUniformdv(GLhandleARB
, GLint
, GLdouble
*);
131 _mesa_GetUniformLocation(GLhandleARB
, const GLcharARB
*);
133 _mesa_GetUniformBlockIndex(GLuint program
,
134 const GLchar
*uniformBlockName
);
136 _mesa_GetUniformIndices(GLuint program
,
137 GLsizei uniformCount
,
138 const GLchar
* const *uniformNames
,
139 GLuint
*uniformIndices
);
141 _mesa_UniformBlockBinding(GLuint program
,
142 GLuint uniformBlockIndex
,
143 GLuint uniformBlockBinding
);
145 _mesa_GetActiveAtomicCounterBufferiv(GLuint program
, GLuint bufferIndex
,
146 GLenum pname
, GLint
*params
);
148 _mesa_GetActiveUniformBlockiv(GLuint program
,
149 GLuint uniformBlockIndex
,
153 _mesa_GetActiveUniformBlockName(GLuint program
,
154 GLuint uniformBlockIndex
,
157 GLchar
*uniformBlockName
);
159 _mesa_GetActiveUniformName(GLuint program
, GLuint uniformIndex
,
160 GLsizei bufSize
, GLsizei
*length
,
161 GLchar
*uniformName
);
163 _mesa_GetActiveUniform(GLhandleARB
, GLuint
, GLsizei
, GLsizei
*,
164 GLint
*, GLenum
*, GLcharARB
*);
166 _mesa_GetActiveUniformsiv(GLuint program
,
167 GLsizei uniformCount
,
168 const GLuint
*uniformIndices
,
172 _mesa_GetUniformiv(GLhandleARB
, GLint
, GLint
*);
175 _mesa_parse_program_resource_name(const GLchar
*name
,
176 const GLchar
**out_base_name_end
);
179 _mesa_get_uniform_location(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
180 const GLchar
*name
, unsigned *offset
);
183 _mesa_uniform(struct gl_context
*ctx
, struct gl_shader_program
*shader_program
,
184 GLint location
, GLsizei count
,
185 const GLvoid
*values
, GLenum type
);
188 _mesa_uniform_matrix(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
189 GLuint cols
, GLuint rows
,
190 GLint location
, GLsizei count
,
191 GLboolean transpose
, const GLfloat
*values
);
194 _mesa_get_uniform(struct gl_context
*ctx
, GLuint program
, GLint location
,
195 GLsizei bufSize
, enum glsl_base_type returnType
,
199 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage
*,
200 unsigned element_stride
,
201 unsigned vector_stride
,
202 enum gl_uniform_driver_format format
,
206 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage
*uni
);
209 _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage
*uni
,
210 unsigned array_index
,
214 _mesa_update_shader_textures_used(struct gl_shader_program
*shProg
,
215 struct gl_program
*prog
);
218 _mesa_sampler_uniforms_are_valid(const struct gl_shader_program
*shProg
,
219 char *errMsg
, size_t errMsgLength
);
221 extern const struct gl_program_parameter
*
222 get_uniform_parameter(struct gl_shader_program
*shProg
, GLint index
);
225 _mesa_get_uniform_name(const struct gl_uniform_storage
*uni
,
226 GLsizei maxLength
, GLsizei
*length
,
229 struct gl_builtin_uniform_element
{
231 int tokens
[STATE_LENGTH
];
235 struct gl_builtin_uniform_desc
{
237 struct gl_builtin_uniform_element
*elements
;
238 unsigned int num_elements
;
242 * \name GLSL uniform arrays and structs require special handling.
244 * The GL_ARB_shader_objects spec says that if you use
245 * glGetUniformLocation to get the location of an array, you CANNOT
246 * access other elements of the array by adding an offset to the
247 * returned location. For example, you must call
248 * glGetUniformLocation("foo[16]") if you want to set the 16th element
249 * of the array with glUniform().
251 * HOWEVER, some other OpenGL drivers allow accessing array elements
252 * by adding an offset to the returned array location. And some apps
253 * seem to depend on that behaviour.
255 * Mesa's gl_uniform_list doesn't directly support this since each
256 * entry in the list describes one uniform variable, not one uniform
257 * element. We could insert dummy entries in the list for each array
258 * element after [0] but that causes complications elsewhere.
260 * We solve this problem by encoding two values in the location that's
261 * returned by glGetUniformLocation():
262 * a) index into gl_uniform_list::Uniforms[] for the uniform
263 * b) an array/field offset (0 for simple types)
265 * These two values are encoded in the high and low halves of a GLint.
266 * By putting the uniform number in the high part and the offset in the
267 * low part, we can support the unofficial ability to index into arrays
268 * by adding offsets to the location value.
272 * Combine the uniform's base location and the offset
275 _mesa_uniform_merge_location_offset(const struct gl_shader_program
*prog
,
276 unsigned base_location
, unsigned offset
)
278 assert(prog
->UniformLocationBaseScale
>= 1);
279 assert(offset
< prog
->UniformLocationBaseScale
);
280 return (base_location
* prog
->UniformLocationBaseScale
) + offset
;
284 * Separate the uniform base location and parameter offset
287 _mesa_uniform_split_location_offset(const struct gl_shader_program
*prog
,
288 GLint location
, unsigned *base_location
,
291 *offset
= location
% prog
->UniformLocationBaseScale
;
292 *base_location
= location
/ prog
->UniformLocationBaseScale
;
302 #endif /* UNIFORMS_H */