editor_shader_language_plugin.cpp 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "editor_shader_language_plugin.h"
  31. Vector<Ref<EditorShaderLanguagePlugin>> EditorShaderLanguagePlugin::shader_languages;
  32. Vector<Vector2i> EditorShaderLanguagePlugin::language_variation_map;
  33. void EditorShaderLanguagePlugin::register_shader_language(const Ref<EditorShaderLanguagePlugin> &p_shader_language) {
  34. // Allows one ShaderLanguageEditorPlugin to provide multiple dropdown options in
  35. // the language selection menu. For example, ShaderInclude is handled this way.
  36. // X is the plugin index, and Y is the language variation index.
  37. for (int i = 0; i < p_shader_language->get_language_variations().size(); i++) {
  38. language_variation_map.push_back(Vector2i(shader_languages.size(), i));
  39. }
  40. shader_languages.push_back(p_shader_language);
  41. }
  42. void EditorShaderLanguagePlugin::clear_registered_shader_languages() {
  43. shader_languages.clear();
  44. language_variation_map.clear();
  45. }
  46. const Vector<Ref<EditorShaderLanguagePlugin>> EditorShaderLanguagePlugin::get_shader_languages_read_only() {
  47. return shader_languages;
  48. }
  49. int EditorShaderLanguagePlugin::get_shader_language_variation_count() {
  50. return language_variation_map.size();
  51. }
  52. Ref<EditorShaderLanguagePlugin> EditorShaderLanguagePlugin::get_shader_language_for_index(int p_index) {
  53. ERR_FAIL_INDEX_V(p_index, language_variation_map.size(), nullptr);
  54. Vector2i lang_var_indices = language_variation_map[p_index];
  55. return shader_languages[lang_var_indices.x];
  56. }
  57. String EditorShaderLanguagePlugin::get_file_extension_for_index(int p_index) {
  58. ERR_FAIL_INDEX_V(p_index, language_variation_map.size(), "tres");
  59. Vector2i lang_var_indices = language_variation_map[p_index];
  60. EditorShaderLanguagePlugin *lang = shader_languages[lang_var_indices.x].ptr();
  61. return lang->get_file_extension(lang_var_indices.y);
  62. }