@@ -56,7 +56,7 @@ struct LVGLWidget<BaseWidget>::PrivateData {
5656 #elif defined(DGL_OPENGL)
5757 GLuint textureId = 0 ;
5858 #ifdef DGL_USE_OPENGL3
59- struct { GLuint prog, pos, tex; } gl3 = {};
59+ struct { GLuint prog, obuf, vbuf, pos, tex; } gl3 = {};
6060 #endif
6161 #endif
6262
@@ -135,6 +135,13 @@ struct LVGLWidget<BaseWidget>::PrivateData {
135135
136136 #ifdef DGL_USE_OPENGL3
137137 int status;
138+ GLuint obuffer, vbuffer;
139+
140+ glGenBuffers (1 , &obuffer);
141+ DISTRHO_SAFE_ASSERT_RETURN (obuffer != 0 , gl3fail ());
142+
143+ glGenBuffers (1 , &vbuffer);
144+ DISTRHO_SAFE_ASSERT_RETURN (vbuffer != 0 , gl3fail ());
138145
139146 const GLuint fragment = glCreateShader (GL_FRAGMENT_SHADER);
140147 DISTRHO_SAFE_ASSERT_RETURN (fragment != 0 , gl3fail ());
@@ -161,7 +168,7 @@ struct LVGLWidget<BaseWidget>::PrivateData {
161168 #ifdef DGL_USE_GLES3
162169 " in vec2 vtex;"
163170 " out vec4 FragColor;"
164- " void main() { FragColor = texture2D (stex, vtex); }" ;
171+ " void main() { FragColor = texture (stex, vtex); }" ;
165172 #else
166173 " varying vec2 vtex;"
167174 " void main() { gl_FragColor = texture2D(stex, vtex); }" ;
@@ -202,6 +209,8 @@ struct LVGLWidget<BaseWidget>::PrivateData {
202209 DISTRHO_SAFE_ASSERT_RETURN (status != 0 , gl3fail ());
203210
204211 gl3.prog = program;
212+ gl3.obuf = obuffer;
213+ gl3.vbuf = vbuffer;
205214 gl3.pos = glGetAttribLocation (program, " pos" );
206215 gl3.tex = glGetAttribLocation (program, " tex" );
207216 #endif
@@ -535,19 +544,27 @@ void LVGLWidget<BaseWidget>::onDisplay()
535544 }
536545
537546 #ifdef DGL_USE_OPENGL3
538- const GLfloat vertices[] = { -1 .f , 1 .f , -1 .f , -1 .f , 1 .f , -1 .f , 1 .f , 1 .f };
539- glVertexAttribPointer (lvglData->gl3 .pos , 2 , GL_FLOAT, GL_FALSE, 0 , vertices);
547+ static constexpr const GLfloat vertices[] = {
548+ -1 .f , 1 .f , -1 .f , -1 .f , 1 .f , -1 .f , 1 .f , 1 .f ,
549+ 0 .f , 0 .f , 0 .f , 1 .f , 1 .f , 1 .f , 1 .f , 0 .f
550+ };
551+ glBindBuffer (GL_ARRAY_BUFFER, lvglData->gl3 .vbuf );
552+ glBufferData (GL_ARRAY_BUFFER, sizeof (vertices), vertices, GL_STATIC_DRAW);
540553 glEnableVertexAttribArray (lvglData->gl3 .pos );
541-
542- const GLfloat vtex[] = { 0 .f , 0 .f , 0 .f , 1 .f , 1 .f , 1 .f , 1 .f , 0 .f };
543- glVertexAttribPointer (lvglData->gl3 .tex , 2 , GL_FLOAT, GL_FALSE, 0 , vtex);
544554 glEnableVertexAttribArray (lvglData->gl3 .tex );
555+ glVertexAttribPointer (lvglData->gl3 .pos , 2 , GL_FLOAT, GL_FALSE, 0 , nullptr );
556+ glVertexAttribPointer (lvglData->gl3 .tex , 2 , GL_FLOAT, GL_FALSE, 0 , reinterpret_cast <void *>(sizeof (GLfloat) * 8 ));
557+
558+ static constexpr const GLubyte order[] = { 0 , 1 , 2 , 0 , 2 , 3 };
559+ glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, lvglData->gl3 .obuf );
560+ glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof (order), order, GL_STATIC_DRAW);
545561
546- const GLubyte order[] = { 0 , 1 , 2 , 0 , 2 , 3 };
547- glDrawElements (GL_TRIANGLES, ARRAY_SIZE (order), GL_UNSIGNED_BYTE, order);
562+ glDrawElements (GL_TRIANGLES, ARRAY_SIZE (order), GL_UNSIGNED_BYTE, nullptr );
548563
564+ glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0 );
549565 glDisableVertexAttribArray (lvglData->gl3 .tex );
550566 glDisableVertexAttribArray (lvglData->gl3 .pos );
567+ glBindBuffer (GL_ARRAY_BUFFER, 0 );
551568 #else
552569 glBegin (GL_QUADS);
553570 {
0 commit comments