From daa598954ffa879747471662be9afab543e4bdce Mon Sep 17 00:00:00 2001 From: youle31 Date: Thu, 27 Jul 2023 21:14:47 +0200 Subject: [PATCH] UPBGE: Change previous commmit to fix https://github.com/UPBGE/upbge/issues/1827 because i was not comfortable with what i did previously --- source/gameengine/Ketsji/KX_Scene.cpp | 7 ++++--- .../gameengine/Rasterizer/RAS_FrameBuffer.cpp | 17 +++++++++++++++++ source/gameengine/Rasterizer/RAS_FrameBuffer.h | 2 ++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 11719551ee43..19274015b442 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -886,15 +886,16 @@ void KX_Scene::RenderAfterCameraSetup(KX_Camera *cam, RAS_FrameBuffer *input = rasty->GetFrameBuffer(rasty->NextFilterFrameBuffer(r)); RAS_FrameBuffer *output = rasty->GetFrameBuffer(rasty->NextRenderFrameBuffer(s)); + GPUTexture *color = GPU_viewport_color_texture(m_currentGPUViewport, 0); + GPUAttachment config[] = { GPU_ATTACHMENT_TEXTURE(GPU_viewport_depth_texture(m_currentGPUViewport)), - GPU_ATTACHMENT_TEXTURE(GPU_viewport_color_texture(m_currentGPUViewport, 0))}; + GPU_ATTACHMENT_TEXTURE(color)}; GPU_framebuffer_config_array( input->GetFrameBuffer(), config, sizeof(config) / sizeof(GPUAttachment)); - GPU_framebuffer_config_array( - output->GetFrameBuffer(), config, sizeof(config) / sizeof(GPUAttachment)); + output->UpdateSize(GPU_texture_width(color), GPU_texture_height(color)); RAS_FrameBuffer *f = is_overlay_pass ? input : Render2DFilters(rasty, canvas, input, output); diff --git a/source/gameengine/Rasterizer/RAS_FrameBuffer.cpp b/source/gameengine/Rasterizer/RAS_FrameBuffer.cpp index c6dc7d679a7f..6c9519c64eb1 100644 --- a/source/gameengine/Rasterizer/RAS_FrameBuffer.cpp +++ b/source/gameengine/Rasterizer/RAS_FrameBuffer.cpp @@ -78,6 +78,23 @@ GPUTexture *RAS_FrameBuffer::GetDepthAttachment() return m_depthAttachment; } +void RAS_FrameBuffer::UpdateSize(int width, int height) +{ + if (GPU_texture_width(m_colorAttachment) != width || + GPU_texture_height(m_colorAttachment) != height) { + GPU_texture_free(m_colorAttachment); + GPU_texture_free(m_depthAttachment); + m_colorAttachment = GPU_texture_create_2d( + "color_tex", width, height, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_GENERAL, nullptr); + m_depthAttachment = GPU_texture_create_2d( + "depth_tex", width, height, 1, GPU_DEPTH24_STENCIL8, GPU_TEXTURE_USAGE_GENERAL, nullptr); + GPUAttachment config[] = {GPU_ATTACHMENT_TEXTURE(m_depthAttachment), + GPU_ATTACHMENT_TEXTURE(m_colorAttachment)}; + + GPU_framebuffer_config_array(m_frameBuffer, config, sizeof(config) / sizeof(GPUAttachment)); + } +} + RAS_Rasterizer::FrameBufferType RAS_FrameBuffer::GetType() const { return m_frameBufferType; diff --git a/source/gameengine/Rasterizer/RAS_FrameBuffer.h b/source/gameengine/Rasterizer/RAS_FrameBuffer.h index 05570a74cb5d..0f5f7c1a1898 100644 --- a/source/gameengine/Rasterizer/RAS_FrameBuffer.h +++ b/source/gameengine/Rasterizer/RAS_FrameBuffer.h @@ -57,5 +57,7 @@ class RAS_FrameBuffer { GPUTexture *GetColorAttachment(); GPUTexture *GetDepthAttachment(); + void UpdateSize(int width, int height); + RAS_Rasterizer::FrameBufferType GetType() const; };