[cogl/cogl-1.10] buffer: Use GL_STREAM_DRAW on GLES2



commit 24455f89bbda1dd58e8833ef7b33ffb27d722243
Author: Neil Roberts <neil linux intel com>
Date:   Wed May 2 10:08:36 2012 +0100

    buffer: Use GL_STREAM_DRAW on GLES2
    
    The function to convert the CoglBufferUpdateHint to a GL enum was
    previously ifdef'd to only use GL_STREAM_DRAW when Cogl is compiled
    with big GL support. One problem with this is that it would end up
    trying to use it on GLES1 if support for both is compiled. The other
    problem is that GLES2 seems to actually support GL_STREAM_DRAW so we
    might as well use it in that case.
    
    This patch also changes it so that if the hint is stream with GLES1
    then it will default to GL_DYNAMIC_DRAW instead of GL_STATIC_DRAW
    because I think that is closer to the meaning of the stream hint.
    
    Reviewed-by: Robert Bragg <robert linux intel com>
    
    (cherry picked from commit 9e997476a7f9271bc000abdc82b1e343b92afb4c)

 cogl/cogl-buffer.c |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/cogl/cogl-buffer.c b/cogl/cogl-buffer.c
index f5a0fc5..4f95ff1 100644
--- a/cogl/cogl-buffer.c
+++ b/cogl/cogl-buffer.c
@@ -147,21 +147,27 @@ _cogl_buffer_bind_no_create (CoglBuffer *buffer,
 }
 
 static GLenum
-_cogl_buffer_hints_to_gl_enum (CoglBufferUsageHint  usage_hint,
-                               CoglBufferUpdateHint update_hint)
+_cogl_buffer_hints_to_gl_enum (CoglBuffer *buffer)
 {
-  /* usage hint is always TEXTURE for now */
-  if (update_hint == COGL_BUFFER_UPDATE_HINT_STATIC)
-    return GL_STATIC_DRAW;
-  if (update_hint == COGL_BUFFER_UPDATE_HINT_DYNAMIC)
-    return GL_DYNAMIC_DRAW;
-  /* OpenGL ES 1.1 and 2 only know about STATIC_DRAW and DYNAMIC_DRAW */
-#ifdef HAVE_COGL_GL
-  if (update_hint == COGL_BUFFER_UPDATE_HINT_STREAM)
-    return GL_STREAM_DRAW;
+  /* usage hint is always DRAW for now */
+  switch (buffer->update_hint)
+    {
+    case COGL_BUFFER_UPDATE_HINT_STATIC:
+      return GL_STATIC_DRAW;
+    case COGL_BUFFER_UPDATE_HINT_DYNAMIC:
+      return GL_DYNAMIC_DRAW;
+
+    case COGL_BUFFER_UPDATE_HINT_STREAM:
+      /* OpenGL ES 1.1 only knows about STATIC_DRAW and DYNAMIC_DRAW */
+#if defined(HAVE_COGL_GL) || defined(HAVE_COGL_GLES2)
+      if (buffer->context->driver != COGL_DRIVER_GLES1)
+        return GL_STREAM_DRAW;
+#else
+      return GL_DYNAMIC_DRAW;
 #endif
+    }
 
-  return GL_STATIC_DRAW;
+  g_assert_not_reached ();
 }
 
 static void
@@ -173,8 +179,7 @@ bo_recreate_store (CoglBuffer *buffer)
   /* This assumes the buffer is already bound */
 
   gl_target = convert_bind_target_to_gl_target (buffer->last_target);
-  gl_enum = _cogl_buffer_hints_to_gl_enum (buffer->usage_hint,
-                                           buffer->update_hint);
+  gl_enum = _cogl_buffer_hints_to_gl_enum (buffer);
 
   GE( buffer->context, glBufferData (gl_target,
                                      buffer->size,



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