[Mesa-dev] [PATCH 10/12] geom-outlining-150: Use a vbo.

Fabian Bieler fabianbieler at fastmail.fm
Wed Feb 5 13:07:50 PST 2014


Use a vbo for vertex data instead of client-side arrays.
Also bind a vertex array object.

This is necessary for the switch to a core profile context.

Signed-off-by: Fabian Bieler <fabianbieler at fastmail.fm>
---
 src/glsl/geom-outlining-150.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/glsl/geom-outlining-150.c b/src/glsl/geom-outlining-150.c
index 5c2b3c9..0bc20f0 100644
--- a/src/glsl/geom-outlining-150.c
+++ b/src/glsl/geom-outlining-150.c
@@ -23,6 +23,7 @@
 static GLint WinWidth = 500, WinHeight = 500;
 static GLint Win = 0;
 static GLuint VertShader, GeomShader, FragShader, Program;
+static GLuint vao, vbo;
 static GLboolean Anim = GL_TRUE;
 static int uViewportSize = -1, uModelViewProj = -1, uColor = -1;
 
@@ -112,11 +113,6 @@ mat_multiply(GLfloat product[16], const GLfloat a[16], const GLfloat b[16])
 static void
 Redisplay(void)
 {
-   static const GLfloat verts[3][2] = {
-      { -1, -1 },
-      {  1, -1 },
-      {  0,  1 }
-   };
    GLfloat rot[4][4];
    GLfloat trans[16], mvp[16];
 
@@ -131,8 +127,6 @@ Redisplay(void)
    glUniformMatrix4fv(uModelViewProj, 1, GL_FALSE, (float *) mvp);
 
    /* Draw */
-   glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, verts);
-   glEnableVertexAttribArray(0);
    glDrawArrays(GL_TRIANGLES, 0, 3);
 
    glutSwapBuffers();
@@ -217,6 +211,8 @@ CleanUp(void)
    glDeleteShader(VertShader);
    glDeleteShader(GeomShader);
    glDeleteProgram(Program);
+   glDeleteVertexArrays(1, &vao);
+   glDeleteBuffers(1, &vbo);
    glutDestroyWindow(Win);
 }
 
@@ -304,6 +300,11 @@ Init(void)
       "   float m = min(d0, min(d1, d2)); \n"
       "   FragColor = Color * smoothstep(0.0, LINE_WIDTH, m); \n"
       "} \n";
+   static const GLfloat verts[3][2] = {
+      { -1, -1 },
+      {  1, -1 },
+      {  0,  1 }
+   };
 
    if (!ShadersSupported())
       exit(1);
@@ -351,6 +352,16 @@ Init(void)
 
    glUniform4fv(uColor, 1, Orange);
 
+   glGenBuffers(1, &vbo);
+   glBindBuffer(GL_ARRAY_BUFFER, vbo);
+   glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
+
+   glGenVertexArrays(1, &vao);
+   glBindVertexArray(vao);
+
+   glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
+   glEnableVertexAttribArray(0);
+
    glClearColor(0.3f, 0.3f, 0.3f, 0.0f);
    glEnable(GL_DEPTH_TEST);
 
-- 
1.8.3.2



More information about the mesa-dev mailing list