@@ -4,41 +4,35 @@ namespace libprojectM {
44namespace MilkdropPreset {
55
66DarkenCenter::DarkenCenter (PresetState& presetState)
7- : RenderItem( )
8- , m_presetState(presetState )
7+ : m_presetState(presetState )
8+ , m_mesh(Renderer::VertexBufferUsage::StaticDraw, true , false )
99{
10- RenderItem::Init ();
11- }
12-
13- void DarkenCenter::InitVertexAttrib ()
14- {
15- glEnableVertexAttribArray (0 );
16- glEnableVertexAttribArray (1 );
17-
18- glVertexAttribPointer (0 , 2 , GL_FLOAT, GL_FALSE, sizeof (ColoredPoint), nullptr ); // points
19- glVertexAttribPointer (1 , 4 , GL_FLOAT, GL_FALSE, sizeof (ColoredPoint), reinterpret_cast <void *>(offsetof (ColoredPoint, r))); // colors
10+ m_mesh.SetRenderPrimitiveType (Renderer::Mesh::PrimitiveType::TriangleFan);
11+ m_mesh.SetVertexCount (6 );
12+ m_mesh.Colors ().Set ({{0 .0f , 0 .0f , 0 .0f , 3 .0f / 32 .0f },
13+ {0 .0f , 0 .0f , 0 .0f , 0 .0f },
14+ {0 .0f , 0 .0f , 0 .0f , 0 .0f },
15+ {0 .0f , 0 .0f , 0 .0f , 0 .0f },
16+ {0 .0f , 0 .0f , 0 .0f , 0 .0f },
17+ {0 .0f , 0 .0f , 0 .0f , 0 .0f }});
18+ m_mesh.Update ();
2019}
2120
2221void DarkenCenter::Draw ()
2322{
24- glBindVertexArray (m_vaoID);
25-
2623 if (m_presetState.renderContext .aspectY != m_aspectY)
2724 {
2825 m_aspectY = m_presetState.renderContext .aspectY ;
2926
3027 // Update mesh with new aspect ratio if needed
31- float const halfSize = 0 .05f ;
32- std::array<ColoredPoint, 6 > vertices = {{{0 .0f , 0 .0f , 0 .0f , 0 .0f , 0 .0f , 3 .0f / 32 .0f },
33- {0 .0f - halfSize * m_aspectY, 0 .0f , 0 .0f , 0 .0f , 0 .0f , 0 .0f },
34- {0 .0f , 0 .0f - halfSize, 0 .0f , 0 .0f , 0 .0f , 0 .0f },
35- {0 .0f + halfSize * m_aspectY, 0.0 , 0 .0f , 0 .0f , 0 .0f , 0 .0f },
36- {0 .0f , 0 .0f + halfSize, 0 .0f , 0 .0f , 0 .0f , 0 .0f },
37- {0 .0f - halfSize * m_aspectY, 0.0 , 0 .0f , 0 .0f , 0 .0f , 0 .0f }}};
38-
39- glBindBuffer (GL_ARRAY_BUFFER, m_vboID);
40- glBufferData (GL_ARRAY_BUFFER, sizeof (ColoredPoint) * vertices.size (), vertices.data (), GL_STATIC_DRAW);
41- glBindBuffer (GL_ARRAY_BUFFER, 0 );
28+ constexpr float halfSize = 0 .05f ;
29+ m_mesh.Vertices ().Set ({{0 .0f , 0 .0f },
30+ {0 .0f - halfSize * m_aspectY, 0 .0f },
31+ {0 .0f , 0 .0f - halfSize},
32+ {0 .0f + halfSize * m_aspectY, 0 .0f },
33+ {0 .0f , 0 .0f + halfSize},
34+ {0 .0f - halfSize * m_aspectY, 0 .0f }});
35+ m_mesh.Update ();
4236 }
4337
4438 glEnable (GL_BLEND);
@@ -48,10 +42,10 @@ void DarkenCenter::Draw()
4842 shader->Bind ();
4943 shader->SetUniformMat4x4 (" vertex_transformation" , PresetState::orthogonalProjection);
5044
51- glDrawArrays (GL_TRIANGLE_FAN, 0 , 6 );
45+ m_mesh. Draw ( );
5246
5347 glDisable (GL_BLEND);
54- glBindVertexArray ( 0 );
48+ Renderer::Mesh::Unbind ( );
5549 Renderer::Shader::Unbind ();
5650}
5751
0 commit comments