Use Mesh class in classic post-processing effects

This commit is contained in:
Kai Blaschke
2025-09-30 19:28:26 +02:00
parent bfd11fa3bf
commit 11d93e1633
2 changed files with 21 additions and 40 deletions

View File

@ -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<void*>(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<RenderItem::Point, 4> points;
float const fOnePlusInvWidth = 1.0f + 1.0f / static_cast<float>(m_viewportWidth);
float const fOnePlusInvHeight = 1.0f + 1.0f / static_cast<float>(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

View File

@ -2,7 +2,7 @@
#include "PresetState.hpp"
#include <Renderer/RenderItem.hpp>
#include <Renderer/Mesh.hpp>
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
};