diff --git a/include/renderpasses.h b/include/renderpasses.h index 3535cb1..583460f 100644 --- a/include/renderpasses.h +++ b/include/renderpasses.h @@ -2,10 +2,11 @@ #define WW_RENDERPASSES_H #include -#include -#include #include +class CFramebuffer; +class SShader; + class CBindOwnFramebufferPassElement final: public IPassElement { public: explicit CBindOwnFramebufferPassElement(CFramebuffer* pFramebuffer) : @@ -67,9 +68,7 @@ class CRenderWobblyWindowPassElement final: public IPassElement { return "RENDER_WOBBLY_WINDOW"; } - std::optional boundingBox() override { - return g_pHyprOpenGL->m_renderData.pMonitor->logicalBox(); - } + std::optional boundingBox() override; CRegion opaqueRegion() override { return CRegion {}; diff --git a/include/wobblywindow.h b/include/wobblywindow.h index 11f0d02..5734056 100644 --- a/include/wobblywindow.h +++ b/include/wobblywindow.h @@ -1,10 +1,7 @@ #ifndef WW_WOBBLYWINDOW_H #define WW_WOBBLYWINDOW_H -#include "renderpasses.h" - #include -#include class CWobblyWindow { struct SParticle { diff --git a/src/main.cpp b/src/main.cpp index dd5b323..525534f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,27 +3,10 @@ #include "version.hpp" // generated by meson #include "wobblywindow.h" -#include #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include #include -#include // Do NOT change this function. APICALL EXPORT std::string PLUGIN_API_VERSION() { @@ -103,6 +86,7 @@ void hkRenderWindow( }(); auto* const pOldFramebuffer = g_pHyprOpenGL->m_renderData.currentFB; + const auto windowBox = pWindow->getFullWindowBoundingBox(); if (shouldWobble) { // HACK: this should only damage the wobbly bbox @@ -110,20 +94,16 @@ void hkRenderWindow( PHLWINDOWREF ref {pWindow}; - const auto windowBox = pWindow->getFullWindowBoundingBox(); - const auto windowSize = Vector2D {windowBox.width, windowBox.height}; - const auto framebufferSize = - Vector2D {windowBox.x + windowBox.width, windowBox.y + windowBox.height}; - // create it if not exists auto&& windowFB = g_windowFramebuffers[ref]; - if (framebufferSize.x > windowFB.m_size.x or framebufferSize.y > windowFB.m_size.y) { - windowFB.alloc(framebufferSize.x, framebufferSize.y); - - std::println("Resizing FB to size {}", framebufferSize); + if (windowBox.width > windowFB.m_size.x or windowBox.height > windowFB.m_size.y) { + windowFB.alloc(windowBox.width, windowBox.height); } + // render window at 0,0 (we translate it afterward) + pWindow->m_floatingOffset -= Vector2D {windowBox.x, windowBox.y}; + pRenderer->m_renderPass.add(makeUnique(&windowFB)); } @@ -140,6 +120,8 @@ void hkRenderWindow( ); if (shouldWobble) { + pWindow->m_floatingOffset += Vector2D {windowBox.x, windowBox.y}; + std::erase_if(g_wobblyWindows, [&](auto&& wobble) { const bool shouldErase = g_wobblyWindows[pWindow].step(time); diff --git a/src/renderpasses.cpp b/src/renderpasses.cpp index b052248..82309bb 100644 --- a/src/renderpasses.cpp +++ b/src/renderpasses.cpp @@ -3,6 +3,9 @@ #include "globals.h" #include "wobblywindow.h" +#include +#include + void CBindOwnFramebufferPassElement::draw(const CRegion& damage) { m_pFramebuffer->bind(); g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer; @@ -127,22 +130,18 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) { GLCALL(glBindVertexArray(s_VAO)); GLCALL(glBindBuffer(GL_ARRAY_BUFFER, s_VBO)); - // TODO: can we avoid this entirely by rendering the window to framebuffer pos 0,0? - const Vector2D UVTopLeft = Vector2D {windowBox.x, windowBox.y} / pWindowFB->m_size; - const Vector2D UVBottomRight = - Vector2D {windowBox.x + windowBox.width, windowBox.y + windowBox.height} - / pWindowFB->m_size; + const Vector2D UVSize = Vector2D {windowBox.width, windowBox.height} / pWindowFB->m_size; const unsigned int vertsPerRow = s_SUBDIVS + 1; std::vector UVs; UVs.reserve(vertsPerRow * vertsPerRow * 2); - const auto step = (UVBottomRight - UVTopLeft) / (s_SUBDIVS); + const auto step = UVSize / s_SUBDIVS; for (unsigned int y = 0; y < vertsPerRow; ++y) { - const float v = UVTopLeft.y + y * step.y; + const float v = y * step.y; for (unsigned int x = 0; x < vertsPerRow; ++x) { - const float u = UVTopLeft.x + x * step.x; + const float u = x * step.x; UVs.push_back(u); UVs.push_back(v); @@ -157,6 +156,7 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) { // TODO: these should never be nan // if (not std::isnan(wobble.m_particles[0].position.x)) { + // TODO: we need the particle positions in their own vec, to avoid this copy std::vector verts; verts.reserve(vertsPerRow * vertsPerRow * 2); @@ -185,3 +185,7 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) { GLCALL(glBindVertexArray(0)); pWindowFB->getTexture()->unbind(); } + +std::optional CRenderWobblyWindowPassElement::boundingBox() { + return g_pHyprOpenGL->m_renderData.pMonitor->logicalBox(); +} diff --git a/src/wobblywindow.cpp b/src/wobblywindow.cpp index 7de9e42..4359c4f 100644 --- a/src/wobblywindow.cpp +++ b/src/wobblywindow.cpp @@ -1,6 +1,7 @@ #include "wobblywindow.h" #include "globals.h" +#include "renderpasses.h" CWobblyWindow::CWobblyWindow() { auto&& verts = CRenderWobblyWindowPassElement::s_baseVerts;