From e72747cbb879b23b26a1f89433a7b7c202481c4f Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 24 Aug 2009 12:50:57 +0100 Subject: [PATCH] [cogl-texture] Set GL_PACK_ROW_LENGTH when downloading texture data Otherwise the rowstride passed in from an application is not used correctly so you can not download to an area with a much larger rowstride. --- gl/cogl-texture.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gl/cogl-texture.c b/gl/cogl-texture.c index 7721ea2a8..20000ec35 100644 --- a/gl/cogl-texture.c +++ b/gl/cogl-texture.c @@ -184,8 +184,16 @@ prep_for_gl_pixels_upload (gint pixels_rowstride, } static void -prep_for_gl_pixels_download (gint pixels_rowstride) +prep_for_gl_pixels_download (gint pixels_rowstride, + gint pixels_src_x, + gint pixels_src_y, + gint pixels_bpp) { + GE( glPixelStorei (GL_PACK_ROW_LENGTH, pixels_rowstride / pixels_bpp) ); + + GE( glPixelStorei (GL_PACK_SKIP_PIXELS, pixels_src_x) ); + GE( glPixelStorei (GL_PACK_SKIP_ROWS, pixels_src_y) ); + if (!(pixels_rowstride & 0x7)) GE( glPixelStorei (GL_PACK_ALIGNMENT, 8) ); else if (!(pixels_rowstride & 0x3)) @@ -404,7 +412,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex, slice_bmp.height); /* Setup gl alignment to 0,0 top-left corner */ - prep_for_gl_pixels_download (slice_bmp.rowstride); + prep_for_gl_pixels_download (slice_bmp.rowstride, 0, 0, bpp); /* Download slice image data into temp bmp */ GE( glBindTexture (tex->gl_target, gl_handle) ); @@ -432,7 +440,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex, + x_span->start * bpp + y_span->start * target_bmp->rowstride; - prep_for_gl_pixels_download (target_bmp->rowstride); + prep_for_gl_pixels_download (target_bmp->rowstride, 0, 0, bpp); /* Download slice image data */ GE( glBindTexture (tex->gl_target, gl_handle) );