Skip to content

Commit 3e510ad

Browse files
committed
Use Mesh class in classic post-processing effects
1 parent 4ff86c1 commit 3e510ad

File tree

2 files changed

+22
-41
lines changed

2 files changed

+22
-41
lines changed

src/libprojectM/MilkdropPreset/Filters.cpp

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@ namespace libprojectM {
44
namespace MilkdropPreset {
55

66
Filters::Filters(const PresetState& presetState)
7-
: RenderItem()
8-
, m_presetState(presetState)
7+
: m_presetState(presetState)
8+
, m_filterMesh(Renderer::VertexBufferUsage::StaticDraw)
99
{
10-
RenderItem::Init();
11-
}
12-
13-
void Filters::InitVertexAttrib()
14-
{
15-
glEnableVertexAttribArray(0);
16-
glDisableVertexAttribArray(1);
17-
18-
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Point), reinterpret_cast<void*>(offsetof(Point, x)));
10+
m_filterMesh.SetRenderPrimitiveType(Renderer::Mesh::PrimitiveType::TriangleStrip);
11+
m_filterMesh.SetVertexCount(4);
1912
}
2013

2114
void Filters::Draw()
@@ -33,7 +26,6 @@ void Filters::Draw()
3326
shader->Bind();
3427
shader->SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjection);
3528

36-
glBindVertexArray(m_vaoID);
3729
glVertexAttrib4f(1, 1.0, 1.0, 1.0, 1.0);
3830

3931
if (m_presetState.brighten)
@@ -53,8 +45,7 @@ void Filters::Draw()
5345
Invert();
5446
}
5547

56-
glBindVertexArray(0);
57-
48+
Renderer::Mesh::Unbind();
5849
Renderer::Shader::Unbind();
5950

6051
glDisable(GL_BLEND);
@@ -64,31 +55,31 @@ void Filters::Draw()
6455
void Filters::Brighten()
6556
{
6657
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
67-
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
58+
m_filterMesh.Draw();
6859
glBlendFunc(GL_ZERO, GL_DST_COLOR);
69-
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
60+
m_filterMesh.Draw();
7061
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
71-
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
62+
m_filterMesh.Draw();
7263
}
7364

7465
void Filters::Darken()
7566
{
7667
glBlendFunc(GL_ZERO, GL_DST_COLOR);
77-
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
68+
m_filterMesh.Draw();
7869
}
7970

8071
void Filters::Solarize()
8172
{
8273
glBlendFunc(GL_ZERO, GL_ONE_MINUS_DST_COLOR);
83-
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
74+
m_filterMesh.Draw();
8475
glBlendFunc(GL_DST_COLOR, GL_ONE);
85-
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
76+
m_filterMesh.Draw();
8677
}
8778

8879
void Filters::Invert()
8980
{
9081
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
91-
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
82+
m_filterMesh.Draw();
9283
}
9384

9485
void Filters::UpdateMesh()
@@ -102,24 +93,14 @@ void Filters::UpdateMesh()
10293
m_viewportWidth = m_presetState.renderContext.viewportSizeX;
10394
m_viewportHeight = m_presetState.renderContext.viewportSizeY;
10495

105-
std::array<RenderItem::Point, 4> points;
106-
10796
float const fOnePlusInvWidth = 1.0f + 1.0f / static_cast<float>(m_viewportWidth);
10897
float const fOnePlusInvHeight = 1.0f + 1.0f / static_cast<float>(m_viewportHeight);
109-
points[0].x = -fOnePlusInvWidth;
110-
points[1].x = fOnePlusInvWidth;
111-
points[2].x = -fOnePlusInvWidth;
112-
points[3].x = fOnePlusInvWidth;
113-
points[0].y = fOnePlusInvHeight;
114-
points[1].y = fOnePlusInvHeight;
115-
points[2].y = -fOnePlusInvHeight;
116-
points[3].y = -fOnePlusInvHeight;
117-
118-
glBindVertexArray(m_vaoID);
119-
glBindBuffer(GL_ARRAY_BUFFER, m_vboID);
120-
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points.data(), GL_STATIC_DRAW);
121-
glBindVertexArray(0);
122-
glBindBuffer(GL_ARRAY_BUFFER, 0);
98+
m_filterMesh.Vertices().Set({{-fOnePlusInvWidth, fOnePlusInvHeight},
99+
{fOnePlusInvWidth, fOnePlusInvHeight},
100+
{-fOnePlusInvWidth, -fOnePlusInvHeight},
101+
{fOnePlusInvWidth, -fOnePlusInvHeight}});
102+
103+
m_filterMesh.Update();
123104
}
124105

125106
} // namespace MilkdropPreset

src/libprojectM/MilkdropPreset/Filters.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
#include "PresetState.hpp"
44

5-
#include <Renderer/RenderItem.hpp>
5+
#include <Renderer/Mesh.hpp>
66

77
namespace libprojectM {
88
namespace MilkdropPreset {
99

1010
/**
1111
* @brief Classic Milkdrop 1 postprocessing effects.
1212
*/
13-
class Filters : public Renderer::RenderItem
13+
class Filters
1414
{
1515
public:
1616
Filters() = delete;
1717
explicit Filters(const PresetState& presetState);
1818

19-
void InitVertexAttrib();
20-
2119
/**
2220
* @brief Applies the configured filters to the current output.
2321
*/
@@ -48,6 +46,8 @@ class Filters : public Renderer::RenderItem
4846

4947
const PresetState& m_presetState; //!< The global preset state.
5048

49+
Renderer::Mesh m_filterMesh;
50+
5151
int m_viewportWidth{}; //!< Last known viewport width
5252
int m_viewportHeight{}; //!< Last known viewport height
5353
};

0 commit comments

Comments
 (0)