mirror of
https://git.allpurposem.at/mat/WiggleWobble.git
synced 2025-12-23 13:01:28 +01:00
fix: improve rendering somewhat but still has damage & order issues
This commit is contained in:
parent
1059a997f3
commit
fd86b84cdf
69
src/main.cpp
69
src/main.cpp
@ -47,14 +47,12 @@ class CBindOwnFramebufferPassElement final: public IPassElement {
|
||||
m_pFramebuffer->bind();
|
||||
g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer;
|
||||
|
||||
GLCALL(glClearColor(0, 0, 0, 0));
|
||||
GLCALL(glClearColor(1, 0, 0, 0));
|
||||
GLCALL(glClear(GL_COLOR_BUFFER_BIT));
|
||||
|
||||
g_pHyprRenderer->damageMonitor(g_pHyprOpenGL->m_renderData.pMonitor.lock());
|
||||
}
|
||||
|
||||
bool needsLiveBlur() override {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool needsPrecomputeBlur() override {
|
||||
@ -66,7 +64,11 @@ class CBindOwnFramebufferPassElement final: public IPassElement {
|
||||
}
|
||||
|
||||
std::optional<CBox> boundingBox() override {
|
||||
return g_pHyprOpenGL->m_renderData.pMonitor->logicalBox();
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
CRegion opaqueRegion() override {
|
||||
return CRegion {};
|
||||
}
|
||||
|
||||
private:
|
||||
@ -148,6 +150,11 @@ class CWobblyWindow {
|
||||
const bool shouldEnd =
|
||||
m_windowMovement.size() == 0 and totalVel.size() / m_particles.size() < .001f;
|
||||
|
||||
// std::println(
|
||||
// "Top left: {}, totalVel: {}",
|
||||
// m_particles[0].position,
|
||||
// totalVel.size() / m_particles.size()
|
||||
// );
|
||||
m_windowMovement = Vector2D {};
|
||||
|
||||
return shouldEnd;
|
||||
@ -223,20 +230,18 @@ class CRenderWobblyWindowPassElement final: public IPassElement {
|
||||
auto&& wobble = g_wobblyWindows[m_pWindow];
|
||||
|
||||
// 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);
|
||||
for (auto&& particle : wobble.m_particles) {
|
||||
verts.push_back(particle.position.x);
|
||||
verts.push_back(particle.position.y);
|
||||
}
|
||||
|
||||
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, g_VBO));
|
||||
GLCALL(
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, verts.size() * sizeof(float), verts.data())
|
||||
);
|
||||
// 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);
|
||||
for (auto&& particle : wobble.m_particles) {
|
||||
verts.push_back(particle.position.x);
|
||||
verts.push_back(particle.position.y);
|
||||
}
|
||||
|
||||
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, g_VBO));
|
||||
GLCALL(glBufferSubData(GL_ARRAY_BUFFER, 0, verts.size() * sizeof(float), verts.data()));
|
||||
// }
|
||||
} else {
|
||||
// restore default verts
|
||||
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, g_VBO));
|
||||
@ -271,11 +276,16 @@ class CRenderWobblyWindowPassElement final: public IPassElement {
|
||||
return g_pHyprOpenGL->m_renderData.pMonitor->logicalBox();
|
||||
}
|
||||
|
||||
CRegion opaqueRegion() override {
|
||||
return CRegion {};
|
||||
}
|
||||
|
||||
private:
|
||||
CFramebuffer* m_pOldFramebuffer;
|
||||
PHLWINDOWREF m_pWindow;
|
||||
};
|
||||
|
||||
// TODO: unregister on close
|
||||
void registerWindow(PHLWINDOW pWindow) {
|
||||
g_windowPositions[pWindow] = pWindow->m_realPosition->value();
|
||||
}
|
||||
@ -336,16 +346,15 @@ void hkRenderWindow(
|
||||
g_windowPositions[pWindow] = pos;
|
||||
}
|
||||
|
||||
if (g_wobblyWindows.contains(pWindow)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return g_wobblyWindows.contains(pWindow);
|
||||
}();
|
||||
|
||||
auto* const pOldFramebuffer = g_pHyprOpenGL->m_renderData.currentFB;
|
||||
|
||||
if (shouldWobble) {
|
||||
// HACK: this should only damage the wobbly bbox
|
||||
// g_pHyprRenderer->damageMonitor(g_pHyprOpenGL->m_renderData.pMonitor.lock());
|
||||
|
||||
PHLWINDOWREF ref {pWindow};
|
||||
|
||||
const auto windowBox = pWindow->getFullWindowBoundingBox();
|
||||
@ -353,15 +362,13 @@ void hkRenderWindow(
|
||||
const auto framebufferSize =
|
||||
Vector2D {windowBox.x + windowBox.width, windowBox.y + windowBox.height};
|
||||
|
||||
if (!g_windowFramebuffers.contains(ref)) {
|
||||
g_windowFramebuffers[ref].alloc(framebufferSize.x, framebufferSize.y);
|
||||
}
|
||||
|
||||
auto&& windowFB = g_windowFramebuffers.at(ref);
|
||||
// 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.release();
|
||||
windowFB.alloc(framebufferSize.x, framebufferSize.y);
|
||||
|
||||
std::println("Resizing FB to size {}", framebufferSize);
|
||||
}
|
||||
|
||||
pRenderer->m_renderPass.add(makeUnique<CBindOwnFramebufferPassElement>(&windowFB));
|
||||
@ -381,7 +388,9 @@ void hkRenderWindow(
|
||||
|
||||
if (shouldWobble) {
|
||||
std::erase_if(g_wobblyWindows, [&](auto&& wobble) {
|
||||
return g_wobblyWindows[pWindow].step(time);
|
||||
const bool shouldErase = g_wobblyWindows[pWindow].step(time);
|
||||
|
||||
return shouldErase;
|
||||
});
|
||||
|
||||
pRenderer->m_renderPass.add(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user