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