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-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 31 #ifndef SHADERCOMPILERGLES3_H 32 #define SHADERCOMPILERGLES3_H 33 34 #include "core/pair.h" 35 #include "servers/visual/shader_language.h" 36 #include "servers/visual/shader_types.h" 37 #include "servers/visual_server.h" 38 39 class ShaderCompilerGLES3 { 40 public: 41 struct IdentifierActions { 42 43 Map<StringName, Pair<int *, int> > render_mode_values; 44 Map<StringName, bool *> render_mode_flags; 45 Map<StringName, bool *> usage_flag_pointers; 46 Map<StringName, bool *> write_flag_pointers; 47 48 Map<StringName, ShaderLanguage::ShaderNode::Uniform> *uniforms; 49 }; 50 51 struct GeneratedCode { 52 53 Vector<CharString> defines; 54 Vector<StringName> texture_uniforms; 55 Vector<ShaderLanguage::DataType> texture_types; 56 Vector<ShaderLanguage::ShaderNode::Uniform::Hint> texture_hints; 57 58 Vector<uint32_t> uniform_offsets; 59 uint32_t uniform_total_size; 60 String uniforms; 61 String vertex_global; 62 String vertex; 63 String fragment_global; 64 String fragment; 65 String light; 66 67 bool uses_fragment_time; 68 bool uses_vertex_time; 69 }; 70 71 private: 72 ShaderLanguage parser; 73 74 struct DefaultIdentifierActions { 75 76 Map<StringName, String> renames; 77 Map<StringName, String> render_mode_defines; 78 Map<StringName, String> usage_defines; 79 }; 80 81 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); 82 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, bool p_use_scope = true); 83 84 StringName current_func_name; 85 StringName vertex_name; 86 StringName fragment_name; 87 StringName light_name; 88 StringName time_name; 89 90 Set<StringName> used_name_defines; 91 Set<StringName> used_flag_pointers; 92 Set<StringName> used_rmode_defines; 93 Set<StringName> internal_functions; 94 95 DefaultIdentifierActions actions[VS::SHADER_MAX]; 96 97 public: 98 Error compile(VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code); 99 100 ShaderCompilerGLES3(); 101 }; 102 103 #endif // SHADERCOMPILERGLES3_H 104