55
66#include " MilkdropStaticShaders.hpp"
77
8- #include " Renderer/ShaderCache.hpp"
8+ #include < Renderer/Point.hpp>
9+ #include < Renderer/ShaderCache.hpp>
910
1011#include < array>
1112
1213namespace libprojectM {
1314namespace MilkdropPreset {
1415
1516BlurTexture::BlurTexture ()
16- : m_blurSampler(std::make_shared<Renderer::Sampler>(GL_CLAMP_TO_EDGE, GL_LINEAR))
17+ : m_blurMesh(Renderer::VertexBufferUsage::StaticDraw, false , true )
18+ , m_blurSampler(std::make_shared<Renderer::Sampler>(GL_CLAMP_TO_EDGE, GL_LINEAR))
1719{
1820 m_blurFramebuffer.CreateColorAttachment (0 , 0 );
1921
20- // Initialize Blur VAO/VBO with a single fullscreen quad.
21- static constexpr std::array<float , 16 > pointsBlur{
22- -1.0 , -1.0 , 0.0 , 0.0 ,
23- 1.0 , -1.0 , 1.0 , 0.0 ,
24- -1.0 , 1.0 , 0.0 , 1.0 ,
25- 1.0 , 1.0 , 1.0 , 1.0 };
22+ // Initialize blur mesh with a single fullscreen quad.
23+ m_blurMesh.SetRenderPrimitiveType (Renderer::Mesh::PrimitiveType::TriangleStrip);
2624
27- glGenBuffers (1 , &m_vboBlur);
28- glGenVertexArrays (1 , &m_vaoBlur);
25+ m_blurMesh.Vertices ().Set ({{-1 .0f , -1 .0f },
26+ {1 .0f , -1 .0f },
27+ {-1 .0f , 1 .0f },
28+ {1 .0f , 1 .0f }});
2929
30- glBindVertexArray (m_vaoBlur);
31- glBindBuffer (GL_ARRAY_BUFFER, m_vboBlur);
30+ m_blurMesh.UVs ().Set ({{0.0 , 0.0 },
31+ {1.0 , 0.0 },
32+ {0.0 , 1.0 },
33+ {1.0 , 1.0 }});
3234
33- glBufferData (GL_ARRAY_BUFFER, sizeof (float ) * pointsBlur.size (), pointsBlur.data (), GL_STATIC_DRAW);
34-
35- glEnableVertexAttribArray (0 );
36- glEnableVertexAttribArray (1 );
37-
38- glVertexAttribPointer (0 , 2 , GL_FLOAT, GL_FALSE, sizeof (float ) * 4 , nullptr ); // Position at index 0 and 1
39- glVertexAttribPointer (1 , 2 , GL_FLOAT, GL_FALSE, sizeof (float ) * 4 , reinterpret_cast <void *>(sizeof (float ) * 2 )); // Texture coord at index 2 and 3
40-
41- glBindVertexArray (0 );
42- glBindBuffer (GL_ARRAY_BUFFER, 0 );
35+ m_blurMesh.Update ();
4336
4437 // Initialize with empty textures.
4538 for (size_t i = 0 ; i < m_blurTextures.size (); i++)
@@ -54,12 +47,6 @@ BlurTexture::BlurTexture()
5447 }
5548}
5649
57- BlurTexture::~BlurTexture ()
58- {
59- glDeleteBuffers (1 , &m_vboBlur);
60- glDeleteVertexArrays (1 , &m_vaoBlur);
61- }
62-
6350void BlurTexture::Initialize (const Renderer::RenderContext& renderContext)
6451{
6552 auto staticShaders = libprojectM::MilkdropPreset::MilkdropStaticShaders::Get ();
@@ -164,7 +151,6 @@ void BlurTexture::Update(const Renderer::Texture& sourceTexture, const PerFrameC
164151 m_blurFramebuffer.Bind (0 );
165152
166153 glBlendFunc (GL_ONE, GL_ZERO);
167- glBindVertexArray (m_vaoBlur);
168154
169155 for (unsigned int pass = 0 ; pass < passes; pass++)
170156 {
@@ -268,15 +254,15 @@ void BlurTexture::Update(const Renderer::Texture& sourceTexture, const PerFrameC
268254 }
269255
270256 // Draw fullscreen quad
271- glDrawArrays (GL_TRIANGLE_STRIP, 0 , 4 );
257+ m_blurMesh. Draw ( );
272258
273259 // Save to blur texture
274260 m_blurTextures[pass]->Bind (0 );
275261 glCopyTexSubImage2D (GL_TEXTURE_2D, 0 , 0 , 0 , 0 , 0 , m_blurTextures[pass]->Width (), m_blurTextures[pass]->Height ());
276262 m_blurTextures[pass]->Unbind (0 );
277263 }
278264
279- glBindVertexArray ( 0 );
265+ Renderer::Mesh::Unbind ( );
280266 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
281267
282268 // Bind previous framebuffer and reset viewport size
0 commit comments