[patch] gl - use direct mode for uploading gradient texture

"Henry (Yu) Song - SISA" <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <3955FA337689574EB32F94B12A7E6E9E0B4E5178@ex10mail>
Using pbo to upload gradient fails on ATI/fglrx driver (latest 12.2).  glGetError () after glTexSubImage2D() always returns GL_INVALID_OPERATION.  Not sure why, might be fglrx bug.  PBO works for other drivers.
To make it work in ATI/flgrlx, I have attached the following patch.  Figured that since gradient is small, non-pbo performance hit should be minimal.  If you think that cairo should keep pbo and let fglrx fails until they fix bugs.  I am fine with that.

Here is the patch

Author: Henry Song <[email protected]>
Date:   Mon Mar 19 17:21:27 2012 -0700

    use direct mode to upload gradient texture instead of pbo.

diff --git a/src/cairo-gl-gradient.c b/src/cairo-gl-gradient.c
index aad2773..0936b53 100644
--- a/src/cairo-gl-gradient.c
+++ b/src/cairo-gl-gradient.c
@@ -238,38 +238,14 @@ _cairo_gl_gradient_create (cairo_gl_context_t           *ctx,
     _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP);
     glBindTexture (ctx->tex_target, gradient->tex);
 
-    /* GL_PIXEL_UNPACK_BUFFER is only available in Desktop GL */
-    if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) {
-	dispatch->BindBuffer (GL_PIXEL_UNPACK_BUFFER, ctx->texture_load_pbo);
-	dispatch->BufferData (GL_PIXEL_UNPACK_BUFFER,
-			      tex_width * sizeof (uint32_t), 0, GL_STREAM_DRAW);
-	data = dispatch->MapBuffer (GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
+    data = _cairo_malloc_ab (tex_width, sizeof (uint32_t));
 
-	status = _cairo_gl_gradient_render (ctx, n_stops, stops, data, tex_width);
+    status = _cairo_gl_gradient_render (ctx, n_stops, stops, data, tex_width);
 
-	dispatch->UnmapBuffer (GL_PIXEL_UNPACK_BUFFER);
-
-	if (unlikely (status)) {
-	    dispatch->BindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);
-	    free (gradient);
-	    return status;
-	}
-
-	glTexImage2D (ctx->tex_target, 0, GL_RGBA8, tex_width, 1, 0,
-		      GL_BGRA, GL_UNSIGNED_BYTE, 0);
-
-	dispatch->BindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);
-    }
-    else {
-	data = _cairo_malloc_ab (tex_width, sizeof (uint32_t));
-
-	status = _cairo_gl_gradient_render (ctx, n_stops, stops, data, tex_width);
-
-	glTexImage2D (ctx->tex_target, 0, GL_BGRA, tex_width, 1, 0,
-		      GL_BGRA, GL_UNSIGNED_BYTE, data);
+    glTexImage2D (ctx->tex_target, 0, GL_RGBA, tex_width, 1, 0,
+   		  GL_BGRA, GL_UNSIGNED_BYTE, data);
 
 	free (data);
-    }
 
     /* we ignore errors here and just return an uncached gradient */
     if (unlikely (_cairo_cache_insert (&ctx->gradients, &gradient->cache_entry)))
--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.