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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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_footer
  145. echo
  146. echo 'const glsl_type *const glsl_type::bool_type = & builtin_core_types['$bool_index'];'
  147. echo 'const glsl_type *const glsl_type::int_type = & builtin_core_types['$int_index'];'
  148. echo 'const glsl_type *const glsl_type::float_type = & builtin_core_types['$float_index'];'
  149. echo 'const glsl_type *const glsl_type::mat2_type = & builtin_core_types['$(($matX_index + 0))'];'
  150. echo 'const glsl_type *const glsl_type::mat3_type = & builtin_core_types['$(($matX_index + 1))'];'
  151. echo 'const glsl_type *const glsl_type::mat4_type = & builtin_core_types['$(($matX_index + 2))'];'
  152. echo '/*@}*/'
  153. echo
  154. echo '/** \name GLSL structures that have not been deprecated.'
  155. echo ' */'
  156. echo '/*@{*/'
  157. gen_struct_field_header gl_DepthRangeParameters
  158. gen_struct_field builtin_core_types 8 "near"
  159. gen_struct_field builtin_core_types 8 "far"
  160. gen_struct_field builtin_core_types 8 "diff"
  161. gen_struct_field_footer
  162. gen_header "structure"
  163. gen_struct_type gl_DepthRangeParameters
  164. gen_footer
  165. echo '/*@}*/'
  166. echo
  167. echo '/** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30'
  168. echo ' */'
  169. echo '/*@{*/'
  170. gen_struct_field_header gl_PointParameters
  171. gen_struct_field builtin_core_types 8 "size"
  172. gen_struct_field builtin_core_types 8 "sizeMin"
  173. gen_struct_field builtin_core_types 8 "sizeMax"
  174. gen_struct_field builtin_core_types 8 "fadeThresholdSize"
  175. gen_struct_field builtin_core_types 8 "distanceConstantAttenuation"
  176. gen_struct_field builtin_core_types 8 "distanceLinearAttenuation"
  177. gen_struct_field builtin_core_types 8 "distanceQuadraticAttenuation"
  178. gen_struct_field_footer
  179. gen_struct_field_header gl_MaterialParameters
  180. gen_struct_field builtin_core_types 11 "emission"
  181. gen_struct_field builtin_core_types 11 "ambient"
  182. gen_struct_field builtin_core_types 11 "diffuse"
  183. gen_struct_field builtin_core_types 11 "specular"
  184. gen_struct_field builtin_core_types 8 "shininess"
  185. gen_struct_field_footer
  186. gen_struct_field_header gl_LightSourceParameters
  187. gen_struct_field builtin_core_types 11 "ambient"
  188. gen_struct_field builtin_core_types 11 "diffuse"
  189. gen_struct_field builtin_core_types 11 "specular"
  190. gen_struct_field builtin_core_types 11 "position"
  191. gen_struct_field builtin_core_types 11 "halfVector"
  192. gen_struct_field builtin_core_types 10 "spotDirection"
  193. gen_struct_field builtin_core_types 8 "spotExponent"
  194. gen_struct_field builtin_core_types 8 "spotCutoff"
  195. gen_struct_field builtin_core_types 8 "spotCosCutoff"
  196. gen_struct_field builtin_core_types 8 "constantAttenuation"
  197. gen_struct_field builtin_core_types 8 "linearAttenuation"
  198. gen_struct_field builtin_core_types 8 "quadraticAttenuation"
  199. gen_struct_field_footer
  200. gen_struct_field_header gl_LightModelParameters
  201. gen_struct_field builtin_core_types 11 "ambient"
  202. gen_struct_field_footer
  203. gen_struct_field_header gl_LightModelProducts
  204. gen_struct_field builtin_core_types 11 "sceneColor"
  205. gen_struct_field_footer
  206. gen_struct_field_header gl_LightProducts
  207. gen_struct_field builtin_core_types 11 "ambient"
  208. gen_struct_field builtin_core_types 11 "diffuse"
  209. gen_struct_field builtin_core_types 11 "specular"
  210. gen_struct_field_footer
  211. gen_struct_field_header gl_FogParameters
  212. gen_struct_field builtin_core_types 11 "color"
  213. gen_struct_field builtin_core_types 8 "density"
  214. gen_struct_field builtin_core_types 8 "start"
  215. gen_struct_field builtin_core_types 8 "end"
  216. gen_struct_field builtin_core_types 8 "scale"
  217. gen_struct_field_footer
  218. gen_header "110_deprecated_structure"
  219. gen_struct_type gl_PointParameters
  220. gen_struct_type gl_MaterialParameters
  221. gen_struct_type gl_LightSourceParameters
  222. gen_struct_type gl_LightModelParameters
  223. gen_struct_type gl_LightModelProducts
  224. gen_struct_type gl_LightProducts
  225. gen_struct_type gl_FogParameters
  226. gen_footer
  227. echo '/*@}*/'
  228. echo
  229. echo '/** \name Types added in GLSL 1.20'
  230. echo ' */'
  231. echo '/*@{*/'
  232. gen_header "120"
  233. for c in 2 3 4; do
  234. for r in 2 3 4; do
  235. if [ $c -ne $r ]; then
  236. gen_integral_type "mat${c}x${r}" "GLSL_TYPE_FLOAT" $r $c
  237. fi
  238. done
  239. done
  240. gen_footer
  241. echo 'const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];'
  242. echo 'const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];'
  243. echo 'const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];'
  244. echo 'const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];'
  245. echo 'const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];'
  246. echo 'const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];'
  247. echo '/*@}*/'
  248. echo
  249. echo '/** \name Types added in GLSL 1.30'
  250. echo ' */'
  251. echo '/*@{*/'
  252. gen_header "130"
  253. index=0;
  254. uint_index=$index
  255. gen_integral_type "uint" "GLSL_TYPE_UINT" 1 1
  256. for i in 2 3 4; do
  257. gen_integral_type "uvec$i" "GLSL_TYPE_UINT" $i 1
  258. done
  259. echo
  260. echo " /* 1D and 2D texture arrays */"
  261. for i in "1D" "2D"; do
  262. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_FLOAT"
  263. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_INT"
  264. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_UINT"
  265. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 1 1 "GLSL_TYPE_FLOAT"
  266. done
  267. echo
  268. echo " /* cube shadow samplers */"
  269. gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 1 0 "GLSL_TYPE_FLOAT"
  270. echo
  271. echo " /* signed and unsigned integer samplers */"
  272. for i in "1D" "2D" "3D"; do
  273. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 0 "GLSL_TYPE_INT"
  274. gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 0 "GLSL_TYPE_UINT"
  275. done
  276. gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_INT"
  277. gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_UINT"
  278. gen_footer
  279. echo ''
  280. echo 'const glsl_type *const glsl_type::uint_type = & builtin_130_types['$uint_index'];'
  281. echo '/*@}*/'
  282. echo
  283. echo '/** \name Sampler types added by GL_ARB_texture_rectangle'
  284. echo ' */'
  285. echo '/*@{*/'
  286. gen_header "ARB_texture_rectangle"
  287. gen_sampler_type "2DRect" "GLSL_SAMPLER_DIM_RECT" 0 0 "GLSL_TYPE_FLOAT"
  288. gen_sampler_type "2DRect" "GLSL_SAMPLER_DIM_RECT" 1 0 "GLSL_TYPE_FLOAT"
  289. gen_footer
  290. echo '/*@}*/'
  291. echo
  292. echo '/** \name Sampler types added by GL_EXT_texture_buffer_object'
  293. echo ' */'
  294. echo '/*@{*/'
  295. gen_header "EXT_texture_buffer_object"
  296. gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_FLOAT"
  297. gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_INT"
  298. gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_UINT"
  299. gen_footer
  300. echo '/*@}*/'