render_scene_buffers_gles3.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**************************************************************************/
  2. /* render_scene_buffers_gles3.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. #ifdef GLES3_ENABLED
  32. #include "drivers/gles3/effects/glow.h"
  33. #include "servers/rendering/storage/render_scene_buffers.h"
  34. #include "platform_gl.h"
  35. class RenderSceneBuffersGLES3 : public RenderSceneBuffers {
  36. GDCLASS(RenderSceneBuffersGLES3, RenderSceneBuffers);
  37. public:
  38. Size2i internal_size; // Size of the buffer we render 3D content to.
  39. Size2i target_size; // Size of our output buffer (render target).
  40. RS::ViewportScaling3DMode scaling_3d_mode = RS::VIEWPORT_SCALING_3D_MODE_OFF;
  41. //float fsr_sharpness = 0.2f;
  42. //RS::ViewportScreenSpaceAA screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED;
  43. //bool use_taa = false;
  44. //bool use_debanding = false;
  45. uint32_t view_count = 1;
  46. bool apply_color_adjustments_in_post = false;
  47. RID render_target;
  48. // Color format details from our render target
  49. GLuint color_internal_format = GL_RGBA8;
  50. GLuint color_format = GL_RGBA;
  51. GLuint color_type = GL_UNSIGNED_BYTE;
  52. uint32_t color_format_size = 4;
  53. struct FBDEF {
  54. GLuint color = 0;
  55. GLuint depth = 0;
  56. GLuint fbo = 0;
  57. };
  58. struct RTMSAA3D {
  59. RS::ViewportMSAA mode = RS::VIEWPORT_MSAA_DISABLED;
  60. bool needs_resolve = false;
  61. GLsizei samples = 1;
  62. GLuint color = 0;
  63. GLuint depth = 0;
  64. GLuint fbo = 0;
  65. bool check_fbo_cache = false;
  66. Vector<FBDEF> cached_fbos;
  67. } msaa3d; // MSAA buffers used to render 3D
  68. FBDEF internal3d; // buffers used to either render 3D (scaled/post) or to resolve MSAA into
  69. FBDEF backbuffer3d; // our back buffer
  70. // Buffers for our glow implementation
  71. struct GLOW {
  72. GLES3::Glow::GLOWLEVEL levels[4];
  73. } glow;
  74. private:
  75. void _check_render_buffers();
  76. void _clear_msaa3d_buffers();
  77. void _clear_intermediate_buffers();
  78. void _clear_back_buffers();
  79. void _clear_glow_buffers();
  80. void _rt_attach_textures(GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count, bool p_depth_has_stencil);
  81. GLuint _rt_get_cached_fbo(GLuint p_color, GLuint p_depth, GLsizei p_samples, uint32_t p_view_count);
  82. public:
  83. RenderSceneBuffersGLES3();
  84. virtual ~RenderSceneBuffersGLES3();
  85. virtual void configure(const RenderSceneBuffersConfiguration *p_config) override;
  86. void configure_for_probe(Size2i p_size);
  87. virtual void set_anisotropic_filtering_level(RS::ViewportAnisotropicFiltering p_anisotropic_filtering_level) override {}
  88. virtual void set_fsr_sharpness(float p_fsr_sharpness) override {}
  89. virtual void set_texture_mipmap_bias(float p_texture_mipmap_bias) override {}
  90. virtual void set_use_debanding(bool p_use_debanding) override {}
  91. void set_apply_color_adjustments_in_post(bool p_apply_in_post);
  92. void free_render_buffer_data();
  93. void check_backbuffer(bool p_need_color, bool p_need_depth); // Check if we need to initialize our backbuffer.
  94. void check_glow_buffers(); // Check if we need to initialize our glow buffers.
  95. GLuint get_render_fbo();
  96. GLuint get_msaa3d_fbo() {
  97. _check_render_buffers();
  98. return msaa3d.fbo;
  99. }
  100. GLuint get_msaa3d_color() {
  101. _check_render_buffers();
  102. return msaa3d.color;
  103. }
  104. GLuint get_msaa3d_depth() {
  105. _check_render_buffers();
  106. return msaa3d.depth;
  107. }
  108. bool get_msaa_needs_resolve() {
  109. _check_render_buffers();
  110. return msaa3d.needs_resolve;
  111. }
  112. GLuint get_internal_fbo() {
  113. _check_render_buffers();
  114. return internal3d.fbo;
  115. }
  116. GLuint get_internal_color() {
  117. _check_render_buffers();
  118. return internal3d.color;
  119. }
  120. GLuint get_internal_depth() {
  121. _check_render_buffers();
  122. return internal3d.depth;
  123. }
  124. GLuint get_backbuffer_fbo() const { return backbuffer3d.fbo; }
  125. GLuint get_backbuffer() const { return backbuffer3d.color; }
  126. GLuint get_backbuffer_depth() const { return backbuffer3d.depth; }
  127. const GLES3::Glow::GLOWLEVEL *get_glow_buffers() const { return &glow.levels[0]; }
  128. // Getters
  129. _FORCE_INLINE_ RID get_render_target() const { return render_target; }
  130. _FORCE_INLINE_ uint32_t get_view_count() const { return view_count; }
  131. _FORCE_INLINE_ Size2i get_internal_size() const { return internal_size; }
  132. _FORCE_INLINE_ Size2i get_target_size() const { return target_size; }
  133. _FORCE_INLINE_ RS::ViewportScaling3DMode get_scaling_3d_mode() const { return scaling_3d_mode; }
  134. //_FORCE_INLINE_ float get_fsr_sharpness() const { return fsr_sharpness; }
  135. _FORCE_INLINE_ RS::ViewportMSAA get_msaa_3d() const { return msaa3d.mode; }
  136. //_FORCE_INLINE_ RS::ViewportScreenSpaceAA get_screen_space_aa() const { return screen_space_aa; }
  137. //_FORCE_INLINE_ bool get_use_taa() const { return use_taa; }
  138. //_FORCE_INLINE_ bool get_use_debanding() const { return use_debanding; }
  139. };
  140. #endif // GLES3_ENABLED