Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

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