From 21b9b8b74ec0975296d22493254875c0deb7b6da Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 13 Aug 2007 13:56:54 -0600 Subject: fill in the get_tile() function so ReadPixels can work --- src/mesa/pipe/i915simple/i915_surface.c | 39 ++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/mesa/pipe') diff --git a/src/mesa/pipe/i915simple/i915_surface.c b/src/mesa/pipe/i915simple/i915_surface.c index a67784b70c..cc0a87012a 100644 --- a/src/mesa/pipe/i915simple/i915_surface.c +++ b/src/mesa/pipe/i915simple/i915_surface.c @@ -29,6 +29,7 @@ #include "i915_state.h" #include "pipe/p_defines.h" #include "main/imports.h" +#include "main/macros.h" struct i915_surface @@ -38,13 +39,45 @@ struct i915_surface }; +/** + * Note: this is exactly like a8r8g8b8_get_tile() in sp_surface.c + * Share it someday. + */ static void i915_get_tile(struct pipe_surface *ps, GLuint x, GLuint y, GLuint w, GLuint h, GLfloat *p) { - /* any need to get tiles from i915 surfaces? */ - /* Yes, for glReadPixels (for a while at least). */ - assert(0); + const GLuint *src + = ((const GLuint *) (ps->region->map + ps->offset)) + + y * ps->region->pitch + x; + GLuint i, j; + GLuint w0 = w; + + assert(ps->format == PIPE_FORMAT_U_A8_R8_G8_B8); + +#if 0 + assert(x + w <= ps->width); + assert(y + h <= ps->height); +#else + /* temp clipping hack */ + if (x + w > ps->width) + w = ps->width - x; + if (y + h > ps->height) + h = ps->height -y; +#endif + for (i = 0; i < h; i++) { + GLfloat *pRow = p; + for (j = 0; j < w; j++) { + const GLuint pixel = src[j]; + pRow[0] = UBYTE_TO_FLOAT((pixel >> 16) & 0xff); + pRow[1] = UBYTE_TO_FLOAT((pixel >> 8) & 0xff); + pRow[2] = UBYTE_TO_FLOAT((pixel >> 0) & 0xff); + pRow[3] = UBYTE_TO_FLOAT((pixel >> 24) & 0xff); + pRow += 4; + } + src += ps->region->pitch; + p += w0 * 4; + } } -- cgit v1.2.3