shader_compiler_gles2.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*************************************************************************/
  2. /* shader_compiler_gles2.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef SHADER_COMPILER_GLES2_H
  31. #define SHADER_COMPILER_GLES2_H
  32. #include "servers/visual/shader_language.h"
  33. class ShaderCompilerGLES2 {
  34. class Uniform;
  35. public:
  36. struct Flags;
  37. private:
  38. ShaderLanguage::ProgramNode *program_node;
  39. String dump_node_code(ShaderLanguage::Node *p_node, int p_level, bool p_assign_left = false);
  40. Error compile_node(ShaderLanguage::ProgramNode *p_program);
  41. static Error create_glsl_120_code(void *p_str, ShaderLanguage::ProgramNode *p_program);
  42. bool _is_condition_preprocessable(ShaderLanguage::Node *p_condition) const;
  43. bool uses_light;
  44. bool uses_texscreen;
  45. bool uses_texpos;
  46. bool uses_alpha;
  47. bool uses_discard;
  48. bool uses_time;
  49. bool uses_screen_uv;
  50. bool uses_normalmap;
  51. bool uses_normal;
  52. bool uses_texpixel_size;
  53. bool uses_worldvec;
  54. bool vertex_code_writes_vertex;
  55. bool vertex_code_writes_position;
  56. bool uses_shadow_color;
  57. bool sinh_used;
  58. bool tanh_used;
  59. bool cosh_used;
  60. bool custom_h;
  61. Flags *flags;
  62. StringName vname_discard;
  63. StringName vname_screen_uv;
  64. StringName vname_diffuse_alpha;
  65. StringName vname_color_interp;
  66. StringName vname_uv_interp;
  67. StringName vname_uv2_interp;
  68. StringName vname_tangent_interp;
  69. StringName vname_binormal_interp;
  70. StringName vname_var1_interp;
  71. StringName vname_var2_interp;
  72. StringName vname_vertex;
  73. StringName vname_position;
  74. StringName vname_light;
  75. StringName vname_time;
  76. StringName vname_normalmap;
  77. StringName vname_normalmap_depth;
  78. StringName vname_normal;
  79. StringName vname_texpixel_size;
  80. StringName vname_world_vec;
  81. StringName vname_shadow;
  82. Map<StringName, ShaderLanguage::Uniform> *uniforms;
  83. StringName out_vertex_name;
  84. String global_code;
  85. String code;
  86. ShaderLanguage::ShaderType type;
  87. String replace_string(const StringName &p_string);
  88. Map<StringName, StringName> mode_replace_table[9];
  89. Map<StringName, StringName> replace_table;
  90. public:
  91. struct Flags {
  92. bool uses_alpha;
  93. bool uses_texscreen;
  94. bool uses_texpos;
  95. bool uses_normalmap;
  96. bool vertex_code_writes_vertex;
  97. bool vertex_code_writes_position;
  98. bool uses_discard;
  99. bool uses_screen_uv;
  100. bool use_color_interp;
  101. bool use_uv_interp;
  102. bool use_uv2_interp;
  103. bool use_tangent_interp;
  104. bool use_var1_interp;
  105. bool use_var2_interp;
  106. bool uses_light;
  107. bool uses_time;
  108. bool uses_normal;
  109. bool uses_texpixel_size;
  110. bool uses_worldvec;
  111. bool uses_shadow_color;
  112. };
  113. Error compile(const String &p_code, ShaderLanguage::ShaderType p_type, String &r_code_line, String &r_globals_line, Flags &r_flags, Map<StringName, ShaderLanguage::Uniform> *r_uniforms = NULL);
  114. ShaderCompilerGLES2();
  115. };
  116. #endif // SHADER_COMPILERL_GL_H