@@ -4,21 +4,11 @@ namespace libprojectM {
44namespace MilkdropPreset {
55
66VideoEcho::VideoEcho (const PresetState& presetState)
7- : RenderItem( )
8- , m_presetState(presetState )
7+ : m_presetState(presetState )
8+ , m_echoMesh(Renderer::VertexBufferUsage::DynamicDraw, true , true )
99{
10- RenderItem::Init ();
11- }
12-
13- void VideoEcho::InitVertexAttrib ()
14- {
15- glEnableVertexAttribArray (0 );
16- glEnableVertexAttribArray (1 );
17- glEnableVertexAttribArray (2 );
18-
19- glVertexAttribPointer (0 , 2 , GL_FLOAT, GL_FALSE, sizeof (TexturedPoint), reinterpret_cast <void *>(offsetof (TexturedPoint, x))); // Position
20- glVertexAttribPointer (1 , 4 , GL_FLOAT, GL_FALSE, sizeof (TexturedPoint), reinterpret_cast <void *>(offsetof (TexturedPoint, r))); // Color
21- glVertexAttribPointer (2 , 2 , GL_FLOAT, GL_FALSE, sizeof (TexturedPoint), reinterpret_cast <void *>(offsetof (TexturedPoint, u))); // Texture coordinates
10+ m_echoMesh.SetRenderPrimitiveType (Renderer::Mesh::PrimitiveType::TriangleStrip);
11+ m_echoMesh.SetVertexCount (4 );
2212}
2313
2414void VideoEcho::Draw ()
@@ -38,15 +28,12 @@ void VideoEcho::Draw()
3828
3929 float const fOnePlusInvWidth = 1 .0f + 1 .0f / static_cast <float >(m_presetState.renderContext .viewportSizeX );
4030 float const fOnePlusInvHeight = 1 .0f + 1 .0f / static_cast <float >(m_presetState.renderContext .viewportSizeY );
41- m_vertices[0 ].x = -fOnePlusInvWidth * aspectMultX;
42- m_vertices[1 ].x = fOnePlusInvWidth * aspectMultX;
43- m_vertices[2 ].x = -fOnePlusInvWidth * aspectMultX;
44- m_vertices[3 ].x = fOnePlusInvWidth * aspectMultX;
45- m_vertices[0 ].y = fOnePlusInvHeight * aspectMultY;
46- m_vertices[1 ].y = fOnePlusInvHeight * aspectMultY;
47- m_vertices[2 ].y = -fOnePlusInvHeight * aspectMultY;
48- m_vertices[3 ].y = -fOnePlusInvHeight * aspectMultY;
31+ m_echoMesh.Vertices ().Set ({{-fOnePlusInvWidth * aspectMultX, fOnePlusInvHeight * aspectMultY},
32+ {fOnePlusInvWidth * aspectMultX, fOnePlusInvHeight * aspectMultY},
33+ {-fOnePlusInvWidth * aspectMultX, -fOnePlusInvHeight * aspectMultY},
34+ {fOnePlusInvWidth * aspectMultX, -fOnePlusInvHeight * aspectMultY}});
4935
36+ auto & colors = m_echoMesh.Colors ();
5037 for (int i = 0 ; i < 4 ; i++)
5138 {
5239 auto const indexFloat = static_cast <float >(i);
@@ -62,10 +49,10 @@ void VideoEcho::Draw()
6249 m_shade[i][k] = 0 .5f + 0 .5f * m_shade[i][k];
6350 }
6451
65- m_vertices [i]. r = m_shade[i][0 ];
66- m_vertices[i]. g = m_shade[i][1 ];
67- m_vertices[i]. b = m_shade[i][2 ];
68- m_vertices[i]. a = 1 .0f ;
52+ colors [i] = { m_shade[i][0 ],
53+ m_shade[i][1 ],
54+ m_shade[i][2 ],
55+ 1 .0f } ;
6956 }
7057
7158 auto shader = m_presetState.texturedShader .lock ();
@@ -80,9 +67,6 @@ void VideoEcho::Draw()
8067 m_sampler.Bind (0 );
8168 }
8269
83- glBindVertexArray (m_vaoID);
84- glBindBuffer (GL_ARRAY_BUFFER, m_vboID);
85-
8670 if (m_presetState.videoEchoAlpha > 0 .001f )
8771 {
8872 DrawVideoEcho ();
@@ -92,11 +76,9 @@ void VideoEcho::Draw()
9276 DrawGammaAdjustment ();
9377 }
9478
95- glBindBuffer (GL_ARRAY_BUFFER, 0 );
96- glBindVertexArray (0 );
97-
9879 glDisable (GL_BLEND);
9980
81+ Renderer::Mesh::Unbind ();
10082 Renderer::Shader::Unbind ();
10183
10284 if (mainTexture)
@@ -121,15 +103,12 @@ void VideoEcho::DrawVideoEcho()
121103 float const zoom = (pass == 0 ) ? 1 .0f : videoEchoZoom;
122104
123105 float const tempLow = 0 .5f - 0 .5f / zoom;
124- float const temphigh = 0 .5f + 0 .5f / zoom;
125- m_vertices[0 ].u = tempLow;
126- m_vertices[0 ].v = tempLow;
127- m_vertices[1 ].u = temphigh;
128- m_vertices[1 ].v = tempLow;
129- m_vertices[2 ].u = tempLow;
130- m_vertices[2 ].v = temphigh;
131- m_vertices[3 ].u = temphigh;
132- m_vertices[3 ].v = temphigh;
106+ float const tempHigh = 0 .5f + 0 .5f / zoom;
107+
108+ m_echoMesh.UVs ().Set ({{tempLow, tempLow},
109+ {tempHigh, tempLow},
110+ {tempLow, tempHigh},
111+ {tempHigh, tempHigh}});
133112
134113 // Flipping
135114 if (pass == 1 )
@@ -138,26 +117,27 @@ void VideoEcho::DrawVideoEcho()
138117 {
139118 if (videoEchoOrientation % 2 == 1 )
140119 {
141- m_vertices [vertex].u = 1 .0f - m_vertices [vertex].u ;
120+ m_echoMesh. UVs () [vertex].SetU ( 1 .0f - m_echoMesh. UVs () [vertex].U ()) ;
142121 }
143122 if (videoEchoOrientation >= 2 )
144123 {
145- m_vertices [vertex].v = 1 .0f - m_vertices [vertex].v ;
124+ m_echoMesh. UVs () [vertex].SetV ( 1 .0f - m_echoMesh. UVs () [vertex].V ()) ;
146125 }
147126 }
148127 }
149128
150129 float const mix = (pass == 1 ) ? videoEchoAlpha : 1 .0f - videoEchoAlpha;
151130 for (int vertex = 0 ; vertex < 4 ; vertex++)
152131 {
153- m_vertices[vertex].r = mix * m_shade[vertex][0 ];
154- m_vertices[vertex].g = mix * m_shade[vertex][1 ];
155- m_vertices[vertex].b = mix * m_shade[vertex][2 ];
156- m_vertices[vertex].a = 1 .0f ;
132+ m_echoMesh.Colors ()[vertex] = {
133+ mix * m_shade[vertex][0 ],
134+ mix * m_shade[vertex][1 ],
135+ mix * m_shade[vertex][2 ],
136+ 1 .0f };
157137 }
158138
159- glBufferData (GL_ARRAY_BUFFER, static_cast <GLsizei>( sizeof (TexturedPoint) * m_vertices. size ()), m_vertices. data (), GL_DYNAMIC_DRAW );
160- glDrawArrays (GL_TRIANGLE_STRIP, 0 , static_cast <GLsizei>(m_vertices. size ()) );
139+ m_echoMesh. Update ( );
140+ m_echoMesh. Draw ( );
161141
162142 if (pass == 0 )
163143 {
@@ -182,29 +162,26 @@ void VideoEcho::DrawVideoEcho()
182162
183163 for (int vertex = 0 ; vertex < 4 ; vertex++)
184164 {
185- m_vertices[vertex].r = gamma * mix * m_shade[vertex][0 ];
186- m_vertices[vertex].g = gamma * mix * m_shade[vertex][1 ];
187- m_vertices[vertex].b = gamma * mix * m_shade[vertex][2 ];
188- m_vertices[vertex].a = 1 .0f ;
165+ m_echoMesh.Colors ()[vertex] = {
166+ gamma * mix * m_shade[vertex][0 ],
167+ gamma * mix * m_shade[vertex][1 ],
168+ gamma * mix * m_shade[vertex][2 ],
169+ 1 .0f };
189170 }
190171
191- glBufferData (GL_ARRAY_BUFFER, static_cast <GLsizei>( sizeof (TexturedPoint) * m_vertices. size ()), m_vertices. data (), GL_DYNAMIC_DRAW );
192- glDrawArrays (GL_TRIANGLE_STRIP, 0 , static_cast <GLsizei>(m_vertices. size ()) );
172+ m_echoMesh. Colors (). Update ( );
173+ m_echoMesh. Draw ( );
193174 }
194175 }
195176 }
196177}
197178
198179void VideoEcho::DrawGammaAdjustment ()
199180{
200- m_vertices[0 ].u = 0 .0f ;
201- m_vertices[0 ].v = 0 .0f ;
202- m_vertices[1 ].u = 1 .0f ;
203- m_vertices[1 ].v = 0 .0f ;
204- m_vertices[2 ].u = 0 .0f ;
205- m_vertices[2 ].v = 1 .0f ;
206- m_vertices[3 ].u = 1 .0f ;
207- m_vertices[3 ].v = 1 .0f ;
181+ m_echoMesh.UVs ().Set ({{0 .0f , 0 .0f },
182+ {1 .0f , 0 .0f },
183+ {0 .0f , 1 .0f },
184+ {1 .0f , 1 .0f }});
208185
209186 glDisable (GL_BLEND);
210187 glBlendFunc (GL_ONE, GL_ZERO);
@@ -226,14 +203,15 @@ void VideoEcho::DrawGammaAdjustment()
226203
227204 for (int vertex = 0 ; vertex < 4 ; vertex++)
228205 {
229- m_vertices[vertex].r = gamma * m_shade[vertex][0 ];
230- m_vertices[vertex].g = gamma * m_shade[vertex][1 ];
231- m_vertices[vertex].b = gamma * m_shade[vertex][2 ];
232- m_vertices[vertex].a = 1 .0f ;
206+ m_echoMesh.Colors ()[vertex] = {
207+ gamma * m_shade[vertex][0 ],
208+ gamma * m_shade[vertex][1 ],
209+ gamma * m_shade[vertex][2 ],
210+ 1 .0f };
233211 }
234212
235- glBufferData (GL_ARRAY_BUFFER, static_cast <GLsizei>( sizeof (TexturedPoint) * m_vertices. size ()), m_vertices. data (), GL_DYNAMIC_DRAW );
236- glDrawArrays (GL_TRIANGLE_STRIP, 0 , static_cast <GLsizei>(m_vertices. size ()) );
213+ m_echoMesh. Update ( );
214+ m_echoMesh. Draw ( );
237215
238216 if (redraw == 0 )
239217 {
0 commit comments