From 44ee9915e34910aac67ab60f1296eed8be8e7cea Mon Sep 17 00:00:00 2001 From: vaxerski Date: Sun, 7 Jan 2024 18:35:44 +0100 Subject: [PATCH] renderer: overhaul renderModifData --- src/helpers/Box.hpp | 2 ++ src/render/OpenGL.cpp | 38 ++++++++++++++++++++++++++++++-------- src/render/OpenGL.hpp | 13 +++++++++++-- src/render/Renderer.cpp | 16 ++++++++++------ 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp index 5cb7f17f..a1ed83be 100644 --- a/src/helpers/Box.hpp +++ b/src/helpers/Box.hpp @@ -73,6 +73,8 @@ class CBox { double height; }; + double rot = 0; /* rad, ccw */ + // bool operator==(const CBox& rhs) const { return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h; diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index cb468932..c6d16dd8 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -637,7 +637,7 @@ void CHyprOpenGLImpl::renderRectWithDamage(CBox* box, const CColor& col, CRegion TRACY_GPU_ZONE("RenderRectWithDamage"); CBox newBox = *box; - newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); + m_RenderData.renderModif.applyToBox(newBox); box = &newBox; @@ -723,7 +723,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* return; CBox newBox = *pBox; - newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); + m_RenderData.renderModif.applyToBox(newBox); static auto* const PDIMINACTIVE = &g_pConfigManager->getConfigValuePtr("decoration:dim_inactive")->intValue; @@ -886,7 +886,7 @@ void CHyprOpenGLImpl::renderTexturePrimitive(const CTexture& tex, CBox* pBox) { return; CBox newBox = *pBox; - newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); + m_RenderData.renderModif.applyToBox(newBox); // get transform const auto TRANSFORM = wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform); @@ -940,7 +940,7 @@ void CHyprOpenGLImpl::renderTextureMatte(const CTexture& tex, CBox* pBox, CFrame return; CBox newBox = *pBox; - newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); + m_RenderData.renderModif.applyToBox(newBox); // get transform const auto TRANSFORM = wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform); @@ -1475,14 +1475,14 @@ void CHyprOpenGLImpl::renderBorder(CBox* box, const CGradientValueData& grad, in return; CBox newBox = *box; - newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); + m_RenderData.renderModif.applyToBox(newBox); box = &newBox; if (borderSize < 1) return; - int scaledBorderSize = std::round(borderSize * m_RenderData.pMonitor->scale * m_RenderData.renderModif.scale); + int scaledBorderSize = std::round(borderSize * m_RenderData.pMonitor->scale); // adjust box box->x -= scaledBorderSize; @@ -1779,7 +1779,7 @@ void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const TRACY_GPU_ZONE("RenderShadow"); CBox newBox = *box; - newBox.scale(m_RenderData.renderModif.scale).translate(m_RenderData.renderModif.translate); + m_RenderData.renderModif.applyToBox(newBox); box = &newBox; @@ -2210,4 +2210,26 @@ const SGLPixelFormat* CHyprOpenGLImpl::getPixelFormatFromDRM(uint32_t drmFormat) } return nullptr; -} \ No newline at end of file +} + +void SRenderModifData::applyToBox(CBox& box) { + for (auto& [type, val] : modifs) { + try { + switch (type) { + case RMOD_TYPE_SCALE: box.scale(std::any_cast(val)); break; + case RMOD_TYPE_SCALECENTER: box.scaleFromCenter(std::any_cast(val)); break; + case RMOD_TYPE_TRANSLATE: box.translate(std::any_cast(val)); break; + case RMOD_TYPE_ROTATE: box.rot += std::any_cast(val); break; + case RMOD_TYPE_ROTATECENTER: { + const auto THETA = std::any_cast(val); + const double COS = std::cos(THETA); + const double SIN = std::sin(THETA); + box.rot += THETA; + const auto OLDPOS = box.pos(); + box.x = OLDPOS.x * COS - OLDPOS.y * SIN; + box.y = OLDPOS.y * COS + OLDPOS.x * SIN; + } + } + } catch (std::bad_any_cast& e) { Debug::log(ERR, "BUG THIS OR PLUGIN ERROR: caught a bad_any_cast in SRenderModifData::applyToBox!"); } + } +} diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index cd52fe3e..ba27b608 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -36,8 +36,17 @@ enum eDiscardMode { }; struct SRenderModifData { - Vector2D translate = {}; - float scale = 1.f; + enum eRenderModifType { + RMOD_TYPE_SCALE, /* scale by a float */ + RMOD_TYPE_SCALECENTER, /* scale by a float from the center */ + RMOD_TYPE_TRANSLATE, /* translate by a Vector2D */ + RMOD_TYPE_ROTATE, /* rotate by a float in rad from top left */ + RMOD_TYPE_ROTATECENTER, /* rotate by a float in rad from center */ + }; + + std::vector> modifs; + + void applyToBox(CBox& box); }; struct SGLPixelFormat { diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 533215ce..16607739 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -653,13 +653,17 @@ void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, CMon } void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* time, const Vector2D& translate, const float& scale) { - static auto* const PDIMSPECIAL = &g_pConfigManager->getConfigValuePtr("decoration:dim_special")->floatValue; - static auto* const PBLURSPECIAL = &g_pConfigManager->getConfigValuePtr("decoration:blur:special")->intValue; - static auto* const PBLUR = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; - static auto* const PRENDERTEX = &g_pConfigManager->getConfigValuePtr("misc:disable_hyprland_logo")->intValue; - static auto* const PBACKGROUNDCOLOR = &g_pConfigManager->getConfigValuePtr("misc:background_color")->intValue; + static auto* const PDIMSPECIAL = &g_pConfigManager->getConfigValuePtr("decoration:dim_special")->floatValue; + static auto* const PBLURSPECIAL = &g_pConfigManager->getConfigValuePtr("decoration:blur:special")->intValue; + static auto* const PBLUR = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; + static auto* const PRENDERTEX = &g_pConfigManager->getConfigValuePtr("misc:disable_hyprland_logo")->intValue; + static auto* const PBACKGROUNDCOLOR = &g_pConfigManager->getConfigValuePtr("misc:background_color")->intValue; - const SRenderModifData RENDERMODIFDATA = {translate, scale}; + SRenderModifData RENDERMODIFDATA; + if (translate != Vector2D{0, 0}) + RENDERMODIFDATA.modifs.push_back({SRenderModifData::eRenderModifType::RMOD_TYPE_TRANSLATE, translate}); + if (scale != 1.f) + RENDERMODIFDATA.modifs.push_back({SRenderModifData::eRenderModifType::RMOD_TYPE_SCALE, scale}); if (!pMonitor) return;