[gtk+] gdkgl: Use one VBO for both position and uv attributes



commit 6ffba866a61dfcd854711c97e93dce641cb055b1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sat Nov 22 10:12:58 2014 -0800

    gdkgl: Use one VBO for both position and uv attributes

 gdk/gdkgl.c               |   28 +++++++---------------------
 gdk/gdkglcontextprivate.h |    1 -
 2 files changed, 7 insertions(+), 22 deletions(-)
---
diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c
index 78be223..b9563a6 100644
--- a/gdk/gdkgl.c
+++ b/gdk/gdkgl.c
@@ -223,9 +223,6 @@ gdk_gl_texture_quads (GdkGLContext *paint_context,
   if (paint_data->tmp_vertex_buffer == 0)
     glGenBuffers(1, &paint_data->tmp_vertex_buffer);
 
-  if (paint_data->tmp_uv_buffer == 0)
-    glGenBuffers(1, &paint_data->tmp_uv_buffer);
-
   if (texture_target == GL_TEXTURE_RECTANGLE_ARB)
     use_texture_rect_program (paint_data);
   else
@@ -239,32 +236,21 @@ gdk_gl_texture_quads (GdkGLContext *paint_context,
   glEnableVertexAttribArray (0);
   glEnableVertexAttribArray (1);
   glBindBuffer (GL_ARRAY_BUFFER, paint_data->tmp_vertex_buffer);
-  glVertexAttribPointer (program->position_location, 2, GL_FLOAT, GL_FALSE, 0, NULL);
-  glBindBuffer (GL_ARRAY_BUFFER, paint_data->tmp_uv_buffer);
-  glVertexAttribPointer (program->uv_location, 2, GL_FLOAT, GL_FALSE, 0, NULL);
+
+  glVertexAttribPointer (program->position_location, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, NULL);
+  glVertexAttribPointer (program->uv_location, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, NULL + 
sizeof(float) * 2);
 
   for (i = 0; i < n_quads; i++)
     {
       GdkTexturedQuad *quad = &quads[i];
       float vertex_buffer_data[] = {
-        (quad->x2 * 2) / w - 1, (quad->y1 * 2) / h - 1,
-        (quad->x2 * 2) / w - 1, (quad->y2 * 2) / h - 1,
-        (quad->x1 * 2) / w - 1, (quad->y2 * 2) / h - 1,
-        (quad->x1 * 2) / w - 1, (quad->y1 * 2) / h - 1,
-      };
-      float uv_buffer_data[] = {
-        quad->u2, quad->v1,
-        quad->u2, quad->v2,
-        quad->u1, quad->v2,
-        quad->u1, quad->v1,
+        (quad->x2 * 2) / w - 1, (quad->y1 * 2) / h - 1, quad->u2, quad->v1,
+        (quad->x2 * 2) / w - 1, (quad->y2 * 2) / h - 1, quad->u2, quad->v2,
+        (quad->x1 * 2) / w - 1, (quad->y2 * 2) / h - 1, quad->u1, quad->v2,
+        (quad->x1 * 2) / w - 1, (quad->y1 * 2) / h - 1, quad->u1, quad->v1,
       };
 
-      glBindBuffer (GL_ARRAY_BUFFER, paint_data->tmp_vertex_buffer);
       glBufferData (GL_ARRAY_BUFFER, sizeof(vertex_buffer_data), vertex_buffer_data, GL_STREAM_DRAW);
-
-      glBindBuffer (GL_ARRAY_BUFFER, paint_data->tmp_uv_buffer);
-      glBufferData (GL_ARRAY_BUFFER, sizeof(uv_buffer_data), uv_buffer_data, GL_STREAM_DRAW);
-
       glDrawArrays (GL_TRIANGLE_FAN, 0, 4);
     }
 
diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h
index ebe5e18..7f5f574 100644
--- a/gdk/gdkglcontextprivate.h
+++ b/gdk/gdkglcontextprivate.h
@@ -59,7 +59,6 @@ typedef struct {
   guint vertex_array_object;
   guint tmp_framebuffer;
   guint tmp_vertex_buffer;
-  guint tmp_uv_buffer;
 
   GdkGLContextProgram texture_2d_quad_program;
   GdkGLContextProgram texture_rect_quad_program;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]