editor_preview_plugins.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**************************************************************************/
  2. /* editor_preview_plugins.h */
  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. #pragma once
  31. #include "editor/inspector/editor_resource_preview.h"
  32. class ScriptLanguage;
  33. void post_process_preview(Ref<Image> p_image);
  34. class EditorTexturePreviewPlugin : public EditorResourcePreviewGenerator {
  35. GDCLASS(EditorTexturePreviewPlugin, EditorResourcePreviewGenerator);
  36. public:
  37. virtual bool handles(const String &p_type) const override;
  38. virtual bool generate_small_preview_automatically() const override;
  39. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  40. };
  41. class EditorImagePreviewPlugin : public EditorResourcePreviewGenerator {
  42. GDCLASS(EditorImagePreviewPlugin, EditorResourcePreviewGenerator);
  43. public:
  44. virtual bool handles(const String &p_type) const override;
  45. virtual bool generate_small_preview_automatically() const override;
  46. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  47. };
  48. class EditorBitmapPreviewPlugin : public EditorResourcePreviewGenerator {
  49. GDCLASS(EditorBitmapPreviewPlugin, EditorResourcePreviewGenerator);
  50. public:
  51. virtual bool handles(const String &p_type) const override;
  52. virtual bool generate_small_preview_automatically() const override;
  53. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  54. };
  55. class EditorPackedScenePreviewPlugin : public EditorResourcePreviewGenerator {
  56. GDCLASS(EditorPackedScenePreviewPlugin, EditorResourcePreviewGenerator);
  57. public:
  58. virtual bool handles(const String &p_type) const override;
  59. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  60. virtual Ref<Texture2D> generate_from_path(const String &p_path, const Size2 &p_size, Dictionary &p_metadata) const override;
  61. };
  62. class EditorMaterialPreviewPlugin : public EditorResourcePreviewGenerator {
  63. GDCLASS(EditorMaterialPreviewPlugin, EditorResourcePreviewGenerator);
  64. RID scenario;
  65. RID sphere;
  66. RID sphere_instance;
  67. RID viewport;
  68. RID viewport_texture;
  69. RID light;
  70. RID light_instance;
  71. RID light2;
  72. RID light_instance2;
  73. RID camera;
  74. RID camera_attributes;
  75. mutable DrawRequester draw_requester;
  76. public:
  77. virtual bool handles(const String &p_type) const override;
  78. virtual bool generate_small_preview_automatically() const override;
  79. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  80. virtual void abort() override;
  81. EditorMaterialPreviewPlugin();
  82. ~EditorMaterialPreviewPlugin();
  83. };
  84. class EditorScriptPreviewPlugin : public EditorResourcePreviewGenerator {
  85. GDCLASS(EditorScriptPreviewPlugin, EditorResourcePreviewGenerator);
  86. Ref<Texture2D> _generate_from_source_code(const ScriptLanguage *p_language, const String &p_source_code, const Size2 &p_size, Dictionary &p_metadata) const;
  87. public:
  88. virtual bool handles(const String &p_type) const override;
  89. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  90. virtual Ref<Texture2D> generate_from_path(const String &p_path, const Size2 &p_size, Dictionary &p_metadata) const override;
  91. };
  92. class EditorAudioStreamPreviewPlugin : public EditorResourcePreviewGenerator {
  93. GDCLASS(EditorAudioStreamPreviewPlugin, EditorResourcePreviewGenerator);
  94. public:
  95. virtual bool handles(const String &p_type) const override;
  96. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  97. };
  98. class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator {
  99. GDCLASS(EditorMeshPreviewPlugin, EditorResourcePreviewGenerator);
  100. RID scenario;
  101. RID mesh_instance;
  102. RID viewport;
  103. RID viewport_texture;
  104. RID light;
  105. RID light_instance;
  106. RID light2;
  107. RID light_instance2;
  108. RID camera;
  109. RID camera_attributes;
  110. mutable DrawRequester draw_requester;
  111. public:
  112. virtual bool handles(const String &p_type) const override;
  113. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  114. virtual void abort() override;
  115. EditorMeshPreviewPlugin();
  116. ~EditorMeshPreviewPlugin();
  117. };
  118. class EditorFontPreviewPlugin : public EditorResourcePreviewGenerator {
  119. GDCLASS(EditorFontPreviewPlugin, EditorResourcePreviewGenerator);
  120. RID viewport;
  121. RID viewport_texture;
  122. RID canvas;
  123. RID canvas_item;
  124. mutable DrawRequester draw_requester;
  125. public:
  126. virtual bool handles(const String &p_type) const override;
  127. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  128. virtual Ref<Texture2D> generate_from_path(const String &p_path, const Size2 &p_size, Dictionary &p_metadata) const override;
  129. virtual void abort() override;
  130. EditorFontPreviewPlugin();
  131. ~EditorFontPreviewPlugin();
  132. };
  133. class EditorGradientPreviewPlugin : public EditorResourcePreviewGenerator {
  134. GDCLASS(EditorGradientPreviewPlugin, EditorResourcePreviewGenerator);
  135. public:
  136. virtual bool handles(const String &p_type) const override;
  137. virtual bool generate_small_preview_automatically() const override;
  138. virtual Ref<Texture2D> generate(const Ref<Resource> &p_from, const Size2 &p_size, Dictionary &p_metadata) const override;
  139. };