@@ -4,18 +4,11 @@ namespace libprojectM {
44namespace MilkdropPreset {
55
66Filters::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
2114void 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()
6455void 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
7465void Filters::Darken ()
7566{
7667 glBlendFunc (GL_ZERO, GL_DST_COLOR);
77- glDrawArrays (GL_TRIANGLE_STRIP, 0 , 4 );
68+ m_filterMesh. Draw ( );
7869}
7970
8071void 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
8879void 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
9485void 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
0 commit comments