diff options
author | Bastiaan Olij <mux213@gmail.com> | 2022-08-04 18:40:39 +1000 |
---|---|---|
committer | Bastiaan Olij <mux213@gmail.com> | 2022-09-01 20:01:45 +1000 |
commit | 2cd84be64da98b093ec248fd061702783adfd8b0 (patch) | |
tree | d32a65b9eb0d1e88537a71abea784315cd959e84 /drivers/gles3/storage | |
parent | 0c221f0284909a1156a1c98de5104e07c1cce0b9 (diff) |
Extracting render buffers and changing it to a more generic solution
Diffstat (limited to 'drivers/gles3/storage')
-rw-r--r-- | drivers/gles3/storage/render_scene_buffers_gles3.cpp | 103 | ||||
-rw-r--r-- | drivers/gles3/storage/render_scene_buffers_gles3.h | 98 |
2 files changed, 201 insertions, 0 deletions
diff --git a/drivers/gles3/storage/render_scene_buffers_gles3.cpp b/drivers/gles3/storage/render_scene_buffers_gles3.cpp new file mode 100644 index 0000000000..5d121e2ef9 --- /dev/null +++ b/drivers/gles3/storage/render_scene_buffers_gles3.cpp @@ -0,0 +1,103 @@ +/*************************************************************************/ +/* render_scene_buffers_gles3.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifdef GLES3_ENABLED + +#include "render_scene_buffers_gles3.h" +#include "texture_storage.h" + +RenderSceneBuffersGLES3::~RenderSceneBuffersGLES3() { + free_render_buffer_data(); +} + +void RenderSceneBuffersGLES3::configure(RID p_render_target, const Size2i p_internal_size, const Size2i p_target_size, float p_fsr_sharpness, float p_texture_mipmap_bias, RS::ViewportMSAA p_msaa, RenderingServer::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_taa, bool p_use_debanding, uint32_t p_view_count) { + GLES3::TextureStorage *texture_storage = GLES3::TextureStorage::get_singleton(); + + //internal_size.x = p_internal_size.x; // ignore for now + //internal_size.y = p_internal_size.y; + width = p_target_size.x; + height = p_target_size.y; + //fsr_sharpness = p_fsr_sharpness; + //texture_mipmap_bias = p_texture_mipmap_bias; + render_target = p_render_target; + //msaa = p_msaa; + //screen_space_aa = p_screen_space_aa; + //use_debanding = p_use_debanding; + //view_count = p_view_count; + + free_render_buffer_data(); + + GLES3::RenderTarget *rt = texture_storage->get_render_target(p_render_target); + + is_transparent = rt->is_transparent; + + // framebuffer + glGenFramebuffers(1, &framebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + + glBindTexture(GL_TEXTURE_2D, rt->color); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rt->color, 0); + + glGenTextures(1, &depth_texture); + glBindTexture(GL_TEXTURE_2D, depth_texture); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, rt->size.x, rt->size.y, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture, 0); + + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + + glBindTexture(GL_TEXTURE_2D, 0); + glBindFramebuffer(GL_FRAMEBUFFER, texture_storage->system_fbo); + + if (status != GL_FRAMEBUFFER_COMPLETE) { + free_render_buffer_data(); + WARN_PRINT("Could not create 3D renderbuffer, status: " + texture_storage->get_framebuffer_error(status)); + return; + } +} + +void RenderSceneBuffersGLES3::free_render_buffer_data() { + if (depth_texture) { + glDeleteTextures(1, &depth_texture); + depth_texture = 0; + } + if (framebuffer) { + glDeleteFramebuffers(1, &framebuffer); + framebuffer = 0; + } +} + +#endif // GLES3_ENABLED diff --git a/drivers/gles3/storage/render_scene_buffers_gles3.h b/drivers/gles3/storage/render_scene_buffers_gles3.h new file mode 100644 index 0000000000..ad0d2032b0 --- /dev/null +++ b/drivers/gles3/storage/render_scene_buffers_gles3.h @@ -0,0 +1,98 @@ +/*************************************************************************/ +/* render_scene_buffers_gles3.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef RENDER_SCENE_BUFFERS_GLES3_H +#define RENDER_SCENE_BUFFERS_GLES3_H + +#ifdef GLES3_ENABLED + +#include "servers/rendering/storage/render_scene_buffers.h" + +#include "platform_config.h" +#ifndef OPENGL_INCLUDE_H +#include <GLES3/gl3.h> +#else +#include OPENGL_INCLUDE_H +#endif + +class RenderSceneBuffersGLES3 : public RenderSceneBuffers { + GDCLASS(RenderSceneBuffersGLES3, RenderSceneBuffers); + +public: + // Original implementation, need to investigate which ones we'll keep like this and what we'll change... + + int internal_width = 0; + int internal_height = 0; + int width = 0; + int height = 0; + //float fsr_sharpness = 0.2f; + RS::ViewportMSAA msaa = RS::VIEWPORT_MSAA_DISABLED; + //RS::ViewportScreenSpaceAA screen_space_aa = RS::VIEWPORT_SCREEN_SPACE_AA_DISABLED; + //bool use_debanding = false; + //uint32_t view_count = 1; + + bool is_transparent = false; + + RID render_target; + GLuint internal_texture = 0; // Used for rendering when post effects are enabled + GLuint depth_texture = 0; // Main depth texture + GLuint framebuffer = 0; // Main framebuffer, contains internal_texture and depth_texture or render_target->color and depth_texture + + //built-in textures used for ping pong image processing and blurring + struct Blur { + RID texture; + + struct Mipmap { + RID texture; + int width; + int height; + GLuint fbo; + }; + + Vector<Mipmap> mipmaps; + }; + + Blur blur[2]; //the second one starts from the first mipmap + +private: +public: + virtual ~RenderSceneBuffersGLES3(); + virtual void configure(RID p_render_target, const Size2i p_internal_size, const Size2i p_target_size, float p_fsr_sharpness, float p_texture_mipmap_bias, RS::ViewportMSAA p_msaa, RenderingServer::ViewportScreenSpaceAA p_screen_space_aa, bool p_use_taa, bool p_use_debanding, uint32_t p_view_count) override; + + virtual void set_fsr_sharpness(float p_fsr_sharpness) override{}; + virtual void set_texture_mipmap_bias(float p_texture_mipmap_bias) override{}; + virtual void set_use_debanding(bool p_use_debanding) override{}; + + void free_render_buffer_data(); +}; + +#endif // GLES3_ENABLED + +#endif // RENDER_SCENE_BUFFERS_GLES3_H |