Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

builtin_types.sh 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #!/bin/sh
  2. #
  3. # Copyright © 2009 Intel Corporation
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. # and/or sell copies of the Software, and to permit persons to whom the
  10. # Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice (including the next
  13. # paragraph) shall be included in all copies or substantial portions of the
  14. # Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # 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 OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. # DEALINGS IN THE SOFTWARE.
  23. # gen_integral_type <name> <base_type> <vector elements> <matrix rows>
  24. function gen_integral_type
  25. {
  26. printf ' glsl_type( %17s, %u, %u, "%s"),\n' $2 $3 $4 $1
  27. index=$((index + 1))
  28. }
  29. # gen_struct_type <name>
  30. function gen_struct_type
  31. {
  32. elements=$(printf "%s_fields" $1)
  33. printf ' glsl_type(%s,\n Elements(%s),\n "%s"),\n' \
  34. $elements $elements $1
  35. }
  36. # gen_sampler_type <name> <dimensions> <shadow> <array> <type>
  37. function gen_sampler_type
  38. {
  39. name=$(printf "sampler%s" $1)
  40. if [ $4 -eq 1 ]; then
  41. name=$(printf "%sArray" $name)
  42. fi
  43. if [ $3 -eq 1 ]; then
  44. name=$(printf "%sShadow" $name)
  45. fi
  46. if [ $5 == GLSL_TYPE_INT ]; then
  47. name=$(printf "i%s" $name)
  48. elif [ $5 == GLSL_TYPE_UINT ]; then
  49. name=$(printf "u%s" $name)
  50. fi
  51. printf ' glsl_type(%21s, %u, %u, %15s, "%s"),\n' \
  52. $2 $3 $4 $5 $name
  53. }
  54. function gen_header
  55. {
  56. if [ x$1 == x ]; then
  57. name="builtin_types"
  58. else
  59. name="builtin_${1}_types"
  60. fi
  61. printf "\nstatic const struct glsl_type %s[] = {\n" $name
  62. }
  63. function gen_footer
  64. {
  65. printf "};\n"
  66. }
  67. function gen_struct_field_header
  68. {
  69. printf "\nstatic const struct glsl_struct_field %s_fields[] = {\n" $1
  70. }
  71. function gen_struct_field_footer
  72. {
  73. printf "};\n"
  74. }
  75. function gen_struct_field
  76. {
  77. printf ' { & %s[%2u], "%s" },\n' $1 $2 "$3"
  78. }
  79. cat <<EOF
  80. /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT! See builtin_types.sh. */
  81. /*
  82. * Copyright © 2009 Intel Corporation
  83. *
  84. * Permission is hereby granted, free of charge, to any person obtaining a
  85. * copy of this software and associated documentation files (the "Software"),
  86. * to deal in the Software without restriction, including without limitation
  87. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  88. * and/or sell copies of the Software, and to permit persons to whom the
  89. * Software is furnished to do so, subject to the following conditions:
  90. *
  91. * The above copyright notice and this permission notice (including the next
  92. * paragraph) shall be included in all copies or substantial portions of the
  93. * Software.
  94. *
  95. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  96. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  97. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  98. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  99. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  100. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  101. * DEALINGS IN THE SOFTWARE.
  102. */
  103. #ifndef Elements
  104. #define Elements(x) (sizeof(x)/sizeof(*(x)))
  105. #endif
  106. static const struct glsl_type _error_type =
  107. glsl_type(GLSL_TYPE_ERROR, 0, 0, "");
  108. static const struct glsl_type void_type =
  109. glsl_type(GLSL_TYPE_VOID, 0, 0, "void");
  110. const glsl_type *const glsl_type::error_type = & _error_type;
  111. EOF
  112. echo '/** \name Core built-in types'
  113. echo ' *'
  114. echo ' * These types exist in all versions of GLSL.'
  115. echo ' */'
  116. echo '/*@{*/'
  117. gen_header "core"
  118. index=0;
  119. bool_index=$index
  120. gen_integral_type "bool" "GLSL_TYPE_BOOL" 1 1
  121. for i in 2 3 4; do
  122. gen_integral_type "bvec$i" "GLSL_TYPE_BOOL" $i 1
  123. done
  124. int_index=$index
  125. gen_integral_type "int" "GLSL_TYPE_INT" 1 1
  126. for i in 2 3 4; do
  127. gen_integral_type "ivec$i" "GLSL_TYPE_INT" $i 1
  128. done
  129. float_index=$index
  130. gen_integral_type "float" "GLSL_TYPE_FLOAT" 1 1
  131. for i in 2 3 4; do
  132. gen_integral_type "vec$i" "GLSL_TYPE_FLOAT" $i 1
  133. done
  134. matX_index=$index
  135. for i in 2 3 4; do
  136. gen_integral_type "mat$i" "GLSL_TYPE_FLOAT" $i $i
  137. done
  138. for i in "1D" "2D"; do
  139. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 0 "GLSL_TYPE_FLOAT"
  140. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 1 0 "GLSL_TYPE_FLOAT"
  141. done
  142. gen_sampler_type "3D" "GLSL_SAMPLER_DIM_3D" 0 0 "GLSL_TYPE_FLOAT"
  143. gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_FLOAT"
  144. gen_sampler_type "2DRect" "GLSL_SAMPLER_DIM_RECT" 0 0 "GLSL_TYPE_FLOAT"
  145. gen_sampler_type "2DRect" "GLSL_SAMPLER_DIM_RECT" 1 0 "GLSL_TYPE_FLOAT"
  146. gen_footer
  147. echo
  148. echo 'const glsl_type *const glsl_type::bool_type = & builtin_core_types['$bool_index'];'
  149. echo 'const glsl_type *const glsl_type::int_type = & builtin_core_types['$int_index'];'
  150. echo 'const glsl_type *const glsl_type::float_type = & builtin_core_types['$float_index'];'
  151. echo 'const glsl_type *const glsl_type::mat2_type = & builtin_core_types['$(($matX_index + 0))'];'
  152. echo 'const glsl_type *const glsl_type::mat3_type = & builtin_core_types['$(($matX_index + 1))'];'
  153. echo 'const glsl_type *const glsl_type::mat4_type = & builtin_core_types['$(($matX_index + 2))'];'
  154. echo '/*@}*/'
  155. echo
  156. echo '/** \name GLSL structures that have not been deprecated.'
  157. echo ' */'
  158. echo '/*@{*/'
  159. gen_struct_field_header gl_DepthRangeParameters
  160. gen_struct_field builtin_core_types 8 "near"
  161. gen_struct_field builtin_core_types 8 "far"
  162. gen_struct_field builtin_core_types 8 "diff"
  163. gen_struct_field_footer
  164. gen_header "structure"
  165. gen_struct_type gl_DepthRangeParameters
  166. gen_footer
  167. echo '/*@}*/'
  168. echo
  169. echo '/** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30'
  170. echo ' */'
  171. echo '/*@{*/'
  172. gen_struct_field_header gl_PointParameters
  173. gen_struct_field builtin_core_types 8 "size"
  174. gen_struct_field builtin_core_types 8 "sizeMin"
  175. gen_struct_field builtin_core_types 8 "sizeMax"
  176. gen_struct_field builtin_core_types 8 "fadeThresholdSize"
  177. gen_struct_field builtin_core_types 8 "distanceConstantAttenuation"
  178. gen_struct_field builtin_core_types 8 "distanceLinearAttenuation"
  179. gen_struct_field builtin_core_types 8 "distanceQuadraticAttenuation"
  180. gen_struct_field_footer
  181. gen_struct_field_header gl_MaterialParameters
  182. gen_struct_field builtin_core_types 11 "emission"
  183. gen_struct_field builtin_core_types 11 "ambient"
  184. gen_struct_field builtin_core_types 11 "diffuse"
  185. gen_struct_field builtin_core_types 11 "specular"
  186. gen_struct_field builtin_core_types 8 "shininess"
  187. gen_struct_field_footer
  188. gen_struct_field_header gl_LightSourceParameters
  189. gen_struct_field builtin_core_types 11 "ambient"
  190. gen_struct_field builtin_core_types 11 "diffuse"
  191. gen_struct_field builtin_core_types 11 "specular"
  192. gen_struct_field builtin_core_types 11 "position"
  193. gen_struct_field builtin_core_types 11 "halfVector"
  194. gen_struct_field builtin_core_types 10 "spotDirection"
  195. gen_struct_field builtin_core_types 8 "spotExponent"
  196. gen_struct_field builtin_core_types 8 "spotCutoff"
  197. gen_struct_field builtin_core_types 8 "spotCosCutoff"
  198. gen_struct_field builtin_core_types 8 "constantAttenuation"
  199. gen_struct_field builtin_core_types 8 "linearAttenuation"
  200. gen_struct_field builtin_core_types 8 "quadraticAttenuation"
  201. gen_struct_field_footer
  202. gen_struct_field_header gl_LightModelParameters
  203. gen_struct_field builtin_core_types 11 "ambient"
  204. gen_struct_field_footer
  205. gen_struct_field_header gl_LightModelProducts
  206. gen_struct_field builtin_core_types 11 "sceneColor"
  207. gen_struct_field_footer
  208. gen_struct_field_header gl_LightProducts
  209. gen_struct_field builtin_core_types 11 "ambient"
  210. gen_struct_field builtin_core_types 11 "diffuse"
  211. gen_struct_field builtin_core_types 11 "specular"
  212. gen_struct_field_footer
  213. gen_struct_field_header gl_FogParameters
  214. gen_struct_field builtin_core_types 11 "color"
  215. gen_struct_field builtin_core_types 8 "density"
  216. gen_struct_field builtin_core_types 8 "start"
  217. gen_struct_field builtin_core_types 8 "end"
  218. gen_struct_field builtin_core_types 8 "scale"
  219. gen_struct_field_footer
  220. gen_header "110_deprecated_structure"
  221. gen_struct_type gl_PointParameters
  222. gen_struct_type gl_MaterialParameters
  223. gen_struct_type gl_LightSourceParameters
  224. gen_struct_type gl_LightModelParameters
  225. gen_struct_type gl_LightModelProducts
  226. gen_struct_type gl_LightProducts
  227. gen_struct_type gl_FogParameters
  228. gen_footer
  229. echo '/*@}*/'
  230. echo
  231. echo '/** \name Types added in GLSL 1.20'
  232. echo ' */'
  233. echo '/*@{*/'
  234. gen_header "120"
  235. for c in 2 3 4; do
  236. for r in 2 3 4; do
  237. if [ $c -ne $r ]; then
  238. gen_integral_type "mat${c}x${r}" "GLSL_TYPE_FLOAT" $r $c
  239. fi
  240. done
  241. done
  242. gen_footer
  243. echo 'const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];'
  244. echo 'const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];'
  245. echo 'const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];'
  246. echo 'const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];'
  247. echo 'const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];'
  248. echo 'const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];'
  249. echo '/*@}*/'
  250. echo
  251. echo '/** \name Types added in GLSL 1.30'
  252. echo ' */'
  253. echo '/*@{*/'
  254. gen_header "130"
  255. index=0;
  256. uint_index=$index
  257. gen_integral_type "uint" "GLSL_TYPE_UINT" 1 1
  258. for i in 2 3 4; do
  259. gen_integral_type "uvec$i" "GLSL_TYPE_UINT" $i 1
  260. done
  261. echo
  262. echo " /* 1D and 2D texture arrays */"
  263. for i in "1D" "2D"; do
  264. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_FLOAT"
  265. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_INT"
  266. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_UINT"
  267. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 1 1 "GLSL_TYPE_FLOAT"
  268. done
  269. echo
  270. echo " /* cube shadow samplers */"
  271. gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 1 0 "GLSL_TYPE_FLOAT"
  272. echo
  273. echo " /* signed and unsigned integer samplers */"
  274. for i in "1D" "2D" "3D"; do
  275. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 0 "GLSL_TYPE_INT"
  276. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 0 "GLSL_TYPE_UINT"
  277. done
  278. gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_INT"
  279. gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_UINT"
  280. gen_footer
  281. echo ''
  282. echo 'const glsl_type *const glsl_type::uint_type = & builtin_130_types['$uint_index'];'
  283. echo '/*@}*/'
  284. echo
  285. echo '/** \name Sampler types added by GL_EXT_texture_buffer_object'
  286. echo ' */'
  287. echo '/*@{*/'
  288. gen_header "EXT_texture_buffer_object"
  289. gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_FLOAT"
  290. gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_INT"
  291. gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_UINT"
  292. gen_footer
  293. echo '/*@}*/'