mirror of
https://git.allpurposem.at/mat/WiggleWobble.git
synced 2025-12-23 13:01:28 +01:00
chore: use own shader, commit missing getBox fn
This commit is contained in:
parent
b19b163147
commit
e22c5db68a
@ -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/Shader.hpp>
|
||||||
#include <hyprland/src/render/pass/PassElement.hpp>
|
#include <hyprland/src/render/pass/PassElement.hpp>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
class CFramebuffer;
|
class CFramebuffer;
|
||||||
class SShader;
|
|
||||||
|
|
||||||
class CBindOwnFramebufferPassElement final: public IPassElement {
|
class CBindOwnFramebufferPassElement final: public IPassElement {
|
||||||
public:
|
public:
|
||||||
@ -39,7 +40,6 @@ class CBindOwnFramebufferPassElement final: public IPassElement {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class CRenderWobblyWindowPassElement final: public IPassElement {
|
class CRenderWobblyWindowPassElement final: public IPassElement {
|
||||||
static inline SShader* s_shader {};
|
|
||||||
static inline constexpr unsigned int s_SUBDIVS = 8;
|
static inline constexpr unsigned int s_SUBDIVS = 8;
|
||||||
static_assert(s_SUBDIVS > 0);
|
static_assert(s_SUBDIVS > 0);
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ class CRenderWobblyWindowPassElement final: public IPassElement {
|
|||||||
CFramebuffer* m_pOldFramebuffer;
|
CFramebuffer* m_pOldFramebuffer;
|
||||||
PHLWINDOWREF m_pWindow;
|
PHLWINDOWREF m_pWindow;
|
||||||
|
|
||||||
static inline SShader* s_pShader = nullptr;
|
static inline SShader s_shader;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -27,6 +27,7 @@ class CWobblyWindow {
|
|||||||
CWobblyWindow();
|
CWobblyWindow();
|
||||||
|
|
||||||
bool step(Time::steady_tp time);
|
bool step(Time::steady_tp time);
|
||||||
|
CBox getBox() const;
|
||||||
|
|
||||||
void applyMovement(const Vector2D& movement);
|
void applyMovement(const Vector2D& movement);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -6,17 +6,37 @@
|
|||||||
#include <GLES3/gl32.h>
|
#include <GLES3/gl32.h>
|
||||||
#include <hyprland/src/render/Framebuffer.hpp>
|
#include <hyprland/src/render/Framebuffer.hpp>
|
||||||
#include <hyprland/src/render/OpenGL.hpp>
|
#include <hyprland/src/render/OpenGL.hpp>
|
||||||
|
#include <hyprland/src/render/Renderer.hpp>
|
||||||
|
|
||||||
void CBindOwnFramebufferPassElement::draw(const CRegion& damage) {
|
void CBindOwnFramebufferPassElement::draw(const CRegion& damage) {
|
||||||
|
g_pHyprOpenGL->scissor(nullptr);
|
||||||
|
|
||||||
m_pFramebuffer->bind();
|
m_pFramebuffer->bind();
|
||||||
g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer;
|
g_pHyprOpenGL->m_renderData.currentFB = m_pFramebuffer;
|
||||||
|
|
||||||
GLCALL(glClearColor(0, 0, 0, 0));
|
GLCALL(glClearColor(0, 0, 0, 0));
|
||||||
GLCALL(glClear(GL_COLOR_BUFFER_BIT));
|
GLCALL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRenderWobblyWindowPassElement::initGPUObjects() {
|
void CRenderWobblyWindowPassElement::initGPUObjects() {
|
||||||
s_pShader = &g_pHyprOpenGL->m_shaders->m_shRGBA;
|
constexpr const char* FRAGSRC = R"glsl(#version 300 es
|
||||||
|
|
||||||
|
precision highp float;
|
||||||
|
in vec2 v_texcoord; // is in 0-1
|
||||||
|
uniform sampler2D tex;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 fragColor;
|
||||||
|
void main() {
|
||||||
|
fragColor = texture(tex, v_texcoord);
|
||||||
|
}
|
||||||
|
)glsl";
|
||||||
|
|
||||||
|
s_shader.program = g_pHyprOpenGL->createProgram(g_pHyprOpenGL->m_shaders->TEXVERTSRC, FRAGSRC);
|
||||||
|
s_shader.uniformLocations[SHADER_PROJ] = glGetUniformLocation(s_shader.program, "proj");
|
||||||
|
s_shader.uniformLocations[SHADER_TEX] = glGetUniformLocation(s_shader.program, "tex");
|
||||||
|
s_shader.uniformLocations[SHADER_TEX_ATTRIB] =
|
||||||
|
glGetAttribLocation(s_shader.program, "texcoord");
|
||||||
|
s_shader.uniformLocations[SHADER_POS_ATTRIB] = glGetAttribLocation(s_shader.program, "pos");
|
||||||
|
|
||||||
const unsigned int vertsPerRow = s_SUBDIVS + 1;
|
const unsigned int vertsPerRow = s_SUBDIVS + 1;
|
||||||
s_baseVerts.reserve(vertsPerRow * vertsPerRow * 2);
|
s_baseVerts.reserve(vertsPerRow * vertsPerRow * 2);
|
||||||
@ -68,9 +88,9 @@ void CRenderWobblyWindowPassElement::initGPUObjects() {
|
|||||||
GL_DYNAMIC_DRAW
|
GL_DYNAMIC_DRAW
|
||||||
));
|
));
|
||||||
|
|
||||||
GLCALL(glEnableVertexAttribArray(s_pShader->uniformLocations[SHADER_POS_ATTRIB]));
|
GLCALL(glEnableVertexAttribArray(s_shader.uniformLocations[SHADER_POS_ATTRIB]));
|
||||||
GLCALL(glVertexAttribPointer(
|
GLCALL(glVertexAttribPointer(
|
||||||
s_pShader->uniformLocations[SHADER_POS_ATTRIB],
|
s_shader.uniformLocations[SHADER_POS_ATTRIB],
|
||||||
2,
|
2,
|
||||||
GL_FLOAT,
|
GL_FLOAT,
|
||||||
GL_FALSE,
|
GL_FALSE,
|
||||||
@ -87,9 +107,9 @@ void CRenderWobblyWindowPassElement::initGPUObjects() {
|
|||||||
s_baseVerts.data(),
|
s_baseVerts.data(),
|
||||||
GL_DYNAMIC_DRAW
|
GL_DYNAMIC_DRAW
|
||||||
)); // Initial dummy UVs
|
)); // Initial dummy UVs
|
||||||
GLCALL(glEnableVertexAttribArray(s_pShader->uniformLocations[SHADER_TEX_ATTRIB]));
|
GLCALL(glEnableVertexAttribArray(s_shader.uniformLocations[SHADER_TEX_ATTRIB]));
|
||||||
GLCALL(glVertexAttribPointer(
|
GLCALL(glVertexAttribPointer(
|
||||||
s_pShader->uniformLocations[SHADER_TEX_ATTRIB],
|
s_shader.uniformLocations[SHADER_TEX_ATTRIB],
|
||||||
2,
|
2,
|
||||||
GL_FLOAT,
|
GL_FLOAT,
|
||||||
GL_FALSE,
|
GL_FALSE,
|
||||||
@ -110,6 +130,7 @@ void CRenderWobblyWindowPassElement::deinitGPUObjects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
|
void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
|
||||||
|
g_pHyprOpenGL->scissor(nullptr);
|
||||||
auto* const pWindowFB = g_pHyprOpenGL->m_renderData.currentFB;
|
auto* const pWindowFB = g_pHyprOpenGL->m_renderData.currentFB;
|
||||||
|
|
||||||
m_pOldFramebuffer->bind();
|
m_pOldFramebuffer->bind();
|
||||||
@ -131,12 +152,11 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
|
|||||||
GLCALL(glActiveTexture(GL_TEXTURE0));
|
GLCALL(glActiveTexture(GL_TEXTURE0));
|
||||||
pWindowFB->getTexture()->bind();
|
pWindowFB->getTexture()->bind();
|
||||||
|
|
||||||
g_pHyprOpenGL->useProgram(s_pShader->program);
|
g_pHyprOpenGL->useProgram(s_shader.program);
|
||||||
s_pShader->setUniformMatrix3fv(SHADER_PROJ, 1, GL_TRUE, glMatrix.getMatrix());
|
s_shader.setUniformMatrix3fv(SHADER_PROJ, 1, GL_TRUE, glMatrix.getMatrix());
|
||||||
s_pShader->setUniformInt(SHADER_TEX, 0);
|
s_shader.setUniformInt(SHADER_TEX, 0);
|
||||||
|
|
||||||
GLCALL(glBindVertexArray(s_VAO));
|
GLCALL(glBindVertexArray(s_VAO));
|
||||||
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, s_VBO));
|
|
||||||
|
|
||||||
const Vector2D UVSize = Vector2D {windowBox.width, windowBox.height} / pWindowFB->m_size;
|
const Vector2D UVSize = Vector2D {windowBox.width, windowBox.height} / pWindowFB->m_size;
|
||||||
|
|
||||||
@ -162,9 +182,6 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
|
|||||||
if (g_wobblyWindows.contains(m_pWindow)) {
|
if (g_wobblyWindows.contains(m_pWindow)) {
|
||||||
auto&& wobble = g_wobblyWindows[m_pWindow];
|
auto&& wobble = g_wobblyWindows[m_pWindow];
|
||||||
|
|
||||||
// TODO: these should never be nan
|
|
||||||
// if (not std::isnan(wobble.m_particles[0].position.x)) {
|
|
||||||
|
|
||||||
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, s_VBO));
|
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, s_VBO));
|
||||||
GLCALL(glBufferSubData(
|
GLCALL(glBufferSubData(
|
||||||
GL_ARRAY_BUFFER,
|
GL_ARRAY_BUFFER,
|
||||||
@ -172,7 +189,6 @@ void CRenderWobblyWindowPassElement::draw(const CRegion& damage) {
|
|||||||
wobble.m_particlePositions.size() * sizeof(float),
|
wobble.m_particlePositions.size() * sizeof(float),
|
||||||
wobble.m_particlePositions.data()
|
wobble.m_particlePositions.data()
|
||||||
));
|
));
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
// restore default verts
|
// restore default verts
|
||||||
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, s_VBO));
|
GLCALL(glBindBuffer(GL_ARRAY_BUFFER, s_VBO));
|
||||||
|
|||||||
@ -65,10 +65,20 @@ bool CWobblyWindow::step(Time::steady_tp time) {
|
|||||||
const bool shouldEnd = m_windowMovement.size() == 0
|
const bool shouldEnd = m_windowMovement.size() == 0
|
||||||
and totalVel.size() / (m_particlePositions.size() / 2.f) < .001f;
|
and totalVel.size() / (m_particlePositions.size() / 2.f) < .001f;
|
||||||
|
|
||||||
|
// HACK: why is it ever nan??
|
||||||
|
if (std::isnan(m_particlePositions[0])) {
|
||||||
|
// reset
|
||||||
|
m_particlePositions = CRenderWobblyWindowPassElement::s_baseVerts;
|
||||||
|
|
||||||
|
m_particleVelocities.clear();
|
||||||
|
m_particleVelocities.resize(m_particlePositions.size());
|
||||||
|
}
|
||||||
|
//
|
||||||
// std::println(
|
// std::println(
|
||||||
// "Top left: {}, totalVel: {}",
|
// "Top left: ({}, {}), totalVel: {}",
|
||||||
// m_particles[0].position,
|
// m_particlePositions[0],
|
||||||
// totalVel.size() / m_particles.size()
|
// m_particlePositions[1],
|
||||||
|
// totalVel.size() / m_particlePositions.size() * 2
|
||||||
// );
|
// );
|
||||||
m_windowMovement = Vector2D {};
|
m_windowMovement = Vector2D {};
|
||||||
|
|
||||||
@ -83,3 +93,25 @@ void CWobblyWindow::applyMovement(const Vector2D& movement) {
|
|||||||
m_particlePositions[i * 2 + 1] -= movement.y;
|
m_particlePositions[i * 2 + 1] -= movement.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Hyprutils::Math::CBox CWobblyWindow::getBox() const {
|
||||||
|
Vector2D min {};
|
||||||
|
Vector2D max {};
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < m_particlePositions.size() / 2; i++) {
|
||||||
|
auto&& x = m_particlePositions[i * 2];
|
||||||
|
auto&& y = m_particlePositions[i * 2 + 1];
|
||||||
|
|
||||||
|
if (x > max.x)
|
||||||
|
max.x = x;
|
||||||
|
if (x < min.x)
|
||||||
|
min.x = x;
|
||||||
|
|
||||||
|
if (y > max.y)
|
||||||
|
max.y = y;
|
||||||
|
if (y < min.y)
|
||||||
|
min.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CBox(min, max - min);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user