From da4ec670c155f1c021e0f1411b88bd8b893db182 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Sat, 26 Feb 2022 23:17:48 +0000 Subject: [PATCH] Moves glViewport from CRenderer to CDeviceCommandContext. This was SVN commit r26497. --- source/graphics/MiniMapTexture.cpp | 2 +- source/gui/CGUIText.cpp | 2 +- source/gui/ObjectTypes/CInput.cpp | 2 +- source/renderer/Renderer.cpp | 7 ++++++- source/renderer/SceneRenderer.cpp | 4 ++-- source/renderer/ShadowMap.cpp | 2 +- .../renderer/backend/gl/DeviceCommandContext.cpp | 16 +++++++++++----- .../renderer/backend/gl/DeviceCommandContext.h | 7 ++++--- 8 files changed, 27 insertions(+), 15 deletions(-) diff --git a/source/graphics/MiniMapTexture.cpp b/source/graphics/MiniMapTexture.cpp index 9c3ee6d70d..5142e89cea 100644 --- a/source/graphics/MiniMapTexture.cpp +++ b/source/graphics/MiniMapTexture.cpp @@ -523,7 +523,7 @@ void CMiniMapTexture::RenderFinalTexture( if (m_EntitiesDrawn > 0) { - Renderer::Backend::GL::CDeviceCommandContext::ScissorRect scissorRect; + Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; scissorRect.x = scissorRect.y = 1; scissorRect.width = scissorRect.height = FINAL_TEXTURE_SIZE - 2; deviceCommandContext->SetScissors(1, &scissorRect); diff --git a/source/gui/CGUIText.cpp b/source/gui/CGUIText.cpp index 7915f01c7b..66cdb04842 100644 --- a/source/gui/CGUIText.cpp +++ b/source/gui/CGUIText.cpp @@ -444,7 +444,7 @@ void CGUIText::Draw(CGUI& pGUI, CCanvas2D& canvas, const CGUIColor& DefaultColor clipping.right = std::floor(clipping.right); const float scale = g_VideoMode.GetScale(); - Renderer::Backend::GL::CDeviceCommandContext::ScissorRect scissorRect; + Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; scissorRect.x = std::ceil(clipping.left * scale); scissorRect.y = std::ceil(g_yres - clipping.bottom * scale); scissorRect.width = std::floor(clipping.GetWidth() * scale); diff --git a/source/gui/ObjectTypes/CInput.cpp b/source/gui/ObjectTypes/CInput.cpp index 376c4e6cf5..cb8b548449 100644 --- a/source/gui/ObjectTypes/CInput.cpp +++ b/source/gui/ObjectTypes/CInput.cpp @@ -1244,7 +1244,7 @@ void CInput::Draw(CCanvas2D& canvas) if (cliparea != CRect()) { const float scale = g_VideoMode.GetScale(); - Renderer::Backend::GL::CDeviceCommandContext::ScissorRect scissorRect; + Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; scissorRect.x = cliparea.left * scale; scissorRect.y = g_yres - cliparea.bottom * scale; scissorRect.width = cliparea.GetWidth() * scale; diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index 2db9522a4e..48e01626f5 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -735,7 +735,12 @@ void CRenderer::EndFrame() void CRenderer::SetViewport(const SViewPort &vp) { m_Viewport = vp; - glViewport((GLint)vp.m_X,(GLint)vp.m_Y,(GLsizei)vp.m_Width,(GLsizei)vp.m_Height); + Renderer::Backend::GL::CDeviceCommandContext::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() diff --git a/source/renderer/SceneRenderer.cpp b/source/renderer/SceneRenderer.cpp index 39c7f2be31..3784775d8a 100644 --- a/source/renderer/SceneRenderer.cpp +++ b/source/renderer/SceneRenderer.cpp @@ -570,7 +570,7 @@ void CSceneRenderer::RenderReflections( screenScissor.x2 = (GLint)ceil((reflectionScissor[1].X*0.5f+0.5f)*vpWidth); screenScissor.y2 = (GLint)ceil((reflectionScissor[1].Y*0.5f+0.5f)*vpHeight); - Renderer::Backend::GL::CDeviceCommandContext::ScissorRect scissorRect; + Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; scissorRect.x = screenScissor.x1; scissorRect.y = screenScissor.y1; scissorRect.width = screenScissor.x2 - screenScissor.x1; @@ -652,7 +652,7 @@ void CSceneRenderer::RenderRefractions( screenScissor.x2 = (GLint)ceil((refractionScissor[1].X*0.5f+0.5f)*vpWidth); screenScissor.y2 = (GLint)ceil((refractionScissor[1].Y*0.5f+0.5f)*vpHeight); - Renderer::Backend::GL::CDeviceCommandContext::ScissorRect scissorRect; + Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; scissorRect.x = screenScissor.x1; scissorRect.y = screenScissor.y1; scissorRect.width = screenScissor.x2 - screenScissor.x1; diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index 7b05ec3cf9..fe25cf5281 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -603,7 +603,7 @@ void ShadowMap::PrepareCamera(const int cascade) g_Renderer.GetSceneRenderer().SetViewCamera(camera); const SViewPort& cascadeViewPort = m->Cascades[cascade].ViewPort; - Renderer::Backend::GL::CDeviceCommandContext::ScissorRect scissorRect; + Renderer::Backend::GL::CDeviceCommandContext::Rect scissorRect; scissorRect.x = cascadeViewPort.m_X; scissorRect.y = cascadeViewPort.m_Y; scissorRect.width = cascadeViewPort.m_Width; diff --git a/source/renderer/backend/gl/DeviceCommandContext.cpp b/source/renderer/backend/gl/DeviceCommandContext.cpp index a5f4291f33..4b97536b2b 100644 --- a/source/renderer/backend/gl/DeviceCommandContext.cpp +++ b/source/renderer/backend/gl/DeviceCommandContext.cpp @@ -56,8 +56,8 @@ bool operator!=(const StencilOpState& lhs, const StencilOpState& rhs) } bool operator==( - const CDeviceCommandContext::ScissorRect& lhs, - const CDeviceCommandContext::ScissorRect& rhs) + const CDeviceCommandContext::Rect& lhs, + const CDeviceCommandContext::Rect& rhs) { return lhs.x == rhs.x && lhs.y == rhs.y && @@ -65,8 +65,8 @@ bool operator==( } bool operator!=( - const CDeviceCommandContext::ScissorRect& lhs, - const CDeviceCommandContext::ScissorRect& rhs) + const CDeviceCommandContext::Rect& lhs, + const CDeviceCommandContext::Rect& rhs) { return !operator==(lhs, rhs); } @@ -683,7 +683,7 @@ void CDeviceCommandContext::SetFramebuffer(CFramebuffer* framebuffer) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer->GetHandle()); } -void CDeviceCommandContext::SetScissors(const uint32_t scissorCount, const ScissorRect* scissors) +void CDeviceCommandContext::SetScissors(const uint32_t scissorCount, const Rect* scissors) { ENSURE(scissorCount <= 1); if (scissorCount == 0) @@ -705,6 +705,12 @@ void CDeviceCommandContext::SetScissors(const uint32_t scissorCount, const Sciss m_ScissorCount = scissorCount; } +void CDeviceCommandContext::SetViewports(const uint32_t viewportCount, const Rect* viewports) +{ + ENSURE(viewportCount == 1); + glViewport(viewports[0].x, viewports[0].y, viewports[0].width, viewports[0].height); +} + CDeviceCommandContext::ScopedBind::ScopedBind( CDeviceCommandContext* deviceCommandContext, const GLenum target, const GLuint handle) diff --git a/source/renderer/backend/gl/DeviceCommandContext.h b/source/renderer/backend/gl/DeviceCommandContext.h index de0c37f987..6ae9b6898d 100644 --- a/source/renderer/backend/gl/DeviceCommandContext.h +++ b/source/renderer/backend/gl/DeviceCommandContext.h @@ -77,12 +77,13 @@ public: const UploadBufferFunction& uploadFunction); // TODO: maybe we should add a more common type, like CRectI. - struct ScissorRect + struct Rect { int32_t x, y; int32_t width, height; }; - void SetScissors(const uint32_t scissorCount, const ScissorRect* scissors); + void SetScissors(const uint32_t scissorCount, const Rect* scissors); + void SetViewports(const uint32_t viewportCount, const Rect* viewports); void BeginScopedLabel(const char* name); void EndScopedLabel(); @@ -111,7 +112,7 @@ private: CFramebuffer* m_Framebuffer = nullptr; uint32_t m_ScissorCount = 0; // GL2.1 doesn't support more than 1 scissor. - std::array m_Scissors; + std::array m_Scissors; uint32_t m_ScopedLabelDepth = 0;