diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 278cefdf8e..b2b3263f00 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -210,23 +210,21 @@ void OpenGLFrameBuffer::CopyScreenToBuffer(int width, int height, uint8_t* scr) // //=========================================================================== -void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, AActor* Viewpoint, double FOV) +void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) + { - // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. - - float ratio = tex->aspectRatio; - GLRenderer->StartOffscreen(); GLRenderer->BindToFrameBuffer(tex); + // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. + float ratio = tex->aspectRatio; + IntRect bounds; bounds.left = bounds.top = 0; bounds.width = FHardwareTexture::GetTexDimension(tex->GetWidth()); bounds.height = FHardwareTexture::GetTexDimension(tex->GetHeight()); - FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); - + renderFunc(bounds); GLRenderer->EndOffscreen(); tex->SetUpdated(true); @@ -283,7 +281,12 @@ sector_t *OpenGLFrameBuffer::RenderView(player_t *player) { Level->canvasTextureInfo.UpdateAll([&](AActor* camera, FCanvasTexture* camtex, double fov) { - RenderTextureView(camtex, camera, fov); + RenderTextureView(camtex, [=](IntRect &bounds) + { + FRenderViewpoint texvp; + float ratio = camtex->aspectRatio; + RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); + }); }); } NoInterpolateView = saved_niv; diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index 5412293aee..f84fcf8b70 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -16,7 +16,7 @@ class OpenGLFrameBuffer : public SystemGLFrameBuffer { typedef SystemGLFrameBuffer Super; - void RenderTextureView(FCanvasTexture* tex, AActor* Viewpoint, double FOV); + void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; public: diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 9a02a6b223..dbbde9492b 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -261,7 +261,12 @@ sector_t *PolyFrameBuffer::RenderView(player_t *player) { Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) { - RenderTextureView(camtex, camera, fov); + RenderTextureView(camtex, [=](IntRect &bounds) + { + FRenderViewpoint texvp; + float ratio = camtex->aspectRatio; + RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); + }); }); } NoInterpolateView = saved_niv; @@ -285,7 +290,7 @@ sector_t *PolyFrameBuffer::RenderView(player_t *player) } -void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) +void PolyFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) { // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); @@ -300,8 +305,7 @@ void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, bounds.width = std::min(tex->GetWidth(), image->GetWidth()); bounds.height = std::min(tex->GetHeight(), image->GetHeight()); - FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); + renderFunc(bounds); FlushDrawCommands(); DrawerThreads::WaitForWorkers(); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index ad7bc56ba8..d902e6fe3f 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -70,7 +70,7 @@ public: } FrameDeleteList; private: - void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); + void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; void UpdateShadowMap(); void CheckCanvas(); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index a504c37002..79aa6cbdca 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -320,6 +320,7 @@ public: virtual void ImageTransitionScene(bool unknown) {} virtual void CopyScreenToBuffer(int width, int height, uint8_t* buffer) { memset(buffer, 0, width* height); } virtual bool FlipSavePic() const { return false; } + virtual void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) {} // Screen wiping diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 0fabe75ae8..a276ee3a2b 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -363,7 +363,12 @@ sector_t *VulkanFrameBuffer::RenderView(player_t *player) { Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) { - RenderTextureView(camtex, camera, fov); + RenderTextureView(camtex, [=](IntRect &bounds) + { + FRenderViewpoint texvp; + float ratio = camtex->aspectRatio; + RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); + }); }); } NoInterpolateView = saved_niv; @@ -388,11 +393,12 @@ sector_t *VulkanFrameBuffer::RenderView(player_t *player) return retsec; } -void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) +void VulkanFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) + { + // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); - float ratio = tex->aspectRatio; VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0); VkTextureImage *depthStencil = BaseLayer->GetDepthStencil(tex); @@ -404,13 +410,13 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint mRenderState->SetRenderTarget(image, depthStencil->View.get(), image->Image->width, image->Image->height, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT); + float ratio = tex->aspectRatio; IntRect bounds; bounds.left = bounds.top = 0; bounds.width = std::min(tex->GetWidth(), image->Image->width); bounds.height = std::min(tex->GetHeight(), image->Image->height); - FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); + renderFunc(bounds); mRenderState->EndRenderPass(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 85a5d363ff..9b26c4b153 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -114,9 +114,11 @@ public: void PushGroup(const FString &name); void PopGroup(); void UpdateGpuStats(); + IntRect SetupTextureView(FCanvasTexture* tex); + void FinishTextureView(FCanvasTexture* tex); private: - void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); + void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; void PrintStartupLog(); void CreateFanToTrisIndexBuffer(); void CopyScreenToBuffer(int w, int h, uint8_t *data) override;