mirror of
https://git.allpurposem.at/mat/WiggleWobble.git
synced 2025-12-23 21:11:29 +01:00
perf: render windows at 0,0
Also cleaned up includes
This commit is contained in:
parent
9b6c381496
commit
d132a016b0
@ -2,10 +2,11 @@
|
|||||||
#define WW_RENDERPASSES_H
|
#define WW_RENDERPASSES_H
|
||||||
|
|
||||||
#include <hyprland/src/desktop/Window.hpp>
|
#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>
|
#include <hyprland/src/render/pass/PassElement.hpp>
|
||||||
|
|
||||||
|
class CFramebuffer;
|
||||||
|
class SShader;
|
||||||
|
|
||||||
class CBindOwnFramebufferPassElement final: public IPassElement {
|
class CBindOwnFramebufferPassElement final: public IPassElement {
|
||||||
public:
|
public:
|
||||||
explicit CBindOwnFramebufferPassElement(CFramebuffer* pFramebuffer) :
|
explicit CBindOwnFramebufferPassElement(CFramebuffer* pFramebuffer) :
|
||||||
@ -67,9 +68,7 @@ class CRenderWobblyWindowPassElement final: public IPassElement {
|
|||||||
return "RENDER_WOBBLY_WINDOW";
|
return "RENDER_WOBBLY_WINDOW";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<CBox> boundingBox() override {
|
std::optional<CBox> boundingBox() override;
|
||||||
return g_pHyprOpenGL->m_renderData.pMonitor->logicalBox();
|
|
||||||
}
|
|
||||||
|
|
||||||
CRegion opaqueRegion() override {
|
CRegion opaqueRegion() override {
|
||||||
return CRegion {};
|
return CRegion {};
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
#ifndef WW_WOBBLYWINDOW_H
|
#ifndef WW_WOBBLYWINDOW_H
|
||||||
#define WW_WOBBLYWINDOW_H
|
#define WW_WOBBLYWINDOW_H
|
||||||
|
|
||||||
#include "renderpasses.h"
|
|
||||||
|
|
||||||
#include <hyprland/src/Compositor.hpp>
|
#include <hyprland/src/Compositor.hpp>
|
||||||
#include <hyprutils/math/Vector2D.hpp>
|
|
||||||
|
|
||||||
class CWobblyWindow {
|
class CWobblyWindow {
|
||||||
struct SParticle {
|
struct SParticle {
|
||||||
|
|||||||
34
src/main.cpp
34
src/main.cpp
@ -3,27 +3,10 @@
|
|||||||
#include "version.hpp" // generated by meson
|
#include "version.hpp" // generated by meson
|
||||||
#include "wobblywindow.h"
|
#include "wobblywindow.h"
|
||||||
|
|
||||||
#include <GLES3/gl32.h>
|
|
||||||
#include <any>
|
#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/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/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 <optional>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
// Do NOT change this function.
|
// Do NOT change this function.
|
||||||
APICALL EXPORT std::string PLUGIN_API_VERSION() {
|
APICALL EXPORT std::string PLUGIN_API_VERSION() {
|
||||||
@ -103,6 +86,7 @@ void hkRenderWindow(
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
auto* const pOldFramebuffer = g_pHyprOpenGL->m_renderData.currentFB;
|
auto* const pOldFramebuffer = g_pHyprOpenGL->m_renderData.currentFB;
|
||||||
|
const auto windowBox = pWindow->getFullWindowBoundingBox();
|
||||||
|
|
||||||
if (shouldWobble) {
|
if (shouldWobble) {
|
||||||
// HACK: this should only damage the wobbly bbox
|
// HACK: this should only damage the wobbly bbox
|
||||||
@ -110,20 +94,16 @@ void hkRenderWindow(
|
|||||||
|
|
||||||
PHLWINDOWREF ref {pWindow};
|
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
|
// create it if not exists
|
||||||
auto&& windowFB = g_windowFramebuffers[ref];
|
auto&& windowFB = g_windowFramebuffers[ref];
|
||||||
|
|
||||||
if (framebufferSize.x > windowFB.m_size.x or framebufferSize.y > windowFB.m_size.y) {
|
if (windowBox.width > windowFB.m_size.x or windowBox.height > windowFB.m_size.y) {
|
||||||
windowFB.alloc(framebufferSize.x, framebufferSize.y);
|
windowFB.alloc(windowBox.width, windowBox.height);
|
||||||
|
|
||||||
std::println("Resizing FB to size {}", framebufferSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// render window at 0,0 (we translate it afterward)
|
||||||
|
pWindow->m_floatingOffset -= Vector2D {windowBox.x, windowBox.y};
|
||||||
|
|
||||||
pRenderer->m_renderPass.add(makeUnique<CBindOwnFramebufferPassElement>(&windowFB));
|
pRenderer->m_renderPass.add(makeUnique<CBindOwnFramebufferPassElement>(&windowFB));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,6 +120,8 @@ void hkRenderWindow(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (shouldWobble) {
|
if (shouldWobble) {
|
||||||
|
pWindow->m_floatingOffset += Vector2D {windowBox.x, windowBox.y};
|
||||||
|
|
||||||
std::erase_if(g_wobblyWindows, [&](auto&& wobble) {
|
std::erase_if(g_wobblyWindows, [&](auto&& wobble) {
|
||||||
const bool shouldErase = g_wobblyWindows[pWindow].step(time);
|
const bool shouldErase = g_wobblyWindows[pWindow].step(time);
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,9 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "wobblywindow.h"
|
#include "wobblywindow.h"
|
||||||
|
|
||||||
|
#include <hyprland/src/render/Framebuffer.hpp>
|
||||||
|
#include <hyprland/src/render/OpenGL.hpp>
|
||||||
|
|
||||||
void CBindOwnFramebufferPassElement::draw(const CRegion& damage) {
|
void CBindOwnFramebufferPassElement::draw(const CRegion& damage) {
|
||||||
m_pFramebuffer->bind();
|
m_pFramebuffer->bind();
|
||||||
g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer;
|
g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer;
|
||||||
@ -127,22 +130,18 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
|
|||||||
GLCALL(glBindVertexArray(s_VAO));
|
GLCALL(glBindVertexArray(s_VAO));
|
||||||
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, s_VBO));
|
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, s_VBO));
|
||||||
|
|
||||||
// TODO: can we avoid this entirely by rendering the window to framebuffer pos 0,0?
|
const Vector2D UVSize = Vector2D {windowBox.width, windowBox.height} / pWindowFB->m_size;
|
||||||
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 unsigned int vertsPerRow = s_SUBDIVS + 1;
|
const unsigned int vertsPerRow = s_SUBDIVS + 1;
|
||||||
std::vector<float> UVs;
|
std::vector<float> UVs;
|
||||||
UVs.reserve(vertsPerRow * vertsPerRow * 2);
|
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) {
|
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) {
|
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(u);
|
||||||
UVs.push_back(v);
|
UVs.push_back(v);
|
||||||
@ -157,6 +156,7 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
|
|||||||
|
|
||||||
// TODO: these should never be nan
|
// TODO: these should never be nan
|
||||||
// if (not std::isnan(wobble.m_particles[0].position.x)) {
|
// if (not std::isnan(wobble.m_particles[0].position.x)) {
|
||||||
|
|
||||||
// TODO: we need the particle positions in their own vec, to avoid this copy
|
// TODO: we need the particle positions in their own vec, to avoid this copy
|
||||||
std::vector<float> verts;
|
std::vector<float> verts;
|
||||||
verts.reserve(vertsPerRow * vertsPerRow * 2);
|
verts.reserve(vertsPerRow * vertsPerRow * 2);
|
||||||
@ -185,3 +185,7 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
|
|||||||
GLCALL(glBindVertexArray(0));
|
GLCALL(glBindVertexArray(0));
|
||||||
pWindowFB->getTexture()->unbind();
|
pWindowFB->getTexture()->unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<CBox> CRenderWobblyWindowPassElement::boundingBox() {
|
||||||
|
return g_pHyprOpenGL->m_renderData.pMonitor->logicalBox();
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "wobblywindow.h"
|
#include "wobblywindow.h"
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "renderpasses.h"
|
||||||
|
|
||||||
CWobblyWindow::CWobblyWindow() {
|
CWobblyWindow::CWobblyWindow() {
|
||||||
auto&& verts = CRenderWobblyWindowPassElement::s_baseVerts;
|
auto&& verts = CRenderWobblyWindowPassElement::s_baseVerts;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user