shader_compiler_gles3.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*************************************************************************/
  2. /* shader_compiler_gles3.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 SHADERCOMPILERGLES3_H
  31. #define SHADERCOMPILERGLES3_H
  32. #include "core/pair.h"
  33. #include "servers/visual/shader_language.h"
  34. #include "servers/visual/shader_types.h"
  35. #include "servers/visual_server.h"
  36. class ShaderCompilerGLES3 {
  37. public:
  38. struct IdentifierActions {
  39. Map<StringName, Pair<int *, int> > render_mode_values;
  40. Map<StringName, bool *> render_mode_flags;
  41. Map<StringName, bool *> usage_flag_pointers;
  42. Map<StringName, bool *> write_flag_pointers;
  43. Map<StringName, ShaderLanguage::ShaderNode::Uniform> *uniforms;
  44. };
  45. struct GeneratedCode {
  46. Vector<CharString> defines;
  47. Vector<StringName> texture_uniforms;
  48. Vector<ShaderLanguage::DataType> texture_types;
  49. Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints;
  50. Vector<uint32_t> uniform_offsets;
  51. uint32_t uniform_total_size;
  52. String uniforms;
  53. String vertex_global;
  54. String vertex;
  55. String fragment_global;
  56. String fragment;
  57. String light;
  58. bool uses_fragment_time;
  59. bool uses_vertex_time;
  60. };
  61. private:
  62. ShaderLanguage parser;
  63. struct DefaultIdentifierActions {
  64. Map<StringName, String> renames;
  65. Map<StringName, String> render_mode_defines;
  66. Map<StringName, String> usage_defines;
  67. };
  68. void _dump_function_deps(ShaderLanguage::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, String &r_to_add, Set<StringName> &added);
  69. String _dump_node_code(ShaderLanguage::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning);
  70. StringName current_func_name;
  71. StringName vertex_name;
  72. StringName fragment_name;
  73. StringName light_name;
  74. StringName time_name;
  75. Set<StringName> used_name_defines;
  76. Set<StringName> used_flag_pointers;
  77. Set<StringName> used_rmode_defines;
  78. Set<StringName> internal_functions;
  79. DefaultIdentifierActions actions[VS::SHADER_MAX];
  80. public:
  81. Error compile(VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code);
  82. ShaderCompilerGLES3();
  83. };
  84. #endif // SHADERCOMPILERGLES3_H