Adds BeginFramebufferPass/EndFramebufferPass instead of SetFramebuffer.

This was SVN commit r27151.
This commit is contained in:
vladislavbelov 2022-10-12 21:51:27 +00:00
parent b59e798ef4
commit d3f0395d2a
15 changed files with 85 additions and 65 deletions

View file

@ -143,7 +143,7 @@ void CLOSTexture::InterpolateLOS(Renderer::Backend::IDeviceCommandContext* devic
return;
GPU_SCOPED_LABEL(deviceCommandContext, "Render LOS texture");
deviceCommandContext->SetFramebuffer(m_SmoothFramebuffers[m_WhichTexture].get());
deviceCommandContext->BeginFramebufferPass(m_SmoothFramebuffers[m_WhichTexture].get());
deviceCommandContext->SetGraphicsPipelineState(
m_SmoothTech->GetGraphicsPipelineStateDesc());
@ -209,9 +209,7 @@ void CLOSTexture::InterpolateLOS(Renderer::Backend::IDeviceCommandContext* devic
g_Renderer.SetViewport(oldVp);
deviceCommandContext->EndPass();
deviceCommandContext->SetFramebuffer(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
deviceCommandContext->EndFramebufferPass();
}

View file

@ -447,7 +447,7 @@ void CMiniMapTexture::RenderFinalTexture(
PROFILE3("Render minimap texture");
GPU_SCOPED_LABEL(deviceCommandContext, "Render minimap texture");
deviceCommandContext->SetFramebuffer(m_FinalTextureFramebuffer.get());
deviceCommandContext->BeginFramebufferPass(m_FinalTextureFramebuffer.get());
const SViewPort oldViewPort = g_Renderer.GetViewport();
const SViewPort viewPort = { 0, 0, FINAL_TEXTURE_SIZE, FINAL_TEXTURE_SIZE };
@ -817,8 +817,7 @@ void CMiniMapTexture::RenderFinalTexture(
deviceCommandContext->EndPass();
}
deviceCommandContext->SetFramebuffer(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
deviceCommandContext->EndFramebufferPass();
g_Renderer.SetViewport(oldViewPort);
}

View file

@ -190,7 +190,7 @@ void CPostprocManager::ApplyBlurDownscale2x(
Renderer::Backend::IFramebuffer* framebuffer,
Renderer::Backend::ITexture* inTex, int inWidth, int inHeight)
{
deviceCommandContext->SetFramebuffer(framebuffer);
deviceCommandContext->BeginFramebufferPass(framebuffer);
// Get bloom shader with instructions to simply copy texels.
CShaderDefines defines;
@ -250,6 +250,7 @@ void CPostprocManager::ApplyBlurDownscale2x(
g_Renderer.SetViewport(oldVp);
deviceCommandContext->EndPass();
deviceCommandContext->EndFramebufferPass();
}
void CPostprocManager::ApplyBlurGauss(
@ -260,7 +261,7 @@ void CPostprocManager::ApplyBlurGauss(
Renderer::Backend::IFramebuffer* outFramebuffer,
int inWidth, int inHeight)
{
deviceCommandContext->SetFramebuffer(tempFramebuffer);
deviceCommandContext->BeginFramebufferPass(tempFramebuffer);
// Get bloom shader, for a horizontal Gaussian blur pass.
CShaderDefines defines2;
@ -320,8 +321,9 @@ void CPostprocManager::ApplyBlurGauss(
g_Renderer.SetViewport(oldVp);
deviceCommandContext->EndPass();
deviceCommandContext->EndFramebufferPass();
deviceCommandContext->SetFramebuffer(outFramebuffer);
deviceCommandContext->BeginFramebufferPass(outFramebuffer);
// Get bloom shader, for a vertical Gaussian blur pass.
CShaderDefines defines3;
@ -360,6 +362,7 @@ void CPostprocManager::ApplyBlurGauss(
g_Renderer.SetViewport(oldVp);
deviceCommandContext->EndPass();
deviceCommandContext->EndFramebufferPass();
}
void CPostprocManager::ApplyBlur(
@ -388,10 +391,8 @@ void CPostprocManager::CaptureRenderOutput(
// Leaves m_PingFbo selected for rendering; m_WhichBuffer stays true at this point.
if (m_UsingMultisampleBuffer)
deviceCommandContext->SetFramebuffer(m_MultisampleFramebuffer.get());
else
deviceCommandContext->SetFramebuffer(m_CaptureFramebuffer.get());
deviceCommandContext->BeginFramebufferPass(
m_UsingMultisampleBuffer ? m_MultisampleFramebuffer.get() : m_CaptureFramebuffer.get());
m_WhichBuffer = true;
}
@ -408,9 +409,6 @@ void CPostprocManager::ReleaseRenderOutput(
deviceCommandContext->BlitFramebuffer(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer(),
(m_WhichBuffer ? m_PingFramebuffer : m_PongFramebuffer).get());
deviceCommandContext->SetFramebuffer(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
}
void CPostprocManager::ApplyEffect(
@ -418,7 +416,7 @@ void CPostprocManager::ApplyEffect(
const CShaderTechniquePtr& shaderTech, int pass)
{
// select the other FBO for rendering
deviceCommandContext->SetFramebuffer(
deviceCommandContext->BeginFramebufferPass(
(m_WhichBuffer ? m_PongFramebuffer : m_PingFramebuffer).get());
deviceCommandContext->SetGraphicsPipelineState(
@ -492,6 +490,7 @@ void CPostprocManager::ApplyEffect(
deviceCommandContext->Draw(0, 6);
deviceCommandContext->EndPass();
deviceCommandContext->EndFramebufferPass();
m_WhichBuffer = !m_WhichBuffer;
}
@ -704,5 +703,4 @@ void CPostprocManager::ResolveMultisampleFramebuffer(
GPU_SCOPED_LABEL(deviceCommandContext, "Resolve postproc multisample");
deviceCommandContext->BlitFramebuffer(
m_PingFramebuffer.get(), m_MultisampleFramebuffer.get());
deviceCommandContext->SetFramebuffer(m_PingFramebuffer.get());
}

View file

@ -90,9 +90,11 @@ private:
void CreateMultisampleBuffer();
void DestroyMultisampleBuffer();
std::unique_ptr<Renderer::Backend::IFramebuffer> m_CaptureFramebuffer;
// Two framebuffers, that we flip between at each shader pass.
std::unique_ptr<Renderer::Backend::IFramebuffer>
m_CaptureFramebuffer, m_PingFramebuffer, m_PongFramebuffer;
m_PingFramebuffer, m_PongFramebuffer;
// Unique color textures for the framebuffers.
std::unique_ptr<Renderer::Backend::ITexture> m_ColorTex1, m_ColorTex2;

View file

@ -462,7 +462,7 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
g_Game->GetView()->Render();
}
m->deviceCommandContext->SetFramebuffer(
m->deviceCommandContext->BeginFramebufferPass(
m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
// If we're in Atlas game view, render special tools
@ -478,6 +478,8 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
RenderFrame2D(renderGUI, renderLogger);
m->deviceCommandContext->EndFramebufferPass();
EndFrame();
const Stats& stats = GetStats();

View file

@ -305,13 +305,13 @@ void CSceneRenderer::RenderShadowMap(
CShaderDefines contextCast = shadowsContext;
contextCast.Add(str_MODE_SHADOWCAST, str_1);
m->shadow.BeginRender();
m->shadow.BeginRender(deviceCommandContext);
const int cascadeCount = m->shadow.GetCascadeCount();
ENSURE(0 <= cascadeCount && cascadeCount <= 4);
for (int cascade = 0; cascade < cascadeCount; ++cascade)
{
m->shadow.PrepareCamera(cascade);
m->shadow.PrepareCamera(deviceCommandContext, cascade);
const int cullGroup = CULL_SHADOWS_CASCADE_0 + cascade;
{
@ -330,7 +330,7 @@ void CSceneRenderer::RenderShadowMap(
}
}
m->shadow.EndRender();
m->shadow.EndRender(deviceCommandContext);
g_Renderer.SetViewport(m_ViewCamera.GetViewPort());
}
@ -587,7 +587,7 @@ void CSceneRenderer::RenderReflections(
deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
deviceCommandContext->SetFramebuffer(wm.m_ReflectionFramebuffer.get());
deviceCommandContext->BeginFramebufferPass(wm.m_ReflectionFramebuffer.get());
deviceCommandContext->ClearFramebuffer();
CShaderDefines reflectionsContext = context;
@ -606,6 +606,7 @@ void CSceneRenderer::RenderReflections(
}
deviceCommandContext->SetScissors(0, nullptr);
deviceCommandContext->EndFramebufferPass();
// Reset old camera
m_ViewCamera = normalCamera;
@ -662,7 +663,7 @@ void CSceneRenderer::RenderRefractions(
deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
deviceCommandContext->SetFramebuffer(wm.m_RefractionFramebuffer.get());
deviceCommandContext->BeginFramebufferPass(wm.m_RefractionFramebuffer.get());
deviceCommandContext->ClearFramebuffer();
// Render terrain and models
@ -675,6 +676,7 @@ void CSceneRenderer::RenderRefractions(
RenderTransparentModels(deviceCommandContext, context, CULL_REFRACTIONS, TRANSPARENT_OPAQUE);
deviceCommandContext->SetScissors(0, nullptr);
deviceCommandContext->EndFramebufferPass();
// Reset old camera
m_ViewCamera = normalCamera;
@ -831,7 +833,7 @@ void CSceneRenderer::RenderSubmissions(
}
else
{
deviceCommandContext->SetFramebuffer(
deviceCommandContext->BeginFramebufferPass(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
}
@ -896,11 +898,15 @@ void CSceneRenderer::RenderSubmissions(
if (postprocManager.IsEnabled())
{
deviceCommandContext->EndFramebufferPass();
if (g_Renderer.GetPostprocManager().IsMultisampleEnabled())
g_Renderer.GetPostprocManager().ResolveMultisampleFramebuffer(deviceCommandContext);
postprocManager.ApplyPostproc(deviceCommandContext);
postprocManager.ReleaseRenderOutput(deviceCommandContext);
deviceCommandContext->BeginFramebufferPass(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
}
if (g_RenderingOptions.GetSilhouettes())
@ -920,6 +926,8 @@ void CSceneRenderer::RenderSubmissions(
// render overlays that should appear on top of all other objects
m->overlayRenderer.RenderForegroundOverlays(deviceCommandContext, m_ViewCamera);
deviceCommandContext->EndFramebufferPass();
}
void CSceneRenderer::EndFrame()

View file

@ -565,18 +565,16 @@ void ShadowMapInternals::CreateTexture()
}
}
// Set up to render into shadow map texture
void ShadowMap::BeginRender()
void ShadowMap::BeginRender(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
{
Renderer::Backend::IDeviceCommandContext* deviceCommandContext =
g_Renderer.GetDeviceCommandContext();
deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
{
PROFILE("bind framebuffer");
ENSURE(m->Framebuffer);
deviceCommandContext->SetFramebuffer(m->Framebuffer.get());
deviceCommandContext->BeginFramebufferPass(m->Framebuffer.get());
}
// clear buffers
@ -591,7 +589,8 @@ void ShadowMap::BeginRender()
m->SavedViewCamera = g_Renderer.GetSceneRenderer().GetViewCamera();
}
void ShadowMap::PrepareCamera(const int cascade)
void ShadowMap::PrepareCamera(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const int cascade)
{
m->CalculateShadowMatrices(cascade);
@ -609,22 +608,18 @@ void ShadowMap::PrepareCamera(const int cascade)
scissorRect.y = cascadeViewPort.m_Y;
scissorRect.width = cascadeViewPort.m_Width;
scissorRect.height = cascadeViewPort.m_Height;
g_Renderer.GetDeviceCommandContext()->SetScissors(1, &scissorRect);
deviceCommandContext->SetScissors(1, &scissorRect);
}
// Finish rendering into shadow map texture
void ShadowMap::EndRender()
void ShadowMap::EndRender(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
{
g_Renderer.GetDeviceCommandContext()->SetScissors(0, nullptr);
deviceCommandContext->SetScissors(0, nullptr);
deviceCommandContext->EndFramebufferPass();
g_Renderer.GetSceneRenderer().SetViewCamera(m->SavedViewCamera);
{
PROFILE("unbind framebuffer");
g_Renderer.GetDeviceCommandContext()->SetFramebuffer(
g_VideoMode.GetBackendDevice()->GetCurrentBackbuffer());
}
const SViewPort vp = { 0, 0, g_Renderer.GetWidth(), g_Renderer.GetHeight() };
g_Renderer.SetViewport(vp);
}

View file

@ -100,18 +100,14 @@ public:
CFrustum GetShadowCasterCullFrustum(const int cascade);
/**
* BeginRender: Set OpenGL state for rendering into the shadow map texture.
*
* @todo this depends in non-obvious ways on the behaviour of the call-site
* Sets backend state for rendering into the shadow map texture.
*/
void BeginRender();
void BeginRender(Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
/**
* EndRender: Finish rendering into the shadow map.
*
* @todo this depends in non-obvious ways on the behaviour of the call-site
* Finishes rendering into the shadow map.
*/
void EndRender();
void EndRender(Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
/**
* Returns the current number of used cascades.
@ -121,7 +117,8 @@ public:
/**
* Sets the renderer camera for the cascade.
*/
void PrepareCamera(const int cascade);
void PrepareCamera(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, const int cascade);
/**
* Binds all needed resources and uniforms to draw shadows using the shader.

View file

@ -682,7 +682,7 @@ void TerrainRenderer::RenderWaterFoamOccluders(
GPU_SCOPED_LABEL(deviceCommandContext, "Render water foam occluders");
// Render normals and foam to a framebuffer if we're using fancy effects.
deviceCommandContext->SetFramebuffer(waterManager.m_FancyEffectsFramebuffer.get());
deviceCommandContext->BeginFramebufferPass(waterManager.m_FancyEffectsFramebuffer.get());
// Overwrite waves that would be behind the ground.
CShaderTechniquePtr dummyTech = g_Renderer.GetShaderManager().LoadEffect(str_solid);
@ -706,8 +706,7 @@ void TerrainRenderer::RenderWaterFoamOccluders(
deviceCommandContext->EndPass();
deviceCommandContext->SetFramebuffer(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
deviceCommandContext->EndFramebufferPass();
}
void TerrainRenderer::RenderPriorities(CCanvas2D& canvas, int cullGroup)

View file

@ -788,13 +788,14 @@ void WaterManager::RenderWaves(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
const CFrustum& frustrum)
{
GPU_SCOPED_LABEL(deviceCommandContext, "Render Waves");
if (!m_WaterFancyEffects)
return;
GPU_SCOPED_LABEL(deviceCommandContext, "Render Waves");
deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
deviceCommandContext->SetFramebuffer(m_FancyEffectsFramebuffer.get());
deviceCommandContext->BeginFramebufferPass(m_FancyEffectsFramebuffer.get());
deviceCommandContext->ClearFramebuffer();
CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_water_waves);
@ -878,8 +879,7 @@ void WaterManager::RenderWaves(
g_Renderer.GetStats().m_WaterTris += indexCount / 3;
}
deviceCommandContext->EndPass();
deviceCommandContext->SetFramebuffer(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
deviceCommandContext->EndFramebufferPass();
}
void WaterManager::RecomputeWaterData()

View file

@ -47,7 +47,8 @@ public:
virtual void ClearFramebuffer() = 0;
virtual void ClearFramebuffer(const bool color, const bool depth, const bool stencil) = 0;
virtual void SetFramebuffer(IFramebuffer* framebuffer) = 0;
virtual void BeginFramebufferPass(IFramebuffer* framebuffer) = 0;
virtual void EndFramebufferPass() = 0;
virtual void ReadbackFramebufferSync(
const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height,
void* data) = 0;

View file

@ -111,7 +111,11 @@ void CDeviceCommandContext::ClearFramebuffer(const bool, const bool, const bool)
{
}
void CDeviceCommandContext::SetFramebuffer(IFramebuffer*)
void CDeviceCommandContext::BeginFramebufferPass(IFramebuffer*)
{
}
void CDeviceCommandContext::EndFramebufferPass()
{
}

View file

@ -52,7 +52,8 @@ public:
void ClearFramebuffer() override;
void ClearFramebuffer(const bool color, const bool depth, const bool stencil) override;
void SetFramebuffer(IFramebuffer* framebuffer) override;
void BeginFramebufferPass(IFramebuffer* framebuffer) override;
void EndFramebufferPass() override;
void ReadbackFramebufferSync(
const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height,
void* data) override;

View file

@ -478,7 +478,9 @@ void CDeviceCommandContext::ResetStates()
{
SetGraphicsPipelineStateImpl(MakeDefaultGraphicsPipelineStateDesc(), true);
SetScissors(0, nullptr);
SetFramebuffer(m_Device->GetCurrentBackbuffer());
m_Framebuffer = static_cast<CFramebuffer*>(m_Device->GetCurrentBackbuffer());
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_Framebuffer->GetHandle());
ogl_WarnIfError();
}
void CDeviceCommandContext::SetGraphicsPipelineStateImpl(
@ -730,6 +732,7 @@ void CDeviceCommandContext::SetGraphicsPipelineStateImpl(
void CDeviceCommandContext::BlitFramebuffer(
IFramebuffer* dstFramebuffer, IFramebuffer* srcFramebuffer)
{
ENSURE(!m_InsideFramebufferPass);
CFramebuffer* destinationFramebuffer = dstFramebuffer->As<CFramebuffer>();
CFramebuffer* sourceFramebuffer = srcFramebuffer->As<CFramebuffer>();
#if CONFIG2_GLES
@ -794,8 +797,10 @@ void CDeviceCommandContext::ClearFramebuffer(const bool color, const bool depth,
ApplyStencilMask(m_GraphicsPipelineStateDesc.depthStencilState.stencilWriteMask);
}
void CDeviceCommandContext::SetFramebuffer(IFramebuffer* framebuffer)
void CDeviceCommandContext::BeginFramebufferPass(IFramebuffer* framebuffer)
{
ENSURE(!m_InsideFramebufferPass);
m_InsideFramebufferPass = true;
ENSURE(framebuffer);
m_Framebuffer = framebuffer->As<CFramebuffer>();
ENSURE(m_Framebuffer->GetHandle() == 0 || (m_Framebuffer->GetWidth() > 0 && m_Framebuffer->GetHeight() > 0));
@ -803,6 +808,15 @@ void CDeviceCommandContext::SetFramebuffer(IFramebuffer* framebuffer)
ogl_WarnIfError();
}
void CDeviceCommandContext::EndFramebufferPass()
{
ENSURE(m_InsideFramebufferPass);
m_InsideFramebufferPass = false;
m_Framebuffer = static_cast<CFramebuffer*>(m_Device->GetCurrentBackbuffer());
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_Framebuffer->GetHandle());
ogl_WarnIfError();
}
void CDeviceCommandContext::ReadbackFramebufferSync(
const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height,
void* data)

View file

@ -59,7 +59,8 @@ public:
void ClearFramebuffer() override;
void ClearFramebuffer(const bool color, const bool depth, const bool stencil) override;
void SetFramebuffer(IFramebuffer* framebuffer) override;
void BeginFramebufferPass(IFramebuffer* framebuffer) override;
void EndFramebufferPass() override;
void ReadbackFramebufferSync(
const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height,
void* data) override;
@ -175,6 +176,7 @@ private:
CBuffer* m_IndexBuffer = nullptr;
const void* m_IndexBufferData = nullptr;
bool m_InsideFramebufferPass = false;
bool m_InsidePass = false;
uint32_t m_ActiveTextureUnit = 0;