renderer_compositor_rd.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**************************************************************************/
  2. /* renderer_compositor_rd.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. #ifndef RENDERER_COMPOSITOR_RD_H
  31. #define RENDERER_COMPOSITOR_RD_H
  32. #include "core/os/os.h"
  33. #include "servers/rendering/renderer_compositor.h"
  34. #include "servers/rendering/renderer_rd/effects_rd.h"
  35. #include "servers/rendering/renderer_rd/environment/fog.h"
  36. #include "servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h"
  37. #include "servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h"
  38. #include "servers/rendering/renderer_rd/framebuffer_cache_rd.h"
  39. #include "servers/rendering/renderer_rd/renderer_canvas_render_rd.h"
  40. #include "servers/rendering/renderer_rd/shaders/blit.glsl.gen.h"
  41. #include "servers/rendering/renderer_rd/storage_rd/light_storage.h"
  42. #include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
  43. #include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"
  44. #include "servers/rendering/renderer_rd/storage_rd/particles_storage.h"
  45. #include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
  46. #include "servers/rendering/renderer_rd/storage_rd/utilities.h"
  47. #include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"
  48. class RendererCompositorRD : public RendererCompositor {
  49. protected:
  50. UniformSetCacheRD *uniform_set_cache = nullptr;
  51. FramebufferCacheRD *framebuffer_cache = nullptr;
  52. RendererCanvasRenderRD *canvas = nullptr;
  53. RendererRD::Utilities *utilities = nullptr;
  54. RendererRD::LightStorage *light_storage = nullptr;
  55. RendererRD::MaterialStorage *material_storage = nullptr;
  56. RendererRD::MeshStorage *mesh_storage = nullptr;
  57. RendererRD::ParticlesStorage *particles_storage = nullptr;
  58. RendererRD::TextureStorage *texture_storage = nullptr;
  59. RendererRD::Fog *fog = nullptr;
  60. EffectsRD *effects = nullptr;
  61. RendererSceneRenderRD *scene = nullptr;
  62. enum BlitMode {
  63. BLIT_MODE_NORMAL,
  64. BLIT_MODE_USE_LAYER,
  65. BLIT_MODE_LENS,
  66. BLIT_MODE_NORMAL_ALPHA,
  67. BLIT_MODE_MAX
  68. };
  69. struct BlitPushConstant {
  70. float src_rect[4];
  71. float dst_rect[4];
  72. float eye_center[2];
  73. float k1;
  74. float k2;
  75. float upscale;
  76. float aspect_ratio;
  77. uint32_t layer;
  78. uint32_t pad1;
  79. };
  80. struct Blit {
  81. BlitPushConstant push_constant;
  82. BlitShaderRD shader;
  83. RID shader_version;
  84. RID pipelines[BLIT_MODE_MAX];
  85. RID index_buffer;
  86. RID array;
  87. RID sampler;
  88. } blit;
  89. HashMap<RID, RID> render_target_descriptors;
  90. double time = 0.0;
  91. double delta = 0.0;
  92. static uint64_t frame;
  93. static RendererCompositorRD *singleton;
  94. public:
  95. RendererUtilities *get_utilities() { return utilities; };
  96. RendererLightStorage *get_light_storage() { return light_storage; }
  97. RendererMaterialStorage *get_material_storage() { return material_storage; }
  98. RendererMeshStorage *get_mesh_storage() { return mesh_storage; }
  99. RendererParticlesStorage *get_particles_storage() { return particles_storage; }
  100. RendererTextureStorage *get_texture_storage() { return texture_storage; }
  101. RendererGI *get_gi() {
  102. ERR_FAIL_NULL_V(scene, nullptr);
  103. return scene->get_gi();
  104. }
  105. RendererFog *get_fog() { return fog; }
  106. EffectsRD *get_effects() { return effects; }
  107. RendererCanvasRender *get_canvas() { return canvas; }
  108. RendererSceneRender *get_scene() { return scene; }
  109. void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter);
  110. void initialize();
  111. void begin_frame(double frame_step);
  112. void prepare_for_blitting_render_targets();
  113. void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount);
  114. void end_frame(bool p_swap_buffers);
  115. void finalize();
  116. _ALWAYS_INLINE_ uint64_t get_frame_number() const { return frame; }
  117. _ALWAYS_INLINE_ double get_frame_delta_time() const { return delta; }
  118. _ALWAYS_INLINE_ double get_total_time() const { return time; }
  119. static Error is_viable() {
  120. return OK;
  121. }
  122. static RendererCompositor *_create_current() {
  123. return memnew(RendererCompositorRD);
  124. }
  125. static void make_current() {
  126. _create_func = _create_current;
  127. low_end = false;
  128. }
  129. static RendererCompositorRD *get_singleton() { return singleton; }
  130. RendererCompositorRD();
  131. ~RendererCompositorRD();
  132. };
  133. #endif // RENDERER_COMPOSITOR_RD_H