editor_native_shader_source_visualizer.cpp 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**************************************************************************/
  2. /* editor_native_shader_source_visualizer.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_native_shader_source_visualizer.h"
  31. #include "editor/editor_string_names.h"
  32. #include "editor/settings/editor_settings.h"
  33. #include "editor/themes/editor_scale.h"
  34. #include "scene/gui/code_edit.h"
  35. #include "scene/gui/text_edit.h"
  36. #include "servers/rendering/shader_language.h"
  37. void EditorNativeShaderSourceVisualizer::_inspect_shader(RID p_shader) {
  38. if (versions) {
  39. memdelete(versions);
  40. versions = nullptr;
  41. }
  42. RS::ShaderNativeSourceCode nsc = RS::get_singleton()->shader_get_native_source_code(p_shader);
  43. List<String> keywords;
  44. ShaderLanguage::get_keyword_list(&keywords);
  45. Ref<EditorJsonVisualizerSyntaxHighlighter> syntax_highlighter;
  46. syntax_highlighter.instantiate(keywords);
  47. versions = memnew(TabContainer);
  48. versions->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  49. versions->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  50. versions->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  51. for (int i = 0; i < nsc.versions.size(); i++) {
  52. TabContainer *vtab = memnew(TabContainer);
  53. vtab->set_name("Version " + itos(i));
  54. vtab->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  55. vtab->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  56. vtab->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  57. versions->add_child(vtab);
  58. for (int j = 0; j < nsc.versions[i].stages.size(); j++) {
  59. EditorJsonVisualizer *code_edit = memnew(EditorJsonVisualizer);
  60. code_edit->load_theme(syntax_highlighter);
  61. code_edit->set_name(nsc.versions[i].stages[j].name);
  62. code_edit->set_text(nsc.versions[i].stages[j].code);
  63. code_edit->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  64. code_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  65. vtab->add_child(code_edit);
  66. }
  67. }
  68. add_child(versions);
  69. popup_centered_ratio();
  70. }
  71. void EditorNativeShaderSourceVisualizer::_bind_methods() {
  72. ClassDB::bind_method("_inspect_shader", &EditorNativeShaderSourceVisualizer::_inspect_shader);
  73. }
  74. EditorNativeShaderSourceVisualizer::EditorNativeShaderSourceVisualizer() {
  75. add_to_group("_native_shader_source_visualizer");
  76. set_title(TTR("Native Shader Source Inspector"));
  77. }