Debian Codegraph @

editor/shader/editor_shader_language_plugin.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_shader_language_plugin.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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 #include "editor_shader_language_plugin.h"
32
33 Vector<Ref<EditorShaderLanguagePlugin>> EditorShaderLanguagePlugin::shader_languages;
34 Vector<Vector2i> EditorShaderLanguagePlugin::language_variation_map;
35
36 void EditorShaderLanguagePlugin::register_shader_language(const Ref<EditorShaderLanguagePlugin> &p_shader_language) {
37 // Allows one ShaderLanguageEditorPlugin to provide multiple dropdown options in
38 // the language selection menu. For example, ShaderInclude is handled this way.
39 // X is the plugin index, and Y is the language variation index.
40 for (int i = 0; i < p_shader_language->get_language_variations().size(); i++) {
41 language_variation_map.push_back(Vector2i(shader_languages.size(), i));
42 }
43 shader_languages.push_back(p_shader_language);
44 }
45
46 void EditorShaderLanguagePlugin::clear_registered_shader_languages() {
47 shader_languages.clear();
48 language_variation_map.clear();
49 }
50
51 const Vector<Ref<EditorShaderLanguagePlugin>> EditorShaderLanguagePlugin::get_shader_languages_read_only() {
52 return shader_languages;
53 }
54
55 int EditorShaderLanguagePlugin::get_shader_language_variation_count() {
56 return language_variation_map.size();
57 }
58
59 Ref<EditorShaderLanguagePlugin> EditorShaderLanguagePlugin::get_shader_language_for_index(int p_index) {
60 ERR_FAIL_INDEX_V(p_index, language_variation_map.size(), nullptr);
61 Vector2i lang_var_indices = language_variation_map[p_index];
62 return shader_languages[lang_var_indices.x];
63 }
64
65 String EditorShaderLanguagePlugin::get_file_extension_for_index(int p_index) {
66 ERR_FAIL_INDEX_V(p_index, language_variation_map.size(), "tres");
67 Vector2i lang_var_indices = language_variation_map[p_index];
68 EditorShaderLanguagePlugin *lang = shader_languages[lang_var_indices.x].ptr();
69 return lang->get_file_extension(lang_var_indices.y);
70 }