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.

glsl_types.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright © 2009 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <stdlib.h>
  24. #include "glsl_symbol_table.h"
  25. #include "glsl_parser_extras.h"
  26. #include "glsl_types.h"
  27. #include "builtin_types.h"
  28. static void
  29. add_types_to_symbol_table(glsl_symbol_table *symtab,
  30. const struct glsl_type *types,
  31. unsigned num_types)
  32. {
  33. unsigned i;
  34. for (i = 0; i < num_types; i++) {
  35. symtab->add_type(types[i].name, & types[i]);
  36. }
  37. }
  38. static void
  39. generate_110_types(glsl_symbol_table *symtab)
  40. {
  41. add_types_to_symbol_table(symtab, builtin_core_types,
  42. Elements(builtin_core_types));
  43. add_types_to_symbol_table(symtab, builtin_structure_types,
  44. Elements(builtin_structure_types));
  45. add_types_to_symbol_table(symtab, builtin_110_deprecated_structure_types,
  46. Elements(builtin_110_deprecated_structure_types));
  47. }
  48. static void
  49. generate_120_types(glsl_symbol_table *symtab)
  50. {
  51. generate_110_types(symtab);
  52. add_types_to_symbol_table(symtab, builtin_120_types,
  53. Elements(builtin_120_types));
  54. }
  55. static void
  56. generate_130_types(glsl_symbol_table *symtab)
  57. {
  58. generate_120_types(symtab);
  59. add_types_to_symbol_table(symtab, builtin_130_types,
  60. Elements(builtin_130_types));
  61. }
  62. void
  63. _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
  64. {
  65. switch (state->language_version) {
  66. case 110:
  67. generate_110_types(state->symbols);
  68. break;
  69. case 120:
  70. generate_120_types(state->symbols);
  71. break;
  72. case 130:
  73. generate_130_types(state->symbols);
  74. break;
  75. default:
  76. /* error */
  77. break;
  78. }
  79. }
  80. const struct glsl_type *
  81. _mesa_glsl_get_vector_type(unsigned base_type, unsigned vector_length)
  82. {
  83. switch (base_type) {
  84. case GLSL_TYPE_UINT:
  85. switch (vector_length) {
  86. case 1:
  87. case 2:
  88. case 3:
  89. case 4:
  90. return glsl_uint_type + (vector_length - 1);
  91. default:
  92. return glsl_error_type;
  93. }
  94. case GLSL_TYPE_INT:
  95. switch (vector_length) {
  96. case 1:
  97. case 2:
  98. case 3:
  99. case 4:
  100. return glsl_int_type + (vector_length - 1);
  101. default:
  102. return glsl_error_type;
  103. }
  104. case GLSL_TYPE_FLOAT:
  105. switch (vector_length) {
  106. case 1:
  107. case 2:
  108. case 3:
  109. case 4:
  110. return glsl_float_type + (vector_length - 1);
  111. default:
  112. return glsl_error_type;
  113. }
  114. case GLSL_TYPE_BOOL:
  115. switch (vector_length) {
  116. case 1:
  117. case 2:
  118. case 3:
  119. case 4:
  120. return glsl_bool_type + (vector_length - 1);
  121. default:
  122. return glsl_error_type;
  123. }
  124. default:
  125. return glsl_error_type;
  126. }
  127. }