[Mesa-dev] [PATCH 16/24] swrast: Add a readpixels fast-path based on memcpy and MapRenderbuffer.

Brian Paul brian.e.paul at gmail.com
Sat Oct 29 10:12:15 PDT 2011


On Fri, Oct 28, 2011 at 1:50 PM, Eric Anholt <eric at anholt.net> wrote:
> ---
>  src/mesa/swrast/s_readpix.c |   56 +++++++++++++++++++++++++++++++++++++++---
>  1 files changed, 52 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/swrast/s_readpix.c b/src/mesa/swrast/s_readpix.c
> index 91205fc..bf2fe9d 100644
> --- a/src/mesa/swrast/s_readpix.c
> +++ b/src/mesa/swrast/s_readpix.c
> @@ -297,6 +297,46 @@ fast_read_rgba_pixels( struct gl_context *ctx,
>    return GL_FALSE;
>  }
>
> +static GLboolean
> +fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
> +                             GLint x, GLint y,
> +                             GLsizei width, GLsizei height,
> +                             GLenum format, GLenum type,
> +                             GLvoid *pixels,
> +                             const struct gl_pixelstore_attrib *packing,
> +                             GLbitfield transferOps )
> +{
> +   struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
> +   GLubyte *dst, *map;
> +   int dstStride, stride, j;
> +
> +   if (!_mesa_format_matches_format_and_type(rb->Format, format, type))
> +      return GL_FALSE;
> +
> +   /* check for things we can't handle here */
> +   if (packing->SwapBytes ||
> +       packing->LsbFirst) {
> +      return GL_FALSE;
> +   }
> +
> +   dstStride = _mesa_image_row_stride(packing, width, format, type);
> +   dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
> +                                          format, type, 0, 0);
> +
> +   ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
> +                              &map, &stride);
> +
> +   for (j = 0; j < height; j++) {
> +      memcpy(dst, map, width * _mesa_get_format_bytes(rb->Format));

I think the call to _mesa_get_format_bytes() should be moved out of the loop.


> +      dst += dstStride;
> +      map += stride;
> +   }

-Brian


More information about the mesa-dev mailing list