- reworked canvas texture updater to avoid passing game data to the render backends.

These are now handled one level above using a callback to perform the actual rendering.
This commit is contained in:
Christoph Oelckers 2020-04-25 14:13:36 +02:00
parent 44d39ef63e
commit 730d07fbf7
7 changed files with 37 additions and 21 deletions

View File

@ -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<void(IntRect &)> 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;

View File

@ -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<void(IntRect &)> renderFunc) override;
public:

View File

@ -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<void(IntRect &)> 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<PolyHardwareTexture*>(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();

View File

@ -70,7 +70,7 @@ public:
} FrameDeleteList;
private:
void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV);
void RenderTextureView(FCanvasTexture* tex, std::function<void(IntRect &)> renderFunc) override;
void UpdateShadowMap();
void CheckCanvas();

View File

@ -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<void(IntRect&)> renderFunc) {}
// Screen wiping

View File

@ -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<void(IntRect &)> 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<VkHardwareTexture*>(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();

View File

@ -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<void(IntRect &)> renderFunc) override;
void PrintStartupLog();
void CreateFanToTrisIndexBuffer();
void CopyScreenToBuffer(int w, int h, uint8_t *data) override;