Reviewed-by: Robert Bragg <<a href="mailto:robert@linux.intel.com">robert@linux.intel.com</a>><br><br><div class="gmail_quote">On Thu, Mar 22, 2012 at 5:32 PM, Neil Roberts <span dir="ltr"><<a href="mailto:neil@linux.intel.com">neil@linux.intel.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">This extension lets you upload texture data from a subregion of a<br>
buffer by passing GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_PIXELS and<br>
GL_UNPACK_SKIP_ROWS to glPixelStore. When this extension is available<br>
the GLES texture driver will now avoid making a copy of the bitmap<br>
when a subregion is used.<br>
<br>
Note that Mesa doesn't currently advertise this extension but I've<br>
made a patch to propose it:<br>
<br>
<a href="http://lists.freedesktop.org/archives/mesa-dev/2012-March/020191.html" target="_blank">http://lists.freedesktop.org/archives/mesa-dev/2012-March/020191.html</a><br>
---<br>
cogl/cogl-internal.h | 3 +-<br>
cogl/driver/gles/cogl-gles.c | 3 +<br>
cogl/driver/gles/cogl-texture-driver-gles.c | 60 +++++++++++++++++++++++----<br>
</div> 3 files changed, 56 insertions(+), 10 deletions(-)<br>
<div class="im"><br>
diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h<br>
index 4f53cc3..284fc97 100644<br>
--- a/cogl/cogl-internal.h<br>
+++ b/cogl/cogl-internal.h<br>
@@ -101,7 +101,8 @@ typedef enum<br>
COGL_PRIVATE_FEATURE_VBOS = 1L<<6,<br>
COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL = 1L<<7,<br>
COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL = 1L<<8,<br>
- COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888 = 1L<<9<br>
+ COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888 = 1L<<9,<br>
+ COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE = 1L<<10<br>
} CoglPrivateFeatureFlags;<br>
<br>
/* Sometimes when evaluating pipelines, either during comparisons or<br>
diff --git a/cogl/driver/gles/cogl-gles.c b/cogl/driver/gles/cogl-gles.c<br>
</div>index 102a19f..d7503b7 100644<br>
--- a/cogl/driver/gles/cogl-gles.c<br>
+++ b/cogl/driver/gles/cogl-gles.c<br>
@@ -293,6 +293,9 @@ _cogl_driver_update_features (CoglContext *context,<br>
<div class="im"> if (_cogl_check_extension ("GL_EXT_texture_format_BGRA8888", gl_extensions))<br>
private_flags |= COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_BGRA8888;<br>
<br>
+ if (_cogl_check_extension ("GL_EXT_unpack_subimage", gl_extensions))<br>
+ private_flags |= COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE;<br>
+<br>
/* Cache features */<br>
context->private_feature_flags |= private_flags;<br>
context->feature_flags |= flags;<br>
diff --git a/cogl/driver/gles/cogl-texture-driver-gles.c b/cogl/driver/gles/cogl-texture-driver-gles.c<br>
</div>index f2690da..e6a67d6 100644<br>
<div class="im">--- a/cogl/driver/gles/cogl-texture-driver-gles.c<br>
+++ b/cogl/driver/gles/cogl-texture-driver-gles.c<br>
@@ -52,6 +52,18 @@<br>
#define GL_MAX_3D_TEXTURE_SIZE_OES 0x8073<br>
#endif<br>
<br>
+/* This extension isn't available for GLES 1.1 so these won't be<br>
+ defined */<br>
+#ifndef GL_UNPACK_ROW_LENGTH<br>
+#define GL_UNPACK_ROW_LENGTH 0x0CF2<br>
+#endif<br>
+#ifndef GL_UNPACK_SKIP_ROWS<br>
+#define GL_UNPACK_SKIP_ROWS 0x0CF3<br>
+#endif<br>
+#ifndef GL_UNPACK_SKIP_PIXELS<br>
+#define GL_UNPACK_SKIP_PIXELS 0x0CF4<br>
+#endif<br>
+<br>
static void<br>
</div> _cogl_texture_driver_gen (CoglContext *ctx,<br>
GLenum gl_target,<br>
@@ -83,11 +95,38 @@ _cogl_texture_driver_gen (CoglContext *ctx,<br>
}<br>
<br>
static void<br>
-_cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *context,<br>
+prep_gl_for_pixels_upload_full (CoglContext *ctx,<br>
+ int pixels_rowstride,<br>
<div class="im">+ int pixels_src_x,<br>
+ int pixels_src_y,<br>
+ int pixels_bpp)<br>
+{<br>
</div><div class="im">+ if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE))<br>
+ {<br>
+ GE( ctx, glPixelStorei (GL_UNPACK_ROW_LENGTH,<br>
+ pixels_rowstride / pixels_bpp) );<br>
+<br>
+ GE( ctx, glPixelStorei (GL_UNPACK_SKIP_PIXELS, pixels_src_x) );<br>
+ GE( ctx, glPixelStorei (GL_UNPACK_SKIP_ROWS, pixels_src_y) );<br>
+ }<br>
+ else<br>
+ {<br>
+ g_assert (pixels_src_x == 0);<br>
+ g_assert (pixels_src_y == 0);<br>
+ }<br>
+<br>
+ _cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);<br>
+}<br>
+<br>
+static void<br>
</div>+_cogl_texture_driver_prep_gl_for_pixels_upload (CoglContext *ctx,<br>
<div class="im"> int pixels_rowstride,<br>
int pixels_bpp)<br>
{<br>
- _cogl_texture_prep_gl_alignment_for_pixels_upload (pixels_rowstride);<br>
</div>+ prep_gl_for_pixels_upload_full (ctx,<br>
+ pixels_rowstride,<br>
<div class="im">+ 0, 0, /* src_x/y */<br>
+ pixels_bpp);<br>
}<br>
<br>
static void<br>
</div>@@ -108,7 +147,8 @@ prepare_bitmap_alignment_for_upload (CoglContext *ctx,<br>
<div class="im"> int width = cogl_bitmap_get_width (src_bmp);<br>
int alignment = 1;<br>
<br>
- if (src_rowstride == 0)<br>
</div><div class="im">+ if ((ctx->private_feature_flags & COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE) ||<br>
+ src_rowstride == 0)<br>
return cogl_object_ref (src_bmp);<br>
<br>
/* Work out the alignment of the source rowstride */<br>
</div>@@ -146,11 +186,13 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,<br>
CoglBitmap *slice_bmp;<br>
int rowstride;<br>
<div class="im"><br>
- /* If we are copying a sub region of the source bitmap then we need<br>
- to copy it because GLES does not support GL_UNPACK_ROW_LENGTH */<br>
- if (src_x != 0 || src_y != 0 ||<br>
- width != cogl_bitmap_get_width (source_bmp) ||<br>
- height != cogl_bitmap_get_height (source_bmp))<br>
+ /* If we have the GL_EXT_unpack_subimage extension then we can<br>
+ upload from subregions directly. Otherwise we may need to copy<br>
+ the bitmap */<br>
+ if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_UNPACK_SUBIMAGE) &&<br>
+ (src_x != 0 || src_y != 0 ||<br>
+ width != cogl_bitmap_get_width (source_bmp) ||<br>
+ height != cogl_bitmap_get_height (source_bmp)))<br>
{<br>
slice_bmp =<br>
_cogl_bitmap_new_with_malloc_buffer (ctx,<br>
</div>@@ -168,7 +210,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,<br>
<div class="im"> rowstride = cogl_bitmap_get_rowstride (slice_bmp);<br>
<br>
/* Setup gl alignment to match rowstride and top-left corner */<br>
</div>- _cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);<br>
+ prep_gl_for_pixels_upload_full (ctx, rowstride, src_x, src_y, bpp);<br>
<div class="HOEnZb"><div class="h5"><br>
data = _cogl_bitmap_bind (slice_bmp, COGL_BUFFER_ACCESS_READ, 0);<br>
<br>
--<br>
1.7.3.16.g9464b<br>
<br>
_______________________________________________<br>
Cogl mailing list<br>
<a href="mailto:Cogl@lists.freedesktop.org">Cogl@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/cogl" target="_blank">http://lists.freedesktop.org/mailman/listinfo/cogl</a><br>
</div></div></blockquote></div><br>