1
0
forked from 0ad/0ad

Removes SetViewport from CRenderer.

Differential Revision: https://code.wildfiregames.com/D4849
This was SVN commit r27313.
This commit is contained in:
Vladislav Belov 2022-12-29 06:53:06 +00:00
parent edca3d719e
commit c0e888e2af
23 changed files with 150 additions and 119 deletions

View File

@ -160,14 +160,10 @@ void CLOSTexture::InterpolateLOS(Renderer::Backend::IDeviceCommandContext* devic
(timer_Time() - m_LastTextureRecomputeTime) * 2.0f, 0.0f, 1.0f); (timer_Time() - m_LastTextureRecomputeTime) * 2.0f, 0.0f, 1.0f);
deviceCommandContext->SetUniform(shader->GetBindingSlot(str_delta), delta); deviceCommandContext->SetUniform(shader->GetBindingSlot(str_delta), delta);
const SViewPort oldVp = g_Renderer.GetViewport(); Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
const SViewPort vp = viewportRect.width = m_Texture->GetWidth();
{ viewportRect.height = m_Texture->GetHeight();
0, 0, deviceCommandContext->SetViewports(1, &viewportRect);
static_cast<int>(m_Texture->GetWidth()),
static_cast<int>(m_Texture->GetHeight())
};
g_Renderer.SetViewport(vp);
float quadVerts[] = float quadVerts[] =
{ {
@ -206,8 +202,6 @@ void CLOSTexture::InterpolateLOS(Renderer::Backend::IDeviceCommandContext* devic
deviceCommandContext->Draw(0, 6); deviceCommandContext->Draw(0, 6);
g_Renderer.SetViewport(oldVp);
deviceCommandContext->EndPass(); deviceCommandContext->EndPass();
deviceCommandContext->EndFramebufferPass(); deviceCommandContext->EndFramebufferPass();
} }

View File

@ -465,9 +465,10 @@ void CMiniMapTexture::RenderFinalTexture(
GPU_SCOPED_LABEL(deviceCommandContext, "Render minimap texture"); GPU_SCOPED_LABEL(deviceCommandContext, "Render minimap texture");
deviceCommandContext->BeginFramebufferPass(m_FinalTextureFramebuffer.get()); deviceCommandContext->BeginFramebufferPass(m_FinalTextureFramebuffer.get());
const SViewPort oldViewPort = g_Renderer.GetViewport(); Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
const SViewPort viewPort = { 0, 0, FINAL_TEXTURE_SIZE, FINAL_TEXTURE_SIZE }; viewportRect.width = FINAL_TEXTURE_SIZE;
g_Renderer.SetViewport(viewPort); viewportRect.height = FINAL_TEXTURE_SIZE;
deviceCommandContext->SetViewports(1, &viewportRect);
const float texCoordMax = m_TerrainTexture ? static_cast<float>(m_MapSize - 1) / m_TerrainTexture->GetWidth() : 1.0f; const float texCoordMax = m_TerrainTexture ? static_cast<float>(m_MapSize - 1) / m_TerrainTexture->GetWidth() : 1.0f;
@ -478,9 +479,8 @@ void CMiniMapTexture::RenderFinalTexture(
baseDefines.Add(str_MINIMAP_BASE, str_1); baseDefines.Add(str_MINIMAP_BASE, str_1);
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, baseDefines); tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, baseDefines);
Renderer::Backend::GraphicsPipelineStateDesc pipelineStateDesc = deviceCommandContext->SetGraphicsPipelineState(
tech->GetGraphicsPipelineStateDesc(); tech->GetGraphicsPipelineStateDesc());
deviceCommandContext->SetGraphicsPipelineState(pipelineStateDesc);
deviceCommandContext->BeginPass(); deviceCommandContext->BeginPass();
shader = tech->GetShader(); shader = tech->GetShader();
@ -513,6 +513,8 @@ void CMiniMapTexture::RenderFinalTexture(
DrawTexture(deviceCommandContext); DrawTexture(deviceCommandContext);
deviceCommandContext->EndPass(); deviceCommandContext->EndPass();
Renderer::Backend::GraphicsPipelineStateDesc pipelineStateDesc =
tech->GetGraphicsPipelineStateDesc();
pipelineStateDesc.blendState.enabled = true; pipelineStateDesc.blendState.enabled = true;
pipelineStateDesc.blendState.srcColorBlendFactor = pipelineStateDesc.blendState.srcAlphaBlendFactor = pipelineStateDesc.blendState.srcColorBlendFactor = pipelineStateDesc.blendState.srcAlphaBlendFactor =
Renderer::Backend::BlendFactor::SRC_ALPHA; Renderer::Backend::BlendFactor::SRC_ALPHA;
@ -571,7 +573,6 @@ void CMiniMapTexture::RenderFinalTexture(
DrawEntities(deviceCommandContext, entityRadius); DrawEntities(deviceCommandContext, entityRadius);
deviceCommandContext->EndFramebufferPass(); deviceCommandContext->EndFramebufferPass();
g_Renderer.SetViewport(oldViewPort);
} }
void CMiniMapTexture::UpdateAndUploadEntities( void CMiniMapTexture::UpdateAndUploadEntities(

View File

@ -673,11 +673,11 @@ void CVideoMode::UpdateRenderer(int w, int h)
SViewPort vp = { 0, 0, w, h }; SViewPort vp = { 0, 0, w, h };
if (g_VideoMode.GetBackendDevice())
g_VideoMode.GetBackendDevice()->OnWindowResize(w, h);
if (CRenderer::IsInitialised()) if (CRenderer::IsInitialised())
{
g_Renderer.SetViewport(vp);
g_Renderer.Resize(w, h); g_Renderer.Resize(w, h);
}
if (g_GUI) if (g_GUI)
g_GUI->UpdateResolution(); g_GUI->UpdateResolution();

View File

@ -219,6 +219,11 @@ void CPostprocManager::ApplyBlurDownscale2x(
{ {
deviceCommandContext->BeginFramebufferPass(framebuffer); deviceCommandContext->BeginFramebufferPass(framebuffer);
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = inWidth / 2;
viewportRect.height = inHeight / 2;
deviceCommandContext->SetViewports(1, &viewportRect);
// Get bloom shader with instructions to simply copy texels. // Get bloom shader with instructions to simply copy texels.
CShaderDefines defines; CShaderDefines defines;
defines.Add(str_BLOOM_NOP, str_1); defines.Add(str_BLOOM_NOP, str_1);
@ -232,10 +237,6 @@ void CPostprocManager::ApplyBlurDownscale2x(
deviceCommandContext->SetTexture( deviceCommandContext->SetTexture(
shader->GetBindingSlot(str_renderedTex), inTex); shader->GetBindingSlot(str_renderedTex), inTex);
const SViewPort oldVp = g_Renderer.GetViewport();
const SViewPort vp = { 0, 0, inWidth / 2, inHeight / 2 };
g_Renderer.SetViewport(vp);
// TODO: remove the fullscreen quad drawing duplication. // TODO: remove the fullscreen quad drawing duplication.
float quadVerts[] = float quadVerts[] =
{ {
@ -274,8 +275,6 @@ void CPostprocManager::ApplyBlurDownscale2x(
deviceCommandContext->Draw(0, 6); deviceCommandContext->Draw(0, 6);
g_Renderer.SetViewport(oldVp);
deviceCommandContext->EndPass(); deviceCommandContext->EndPass();
deviceCommandContext->EndFramebufferPass(); deviceCommandContext->EndFramebufferPass();
} }
@ -290,6 +289,11 @@ void CPostprocManager::ApplyBlurGauss(
{ {
deviceCommandContext->BeginFramebufferPass(tempFramebuffer); deviceCommandContext->BeginFramebufferPass(tempFramebuffer);
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = inWidth;
viewportRect.height = inHeight;
deviceCommandContext->SetViewports(1, &viewportRect);
// Get bloom shader, for a horizontal Gaussian blur pass. // Get bloom shader, for a horizontal Gaussian blur pass.
CShaderDefines defines2; CShaderDefines defines2;
defines2.Add(str_BLOOM_PASS_H, str_1); defines2.Add(str_BLOOM_PASS_H, str_1);
@ -304,10 +308,6 @@ void CPostprocManager::ApplyBlurGauss(
deviceCommandContext->SetUniform( deviceCommandContext->SetUniform(
shader->GetBindingSlot(str_texSize), inWidth, inHeight); shader->GetBindingSlot(str_texSize), inWidth, inHeight);
const SViewPort oldVp = g_Renderer.GetViewport();
const SViewPort vp = { 0, 0, inWidth, inHeight };
g_Renderer.SetViewport(vp);
float quadVerts[] = float quadVerts[] =
{ {
1.0f, 1.0f, 1.0f, 1.0f,
@ -345,13 +345,13 @@ void CPostprocManager::ApplyBlurGauss(
deviceCommandContext->Draw(0, 6); deviceCommandContext->Draw(0, 6);
g_Renderer.SetViewport(oldVp);
deviceCommandContext->EndPass(); deviceCommandContext->EndPass();
deviceCommandContext->EndFramebufferPass(); deviceCommandContext->EndFramebufferPass();
deviceCommandContext->BeginFramebufferPass(outFramebuffer); deviceCommandContext->BeginFramebufferPass(outFramebuffer);
deviceCommandContext->SetViewports(1, &viewportRect);
// Get bloom shader, for a vertical Gaussian blur pass. // Get bloom shader, for a vertical Gaussian blur pass.
CShaderDefines defines3; CShaderDefines defines3;
defines3.Add(str_BLOOM_PASS_V, str_1); defines3.Add(str_BLOOM_PASS_V, str_1);
@ -368,8 +368,6 @@ void CPostprocManager::ApplyBlurGauss(
deviceCommandContext->SetUniform( deviceCommandContext->SetUniform(
shader->GetBindingSlot(str_texSize), inWidth, inHeight); shader->GetBindingSlot(str_texSize), inWidth, inHeight);
g_Renderer.SetViewport(vp);
deviceCommandContext->SetVertexAttributeFormat( deviceCommandContext->SetVertexAttributeFormat(
Renderer::Backend::VertexAttributeStream::POSITION, Renderer::Backend::VertexAttributeStream::POSITION,
Renderer::Backend::Format::R32G32_SFLOAT, 0, sizeof(float) * 2, Renderer::Backend::Format::R32G32_SFLOAT, 0, sizeof(float) * 2,
@ -386,8 +384,6 @@ void CPostprocManager::ApplyBlurGauss(
deviceCommandContext->Draw(0, 6); deviceCommandContext->Draw(0, 6);
g_Renderer.SetViewport(oldVp);
deviceCommandContext->EndPass(); deviceCommandContext->EndPass();
deviceCommandContext->EndFramebufferPass(); deviceCommandContext->EndFramebufferPass();
} }
@ -410,22 +406,18 @@ void CPostprocManager::ApplyBlur(
} }
} }
Renderer::Backend::IFramebuffer* CPostprocManager::PrepareAndGetOutputFramebuffer()
void CPostprocManager::CaptureRenderOutput(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
{ {
ENSURE(m_IsInitialized); ENSURE(m_IsInitialized);
// Leaves m_PingFbo selected for rendering; m_WhichBuffer stays true at this point. // Leaves m_PingFbo selected for rendering; m_WhichBuffer stays true at this point.
deviceCommandContext->BeginFramebufferPass(
m_UsingMultisampleBuffer ? m_MultisampleFramebuffer.get() : m_CaptureFramebuffer.get());
m_WhichBuffer = true; m_WhichBuffer = true;
return m_UsingMultisampleBuffer ? m_MultisampleFramebuffer.get() : m_CaptureFramebuffer.get();
} }
void CPostprocManager::BlitOutputFramebuffer(
void CPostprocManager::ReleaseRenderOutput(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
Renderer::Backend::IFramebuffer* destination) Renderer::Backend::IFramebuffer* destination)
{ {
@ -443,8 +435,14 @@ void CPostprocManager::ApplyEffect(
const CShaderTechniquePtr& shaderTech, int pass) const CShaderTechniquePtr& shaderTech, int pass)
{ {
// select the other FBO for rendering // select the other FBO for rendering
deviceCommandContext->BeginFramebufferPass( Renderer::Backend::IFramebuffer* framebuffer =
(m_WhichBuffer ? m_PongFramebuffer : m_PingFramebuffer).get()); (m_WhichBuffer ? m_PongFramebuffer : m_PingFramebuffer).get();
deviceCommandContext->BeginFramebufferPass(framebuffer);
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = framebuffer->GetWidth();
viewportRect.height = framebuffer->GetHeight();
deviceCommandContext->SetViewports(1, &viewportRect);
deviceCommandContext->SetGraphicsPipelineState( deviceCommandContext->SetGraphicsPipelineState(
shaderTech->GetGraphicsPipelineStateDesc(pass)); shaderTech->GetGraphicsPipelineStateDesc(pass));

View File

@ -62,11 +62,8 @@ public:
void SetDepthBufferClipPlanes(float nearPlane, float farPlane); void SetDepthBufferClipPlanes(float nearPlane, float farPlane);
// Clears the two color buffers and depth buffer, and redirects all rendering
// to our textures instead of directly to the system framebuffer.
// @note CPostprocManager must be initialized first // @note CPostprocManager must be initialized first
void CaptureRenderOutput( Renderer::Backend::IFramebuffer* PrepareAndGetOutputFramebuffer();
Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
// First renders blur textures, then calls ApplyEffect for each effect pass, // First renders blur textures, then calls ApplyEffect for each effect pass,
// ping-ponging the buffers at each step. // ping-ponging the buffers at each step.
@ -78,7 +75,7 @@ public:
// framebuffer is selected as the output buffer. Should be called before // framebuffer is selected as the output buffer. Should be called before
// silhouette rendering. // silhouette rendering.
// @note CPostprocManager must be initialized first // @note CPostprocManager must be initialized first
void ReleaseRenderOutput( void BlitOutputFramebuffer(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
Renderer::Backend::IFramebuffer* destination); Renderer::Backend::IFramebuffer* destination);

View File

@ -302,14 +302,6 @@ CRenderer::CRenderer()
// the first Frame. // the first Frame.
GetSceneRenderer().SetLightEnv(&g_LightEnv); GetSceneRenderer().SetLightEnv(&g_LightEnv);
// I haven't seen the camera affecting GUI rendering and such, but the
// viewport has to be updated according to the video mode
SViewPort vp;
vp.m_X = 0;
vp.m_Y = 0;
vp.m_Width = g_xres;
vp.m_Height = g_yres;
SetViewport(vp);
ModelDefActivateFastImpl(); ModelDefActivateFastImpl();
ColorActivateFastImpl(); ColorActivateFastImpl();
ModelRenderer::Init(); ModelRenderer::Init();
@ -468,6 +460,8 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
m->deviceCommandContext->SetGraphicsPipelineState( m->deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc()); Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
Renderer::Backend::IFramebuffer* framebuffer = nullptr;
CPostprocManager& postprocManager = g_Renderer.GetPostprocManager(); CPostprocManager& postprocManager = g_Renderer.GetPostprocManager();
if (postprocManager.IsEnabled()) if (postprocManager.IsEnabled())
{ {
@ -478,20 +472,27 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
m->sceneRenderer.GetViewCamera().GetFarPlane() m->sceneRenderer.GetViewCamera().GetFarPlane()
); );
postprocManager.Initialize(); postprocManager.Initialize();
postprocManager.CaptureRenderOutput(m->deviceCommandContext.get()); framebuffer = postprocManager.PrepareAndGetOutputFramebuffer();
} }
else else
{ {
// We don't need to clear the color attachment of the framebuffer as the sky // We don't need to clear the color attachment of the framebuffer as the sky
// is going to be rendered anyway. // is going to be rendered anyway.
m->deviceCommandContext->BeginFramebufferPass( framebuffer =
m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer( m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer(
Renderer::Backend::AttachmentLoadOp::DONT_CARE, Renderer::Backend::AttachmentLoadOp::DONT_CARE,
Renderer::Backend::AttachmentStoreOp::STORE, Renderer::Backend::AttachmentStoreOp::STORE,
Renderer::Backend::AttachmentLoadOp::CLEAR, Renderer::Backend::AttachmentLoadOp::CLEAR,
Renderer::Backend::AttachmentStoreOp::DONT_CARE)); Renderer::Backend::AttachmentStoreOp::DONT_CARE);
} }
m->deviceCommandContext->BeginFramebufferPass(framebuffer);
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = framebuffer->GetWidth();
viewportRect.height = framebuffer->GetHeight();
m->deviceCommandContext->SetViewports(1, &viewportRect);
g_Game->GetView()->Render(m->deviceCommandContext.get()); g_Game->GetView()->Render(m->deviceCommandContext.get());
if (postprocManager.IsEnabled()) if (postprocManager.IsEnabled())
@ -509,10 +510,15 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
Renderer::Backend::AttachmentStoreOp::STORE, Renderer::Backend::AttachmentStoreOp::STORE,
Renderer::Backend::AttachmentLoadOp::LOAD, Renderer::Backend::AttachmentLoadOp::LOAD,
Renderer::Backend::AttachmentStoreOp::DONT_CARE); Renderer::Backend::AttachmentStoreOp::DONT_CARE);
postprocManager.ReleaseRenderOutput( postprocManager.BlitOutputFramebuffer(
m->deviceCommandContext.get(), backbuffer); m->deviceCommandContext.get(), backbuffer);
m->deviceCommandContext->BeginFramebufferPass(backbuffer); m->deviceCommandContext->BeginFramebufferPass(backbuffer);
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = backbuffer->GetWidth();
viewportRect.height = backbuffer->GetHeight();
m->deviceCommandContext->SetViewports(1, &viewportRect);
} }
g_Game->GetView()->RenderOverlays(m->deviceCommandContext.get()); g_Game->GetView()->RenderOverlays(m->deviceCommandContext.get());
@ -530,12 +536,18 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger)
g_AtlasGameLoop && g_AtlasGameLoop->view g_AtlasGameLoop && g_AtlasGameLoop->view
? Renderer::Backend::AttachmentLoadOp::CLEAR ? Renderer::Backend::AttachmentLoadOp::CLEAR
: Renderer::Backend::AttachmentLoadOp::DONT_CARE; : Renderer::Backend::AttachmentLoadOp::DONT_CARE;
m->deviceCommandContext->BeginFramebufferPass( Renderer::Backend::IFramebuffer* backbuffer =
m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer( m->deviceCommandContext->GetDevice()->GetCurrentBackbuffer(
Renderer::Backend::AttachmentLoadOp::DONT_CARE, Renderer::Backend::AttachmentLoadOp::DONT_CARE,
Renderer::Backend::AttachmentStoreOp::STORE, Renderer::Backend::AttachmentStoreOp::STORE,
depthStencilLoadOp, depthStencilLoadOp,
Renderer::Backend::AttachmentStoreOp::DONT_CARE)); Renderer::Backend::AttachmentStoreOp::DONT_CARE);
m->deviceCommandContext->BeginFramebufferPass(backbuffer);
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = backbuffer->GetWidth();
viewportRect.height = backbuffer->GetHeight();
m->deviceCommandContext->SetViewports(1, &viewportRect);
} }
// If we're in Atlas game view, render special tools // If we're in Atlas game view, render special tools
@ -789,22 +801,6 @@ void CRenderer::EndFrame()
m->sceneRenderer.EndFrame(); m->sceneRenderer.EndFrame();
} }
void CRenderer::SetViewport(const SViewPort &vp)
{
m_Viewport = vp;
Renderer::Backend::IDeviceCommandContext::Rect viewportRect;
viewportRect.x = vp.m_X;
viewportRect.y = vp.m_Y;
viewportRect.width = vp.m_Width;
viewportRect.height = vp.m_Height;
m->deviceCommandContext->SetViewports(1, &viewportRect);
}
SViewPort CRenderer::GetViewport()
{
return m_Viewport;
}
void CRenderer::MakeShadersDirty() void CRenderer::MakeShadersDirty()
{ {
m->ShadersDirty = true; m->ShadersDirty = true;

View File

@ -99,12 +99,6 @@ public:
// trigger a reload of shaders (when parameters they depend on have changed) // trigger a reload of shaders (when parameters they depend on have changed)
void MakeShadersDirty(); void MakeShadersDirty();
// set the viewport
void SetViewport(const SViewPort &);
// get the last viewport
SViewPort GetViewport();
// return stats accumulated for current frame // return stats accumulated for current frame
Stats& GetStats() { return m_Stats; } Stats& GetStats() { return m_Stats; }
@ -168,8 +162,6 @@ protected:
// view height // view height
int m_Height = 0; int m_Height = 0;
SViewPort m_Viewport;
// per-frame renderer stats // per-frame renderer stats
Stats m_Stats; Stats m_Stats;

View File

@ -332,8 +332,6 @@ void CSceneRenderer::RenderShadowMap(
} }
m->shadow.EndRender(deviceCommandContext); m->shadow.EndRender(deviceCommandContext);
g_Renderer.SetViewport(m_ViewCamera.GetViewPort());
} }
void CSceneRenderer::RenderPatches( void CSceneRenderer::RenderPatches(
@ -565,8 +563,6 @@ void CSceneRenderer::RenderReflections(
return; return;
} }
g_Renderer.SetViewport(m_ViewCamera.GetViewPort());
// Save the model-view-projection matrix so the shaders can use it for projective texturing // Save the model-view-projection matrix so the shaders can use it for projective texturing
wm.m_ReflectionMatrix = m_ViewCamera.GetViewProjection(); wm.m_ReflectionMatrix = m_ViewCamera.GetViewProjection();
@ -579,6 +575,15 @@ void CSceneRenderer::RenderReflections(
screenScissor.x2 = static_cast<int>(ceil((reflectionScissor[1].X * 0.5f + 0.5f) * vpWidth)); screenScissor.x2 = static_cast<int>(ceil((reflectionScissor[1].X * 0.5f + 0.5f) * vpWidth));
screenScissor.y2 = static_cast<int>(ceil((reflectionScissor[1].Y * 0.5f + 0.5f) * vpHeight)); screenScissor.y2 = static_cast<int>(ceil((reflectionScissor[1].Y * 0.5f + 0.5f) * vpHeight));
deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
deviceCommandContext->BeginFramebufferPass(wm.m_ReflectionFramebuffer.get());
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = vpWidth;
viewportRect.height = vpHeight;
deviceCommandContext->SetViewports(1, &viewportRect);
Renderer::Backend::IDeviceCommandContext::Rect scissorRect; Renderer::Backend::IDeviceCommandContext::Rect scissorRect;
scissorRect.x = screenScissor.x1; scissorRect.x = screenScissor.x1;
scissorRect.y = screenScissor.y1; scissorRect.y = screenScissor.y1;
@ -586,10 +591,6 @@ void CSceneRenderer::RenderReflections(
scissorRect.height = screenScissor.y2 - screenScissor.y1; scissorRect.height = screenScissor.y2 - screenScissor.y1;
deviceCommandContext->SetScissors(1, &scissorRect); deviceCommandContext->SetScissors(1, &scissorRect);
deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
deviceCommandContext->BeginFramebufferPass(wm.m_ReflectionFramebuffer.get());
CShaderDefines reflectionsContext = context; CShaderDefines reflectionsContext = context;
reflectionsContext.Add(str_PASS_REFLECTIONS, str_1); reflectionsContext.Add(str_PASS_REFLECTIONS, str_1);
@ -610,7 +611,6 @@ void CSceneRenderer::RenderReflections(
// Reset old camera // Reset old camera
m_ViewCamera = normalCamera; m_ViewCamera = normalCamera;
g_Renderer.SetViewport(m_ViewCamera.GetViewPort());
} }
// RenderRefractions: render the water refractions to the refraction texture // RenderRefractions: render the water refractions to the refraction texture
@ -638,8 +638,6 @@ void CSceneRenderer::RenderRefractions(
CVector4D camPlane(0, -1, 0, wm.m_WaterHeight + 2.0f); CVector4D camPlane(0, -1, 0, wm.m_WaterHeight + 2.0f);
SetObliqueFrustumClipping(m_ViewCamera, camPlane); SetObliqueFrustumClipping(m_ViewCamera, camPlane);
g_Renderer.SetViewport(m_ViewCamera.GetViewPort());
// Save the model-view-projection matrix so the shaders can use it for projective texturing // Save the model-view-projection matrix so the shaders can use it for projective texturing
wm.m_RefractionMatrix = m_ViewCamera.GetViewProjection(); wm.m_RefractionMatrix = m_ViewCamera.GetViewProjection();
wm.m_RefractionProjInvMatrix = m_ViewCamera.GetProjection().GetInverse(); wm.m_RefractionProjInvMatrix = m_ViewCamera.GetProjection().GetInverse();
@ -654,6 +652,15 @@ void CSceneRenderer::RenderRefractions(
screenScissor.x2 = static_cast<int>(ceil((refractionScissor[1].X * 0.5f + 0.5f) * vpWidth)); screenScissor.x2 = static_cast<int>(ceil((refractionScissor[1].X * 0.5f + 0.5f) * vpWidth));
screenScissor.y2 = static_cast<int>(ceil((refractionScissor[1].Y * 0.5f + 0.5f) * vpHeight)); screenScissor.y2 = static_cast<int>(ceil((refractionScissor[1].Y * 0.5f + 0.5f) * vpHeight));
deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
deviceCommandContext->BeginFramebufferPass(wm.m_RefractionFramebuffer.get());
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = vpWidth;
viewportRect.height = vpHeight;
deviceCommandContext->SetViewports(1, &viewportRect);
Renderer::Backend::IDeviceCommandContext::Rect scissorRect; Renderer::Backend::IDeviceCommandContext::Rect scissorRect;
scissorRect.x = screenScissor.x1; scissorRect.x = screenScissor.x1;
scissorRect.y = screenScissor.y1; scissorRect.y = screenScissor.y1;
@ -661,10 +668,6 @@ void CSceneRenderer::RenderRefractions(
scissorRect.height = screenScissor.y2 - screenScissor.y1; scissorRect.height = screenScissor.y2 - screenScissor.y1;
deviceCommandContext->SetScissors(1, &scissorRect); deviceCommandContext->SetScissors(1, &scissorRect);
deviceCommandContext->SetGraphicsPipelineState(
Renderer::Backend::MakeDefaultGraphicsPipelineStateDesc());
deviceCommandContext->BeginFramebufferPass(wm.m_RefractionFramebuffer.get());
// Render terrain and models // Render terrain and models
RenderPatches(deviceCommandContext, context, CULL_REFRACTIONS); RenderPatches(deviceCommandContext, context, CULL_REFRACTIONS);
@ -679,7 +682,6 @@ void CSceneRenderer::RenderRefractions(
// Reset old camera // Reset old camera
m_ViewCamera = normalCamera; m_ViewCamera = normalCamera;
g_Renderer.SetViewport(m_ViewCamera.GetViewPort());
} }
void CSceneRenderer::RenderSilhouettes( void CSceneRenderer::RenderSilhouettes(
@ -770,9 +772,6 @@ void CSceneRenderer::PrepareSubmissions(
CShaderDefines context = m->globalContext; CShaderDefines context = m->globalContext;
// Set the camera
g_Renderer.SetViewport(m_ViewCamera.GetViewPort());
// Prepare model renderers // Prepare model renderers
{ {
PROFILE3("prepare models"); PROFILE3("prepare models");

View File

@ -600,8 +600,10 @@ void ShadowMap::PrepareCamera(
{ {
m->CalculateShadowMatrices(cascade); m->CalculateShadowMatrices(cascade);
const SViewPort vp = { 0, 0, m->EffectiveWidth, m->EffectiveHeight }; Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
g_Renderer.SetViewport(vp); viewportRect.width = m->EffectiveWidth;
viewportRect.height = m->EffectiveHeight;
deviceCommandContext->SetViewports(1, &viewportRect);
CCamera camera = m->SavedViewCamera; CCamera camera = m->SavedViewCamera;
camera.SetProjection(m->Cascades[cascade].LightProjection); camera.SetProjection(m->Cascades[cascade].LightProjection);
@ -625,9 +627,6 @@ void ShadowMap::EndRender(
deviceCommandContext->EndFramebufferPass(); deviceCommandContext->EndFramebufferPass();
g_Renderer.GetSceneRenderer().SetViewCamera(m->SavedViewCamera); g_Renderer.GetSceneRenderer().SetViewCamera(m->SavedViewCamera);
const SViewPort vp = { 0, 0, g_Renderer.GetWidth(), g_Renderer.GetHeight() };
g_Renderer.SetViewport(vp);
} }
void ShadowMap::BindTo( void ShadowMap::BindTo(

View File

@ -136,6 +136,13 @@ public:
*/ */
virtual void Present() = 0; virtual void Present() = 0;
/**
* Should be called on window surface resize. It's the device owner
* responsibility to call that function. Shouldn't be called during
* rendering to an acquired backbuffer.
*/
virtual void OnWindowResize(const uint32_t width, const uint32_t height) = 0;
virtual bool IsTextureFormatSupported(const Format format) const = 0; virtual bool IsTextureFormatSupported(const Format format) const = 0;
virtual bool IsFramebufferFormatSupported(const Format format) const = 0; virtual bool IsFramebufferFormatSupported(const Format format) const = 0;

View File

@ -89,6 +89,9 @@ public:
* @see IDevice::CreateFramebuffer() * @see IDevice::CreateFramebuffer()
*/ */
virtual const CColor& GetClearColor() const = 0; virtual const CColor& GetClearColor() const = 0;
virtual uint32_t GetWidth() const = 0;
virtual uint32_t GetHeight() const = 0;
}; };
} // namespace Backend } // namespace Backend

View File

@ -126,6 +126,10 @@ void CDevice::Present()
// We have nothing to present. // We have nothing to present.
} }
void CDevice::OnWindowResize(const uint32_t UNUSED(width), const uint32_t UNUSED(height))
{
}
bool CDevice::IsTextureFormatSupported(const Format UNUSED(format)) const bool CDevice::IsTextureFormatSupported(const Format UNUSED(format)) const
{ {
return true; return true;

View File

@ -79,6 +79,8 @@ public:
void Present() override; void Present() override;
void OnWindowResize(const uint32_t width, const uint32_t height) override;
bool IsTextureFormatSupported(const Format format) const override; bool IsTextureFormatSupported(const Format format) const override;
bool IsFramebufferFormatSupported(const Format format) const override; bool IsFramebufferFormatSupported(const Format format) const override;

View File

@ -42,6 +42,9 @@ public:
const CColor& GetClearColor() const override { return m_ClearColor; } const CColor& GetClearColor() const override { return m_ClearColor; }
uint32_t GetWidth() const override { return 1; }
uint32_t GetHeight() const override { return 1; }
private: private:
friend class CDevice; friend class CDevice;

View File

@ -241,6 +241,8 @@ std::unique_ptr<IDevice> CDevice::Create(SDL_Window* window, const bool arb)
LOGERROR("SDL_GL_CreateContext failed: '%s'", SDL_GetError()); LOGERROR("SDL_GL_CreateContext failed: '%s'", SDL_GetError());
return nullptr; return nullptr;
} }
SDL_GL_GetDrawableSize(window, &device->m_SurfaceDrawableWidth, &device->m_SurfaceDrawableHeight);
#if OS_WIN #if OS_WIN
ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC()); ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC());
#elif (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) && !CONFIG2_GLES #elif (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) && !CONFIG2_GLES
@ -934,7 +936,8 @@ IFramebuffer* CDevice::GetCurrentBackbuffer(
if (it == m_Backbuffers.end()) if (it == m_Backbuffers.end())
{ {
it = m_Backbuffers.emplace(key, CFramebuffer::CreateBackbuffer( it = m_Backbuffers.emplace(key, CFramebuffer::CreateBackbuffer(
this, colorAttachmentLoadOp, colorAttachmentStoreOp, this, m_SurfaceDrawableWidth, m_SurfaceDrawableHeight,
colorAttachmentLoadOp, colorAttachmentStoreOp,
depthStencilAttachmentLoadOp, depthStencilAttachmentStoreOp)).first; depthStencilAttachmentLoadOp, depthStencilAttachmentStoreOp)).first;
} }
return it->second.get(); return it->second.get();
@ -965,6 +968,14 @@ void CDevice::Present()
ONCE(LOGERROR("GL error %s (0x%04x) occurred", ogl_GetErrorName(err), err)); ONCE(LOGERROR("GL error %s (0x%04x) occurred", ogl_GetErrorName(err), err));
} }
void CDevice::OnWindowResize(const uint32_t width, const uint32_t height)
{
ENSURE(!m_BackbufferAcquired);
m_Backbuffers.clear();
m_SurfaceDrawableWidth = width;
m_SurfaceDrawableHeight = height;
}
bool CDevice::IsTextureFormatSupported(const Format format) const bool CDevice::IsTextureFormatSupported(const Format format) const
{ {
bool supported = false; bool supported = false;

View File

@ -100,6 +100,8 @@ public:
void Present() override; void Present() override;
void OnWindowResize(const uint32_t width, const uint32_t height) override;
bool UseFramebufferInvalidating() const { return m_UseFramebufferInvalidating; } bool UseFramebufferInvalidating() const { return m_UseFramebufferInvalidating; }
bool IsTextureFormatSupported(const Format format) const override; bool IsTextureFormatSupported(const Format format) const override;
@ -113,6 +115,7 @@ private:
SDL_Window* m_Window = nullptr; SDL_Window* m_Window = nullptr;
SDL_GLContext m_Context = nullptr; SDL_GLContext m_Context = nullptr;
int m_SurfaceDrawableWidth = 0, m_SurfaceDrawableHeight = 0;
bool m_ARB = false; bool m_ARB = false;

View File

@ -950,6 +950,7 @@ void CDeviceCommandContext::SetScissors(const uint32_t scissorCount, const Rect*
void CDeviceCommandContext::SetViewports(const uint32_t viewportCount, const Rect* viewports) void CDeviceCommandContext::SetViewports(const uint32_t viewportCount, const Rect* viewports)
{ {
ENSURE(m_InsideFramebufferPass);
ENSURE(viewportCount == 1); ENSURE(viewportCount == 1);
glViewport(viewports[0].x, viewports[0].y, viewports[0].width, viewports[0].height); glViewport(viewports[0].x, viewports[0].y, viewports[0].width, viewports[0].height);
ogl_WarnIfError(); ogl_WarnIfError();

View File

@ -164,6 +164,7 @@ std::unique_ptr<CFramebuffer> CFramebuffer::Create(
// static // static
std::unique_ptr<CFramebuffer> CFramebuffer::CreateBackbuffer( std::unique_ptr<CFramebuffer> CFramebuffer::CreateBackbuffer(
CDevice* device, CDevice* device,
const int surfaceDrawableWidth, const int surfaceDrawableHeight,
const AttachmentLoadOp colorAttachmentLoadOp, const AttachmentLoadOp colorAttachmentLoadOp,
const AttachmentStoreOp colorAttachmentStoreOp, const AttachmentStoreOp colorAttachmentStoreOp,
const AttachmentLoadOp depthStencilAttachmentLoadOp, const AttachmentLoadOp depthStencilAttachmentLoadOp,
@ -178,6 +179,8 @@ std::unique_ptr<CFramebuffer> CFramebuffer::CreateBackbuffer(
framebuffer->m_ColorAttachmentStoreOp = colorAttachmentStoreOp; framebuffer->m_ColorAttachmentStoreOp = colorAttachmentStoreOp;
framebuffer->m_DepthStencilAttachmentLoadOp = depthStencilAttachmentLoadOp; framebuffer->m_DepthStencilAttachmentLoadOp = depthStencilAttachmentLoadOp;
framebuffer->m_DepthStencilAttachmentStoreOp = depthStencilAttachmentStoreOp; framebuffer->m_DepthStencilAttachmentStoreOp = depthStencilAttachmentStoreOp;
framebuffer->m_Width = surfaceDrawableWidth;
framebuffer->m_Height = surfaceDrawableHeight;
return framebuffer; return framebuffer;
} }

View File

@ -46,6 +46,9 @@ public:
const CColor& GetClearColor() const override { return m_ClearColor; } const CColor& GetClearColor() const override { return m_ClearColor; }
uint32_t GetWidth() const override { return m_Width; }
uint32_t GetHeight() const override { return m_Height; }
GLuint GetHandle() const { return m_Handle; } GLuint GetHandle() const { return m_Handle; }
GLbitfield GetAttachmentMask() const { return m_AttachmentMask; } GLbitfield GetAttachmentMask() const { return m_AttachmentMask; }
@ -54,9 +57,6 @@ public:
AttachmentLoadOp GetDepthStencilAttachmentLoadOp() const { return m_DepthStencilAttachmentLoadOp; } AttachmentLoadOp GetDepthStencilAttachmentLoadOp() const { return m_DepthStencilAttachmentLoadOp; }
AttachmentStoreOp GetDepthStencilAttachmentStoreOp() const { return m_DepthStencilAttachmentStoreOp; } AttachmentStoreOp GetDepthStencilAttachmentStoreOp() const { return m_DepthStencilAttachmentStoreOp; }
uint32_t GetWidth() const { return m_Width; }
uint32_t GetHeight() const { return m_Height; }
private: private:
friend class CDevice; friend class CDevice;
@ -65,6 +65,7 @@ private:
SDepthStencilAttachment* depthStencilAttachment); SDepthStencilAttachment* depthStencilAttachment);
static std::unique_ptr<CFramebuffer> CreateBackbuffer( static std::unique_ptr<CFramebuffer> CreateBackbuffer(
CDevice* device, CDevice* device,
const int surfaceDrawableWidth, const int surfaceDrawableHeight,
const AttachmentLoadOp colorAttachmentLoadOp, const AttachmentLoadOp colorAttachmentLoadOp,
const AttachmentStoreOp colorAttachmentStoreOp, const AttachmentStoreOp colorAttachmentStoreOp,
const AttachmentLoadOp depthStencilAttachmentLoadOp, const AttachmentLoadOp depthStencilAttachmentLoadOp,

View File

@ -156,6 +156,12 @@ void CDevice::Present()
{ {
} }
void CDevice::OnWindowResize(const uint32_t width, const uint32_t height)
{
UNUSED2(width);
UNUSED2(height);
}
bool CDevice::IsTextureFormatSupported(const Format format) const bool CDevice::IsTextureFormatSupported(const Format format) const
{ {
UNUSED2(format); UNUSED2(format);

View File

@ -86,6 +86,8 @@ public:
void Present() override; void Present() override;
void OnWindowResize(const uint32_t width, const uint32_t height) override;
bool IsTextureFormatSupported(const Format format) const override; bool IsTextureFormatSupported(const Format format) const override;
bool IsFramebufferFormatSupported(const Format format) const override; bool IsFramebufferFormatSupported(const Format format) const override;

View File

@ -539,12 +539,18 @@ void ActorViewer::Render()
sceneRenderer.PrepareScene(deviceCommandContext, m); sceneRenderer.PrepareScene(deviceCommandContext, m);
deviceCommandContext->BeginFramebufferPass( Renderer::Backend::IFramebuffer* backbuffer =
deviceCommandContext->GetDevice()->GetCurrentBackbuffer( deviceCommandContext->GetDevice()->GetCurrentBackbuffer(
Renderer::Backend::AttachmentLoadOp::DONT_CARE, Renderer::Backend::AttachmentLoadOp::DONT_CARE,
Renderer::Backend::AttachmentStoreOp::STORE, Renderer::Backend::AttachmentStoreOp::STORE,
Renderer::Backend::AttachmentLoadOp::CLEAR, Renderer::Backend::AttachmentLoadOp::CLEAR,
Renderer::Backend::AttachmentStoreOp::DONT_CARE)); Renderer::Backend::AttachmentStoreOp::DONT_CARE);
deviceCommandContext->BeginFramebufferPass(backbuffer);
Renderer::Backend::IDeviceCommandContext::Rect viewportRect{};
viewportRect.width = backbuffer->GetWidth();
viewportRect.height = backbuffer->GetHeight();
deviceCommandContext->SetViewports(1, &viewportRect);
sceneRenderer.RenderScene(deviceCommandContext); sceneRenderer.RenderScene(deviceCommandContext);
sceneRenderer.RenderSceneOverlays(deviceCommandContext); sceneRenderer.RenderSceneOverlays(deviceCommandContext);

View File

@ -39,6 +39,7 @@
#include "ps/VideoMode.h" #include "ps/VideoMode.h"
#include "ps/GameSetup/Config.h" #include "ps/GameSetup/Config.h"
#include "ps/GameSetup/GameSetup.h" #include "ps/GameSetup/GameSetup.h"
#include "renderer/backend/IDevice.h"
#include "renderer/Renderer.h" #include "renderer/Renderer.h"
#include "renderer/SceneRenderer.h" #include "renderer/SceneRenderer.h"
@ -118,6 +119,8 @@ MESSAGEHANDLER(InitGraphics)
g_VideoMode.CreateBackendDevice(false); g_VideoMode.CreateBackendDevice(false);
g_VideoMode.GetBackendDevice()->OnWindowResize(g_xres, g_yres);
InitGraphics(g_AtlasGameLoop->args, g_InitFlags, {}); InitGraphics(g_AtlasGameLoop->args, g_InitFlags, {});
} }