From 11d93e1633249cd030e0a0321d2fe4dccc4ebc2e Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Tue, 30 Sep 2025 19:28:26 +0200 Subject: [PATCH] Use Mesh class in classic post-processing effects --- src/libprojectM/MilkdropPreset/Filters.cpp | 53 +++++++--------------- src/libprojectM/MilkdropPreset/Filters.hpp | 8 ++-- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/src/libprojectM/MilkdropPreset/Filters.cpp b/src/libprojectM/MilkdropPreset/Filters.cpp index 472a0e70b..09d472bfa 100644 --- a/src/libprojectM/MilkdropPreset/Filters.cpp +++ b/src/libprojectM/MilkdropPreset/Filters.cpp @@ -4,18 +4,11 @@ namespace libprojectM { namespace MilkdropPreset { Filters::Filters(const PresetState& presetState) - : RenderItem() - , m_presetState(presetState) + : m_presetState(presetState) + , m_filterMesh(Renderer::VertexBufferUsage::StaticDraw) { - RenderItem::Init(); -} - -void Filters::InitVertexAttrib() -{ - glEnableVertexAttribArray(0); - glDisableVertexAttribArray(1); - - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Point), reinterpret_cast(offsetof(Point, x))); + m_filterMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::TriangleStrip); + m_filterMesh.SetVertexCount(4); } void Filters::Draw() @@ -33,7 +26,6 @@ void Filters::Draw() shader->Bind(); shader->SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjection); - glBindVertexArray(m_vaoID); glVertexAttrib4f(1, 1.0, 1.0, 1.0, 1.0); if (m_presetState.brighten) @@ -53,8 +45,7 @@ void Filters::Draw() Invert(); } - glBindVertexArray(0); - + Renderer::Mesh::Unbind(); Renderer::Shader::Unbind(); glDisable(GL_BLEND); @@ -64,31 +55,31 @@ void Filters::Draw() void Filters::Brighten() { glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + m_filterMesh.Draw(); glBlendFunc(GL_ZERO, GL_DST_COLOR); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + m_filterMesh.Draw(); glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + m_filterMesh.Draw(); } void Filters::Darken() { glBlendFunc(GL_ZERO, GL_DST_COLOR); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + m_filterMesh.Draw(); } void Filters::Solarize() { glBlendFunc(GL_ZERO, GL_ONE_MINUS_DST_COLOR); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + m_filterMesh.Draw(); glBlendFunc(GL_DST_COLOR, GL_ONE); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + m_filterMesh.Draw(); } void Filters::Invert() { glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + m_filterMesh.Draw(); } void Filters::UpdateMesh() @@ -102,24 +93,14 @@ void Filters::UpdateMesh() m_viewportWidth = m_presetState.renderContext.viewportSizeX; m_viewportHeight = m_presetState.renderContext.viewportSizeY; - std::array points; - float const fOnePlusInvWidth = 1.0f + 1.0f / static_cast(m_viewportWidth); float const fOnePlusInvHeight = 1.0f + 1.0f / static_cast(m_viewportHeight); - points[0].x = -fOnePlusInvWidth; - points[1].x = fOnePlusInvWidth; - points[2].x = -fOnePlusInvWidth; - points[3].x = fOnePlusInvWidth; - points[0].y = fOnePlusInvHeight; - points[1].y = fOnePlusInvHeight; - points[2].y = -fOnePlusInvHeight; - points[3].y = -fOnePlusInvHeight; + m_filterMesh.Vertices().Set({{-fOnePlusInvWidth, fOnePlusInvHeight}, + {fOnePlusInvWidth, fOnePlusInvHeight}, + {-fOnePlusInvWidth, -fOnePlusInvHeight}, + {fOnePlusInvWidth, -fOnePlusInvHeight}}); - glBindVertexArray(m_vaoID); - glBindBuffer(GL_ARRAY_BUFFER, m_vboID); - glBufferData(GL_ARRAY_BUFFER, sizeof(points), points.data(), GL_STATIC_DRAW); - glBindVertexArray(0); - glBindBuffer(GL_ARRAY_BUFFER, 0); + m_filterMesh.Update(); } } // namespace MilkdropPreset diff --git a/src/libprojectM/MilkdropPreset/Filters.hpp b/src/libprojectM/MilkdropPreset/Filters.hpp index c00084654..1decfcafb 100644 --- a/src/libprojectM/MilkdropPreset/Filters.hpp +++ b/src/libprojectM/MilkdropPreset/Filters.hpp @@ -2,7 +2,7 @@ #include "PresetState.hpp" -#include +#include namespace libprojectM { namespace MilkdropPreset { @@ -10,14 +10,12 @@ namespace MilkdropPreset { /** * @brief Classic Milkdrop 1 postprocessing effects. */ -class Filters : public Renderer::RenderItem +class Filters { public: Filters() = delete; explicit Filters(const PresetState& presetState); - void InitVertexAttrib(); - /** * @brief Applies the configured filters to the current output. */ @@ -48,6 +46,8 @@ private: const PresetState& m_presetState; //!< The global preset state. + Renderer::Mesh m_filterMesh; + int m_viewportWidth{}; //!< Last known viewport width int m_viewportHeight{}; //!< Last known viewport height };