perf: render windows at 0,0

Also cleaned up includes
This commit is contained in:
Matias 2025-07-16 22:40:53 +02:00
parent 9b6c381496
commit d132a016b0
No known key found for this signature in database
GPG Key ID: ED35A6AC65A06B69
5 changed files with 25 additions and 42 deletions

View File

@ -2,10 +2,11 @@
#define WW_RENDERPASSES_H
#include <hyprland/src/desktop/Window.hpp>
#include <hyprland/src/render/Framebuffer.hpp>
#include <hyprland/src/render/OpenGL.hpp>
#include <hyprland/src/render/pass/PassElement.hpp>
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<CBox> boundingBox() override {
return g_pHyprOpenGL->m_renderData.pMonitor->logicalBox();
}
std::optional<CBox> boundingBox() override;
CRegion opaqueRegion() override {
return CRegion {};

View File

@ -1,10 +1,7 @@
#ifndef WW_WOBBLYWINDOW_H
#define WW_WOBBLYWINDOW_H
#include "renderpasses.h"
#include <hyprland/src/Compositor.hpp>
#include <hyprutils/math/Vector2D.hpp>
class CWobblyWindow {
struct SParticle {

View File

@ -3,27 +3,10 @@
#include "version.hpp" // generated by meson
#include "wobblywindow.h"
#include <GLES3/gl32.h>
#include <any>
#include <cmath>
#include <hyprgraphics/color/Color.hpp>
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/desktop/DesktopTypes.hpp>
#include <hyprland/src/desktop/Window.hpp>
#include <hyprland/src/helpers/Monitor.hpp>
#include <hyprland/src/helpers/time/Time.hpp>
#include <hyprland/src/managers/input/InputManager.hpp>
#include <hyprland/src/plugins/PluginAPI.hpp>
#include <hyprland/src/render/Framebuffer.hpp>
#include <hyprland/src/render/OpenGL.hpp>
#include <hyprland/src/render/Renderer.hpp>
#include <hyprland/src/render/pass/PassElement.hpp>
#include <hyprutils/math/Box.hpp>
#include <hyprutils/math/Region.hpp>
#include <hyprutils/math/Vector2D.hpp>
#include <map>
#include <optional>
#include <unistd.h>
// 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<CBindOwnFramebufferPassElement>(&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);

View File

@ -3,6 +3,9 @@
#include "globals.h"
#include "wobblywindow.h"
#include <hyprland/src/render/Framebuffer.hpp>
#include <hyprland/src/render/OpenGL.hpp>
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<float> 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<float> verts;
verts.reserve(vertsPerRow * vertsPerRow * 2);
@ -185,3 +185,7 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
GLCALL(glBindVertexArray(0));
pWindowFB->getTexture()->unbind();
}
std::optional<CBox> CRenderWobblyWindowPassElement::boundingBox() {
return g_pHyprOpenGL->m_renderData.pMonitor->logicalBox();
}

View File

@ -1,6 +1,7 @@
#include "wobblywindow.h"
#include "globals.h"
#include "renderpasses.h"
CWobblyWindow::CWobblyWindow() {
auto&& verts = CRenderWobblyWindowPassElement::s_baseVerts;