st/mesa: remove dependencies on code in st_cb_readpixels.c
[mesa.git] / src / mesa / state_tracker / st_cb_readpixels.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 /**
30 * glReadPixels interface to pipe
31 *
32 * \author Brian Paul
33 */
34
35
36 #include "main/imports.h"
37 #include "main/bufferobj.h"
38 #include "main/context.h"
39 #include "main/image.h"
40 #include "main/pack.h"
41 #include "main/pbo.h"
42
43 #include "pipe/p_context.h"
44 #include "pipe/p_defines.h"
45 #include "util/u_format.h"
46 #include "util/u_inlines.h"
47 #include "util/u_tile.h"
48
49 #include "st_debug.h"
50 #include "st_context.h"
51 #include "st_atom.h"
52 #include "st_cb_bitmap.h"
53 #include "st_cb_readpixels.h"
54 #include "st_cb_fbo.h"
55
56 /**
57 * Special case for reading stencil buffer.
58 * For color/depth we use get_tile(). For stencil, map the stencil buffer.
59 */
60 void
61 st_read_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
62 GLsizei width, GLsizei height,
63 GLenum format, GLenum type,
64 const struct gl_pixelstore_attrib *packing,
65 GLvoid *pixels)
66 {
67 struct gl_framebuffer *fb = ctx->ReadBuffer;
68 struct pipe_context *pipe = st_context(ctx)->pipe;
69 struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer);
70 struct pipe_transfer *pt;
71 ubyte *stmap;
72 GLint j;
73
74 if (strb->Base.Wrapped) {
75 strb = st_renderbuffer(strb->Base.Wrapped);
76 }
77
78 if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
79 y = ctx->DrawBuffer->Height - y - height;
80 }
81
82 /* Create a read transfer from the renderbuffer's texture */
83
84 pt = pipe_get_transfer(pipe, strb->texture,
85 strb->rtt_level,
86 strb->rtt_face + strb->rtt_slice,
87 PIPE_TRANSFER_READ,
88 x, y, width, height);
89
90 /* map the stencil buffer */
91 stmap = pipe_transfer_map(pipe, pt);
92
93 /* width should never be > MAX_WIDTH since we did clipping earlier */
94 ASSERT(width <= MAX_WIDTH);
95
96 /* process image row by row */
97 for (j = 0; j < height; j++) {
98 GLvoid *dest;
99 GLubyte sValues[MAX_WIDTH];
100 GLfloat zValues[MAX_WIDTH];
101 GLint srcY;
102
103 if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) {
104 srcY = height - j - 1;
105 }
106 else {
107 srcY = j;
108 }
109
110 /* get stencil (and Z) values */
111 switch (pt->resource->format) {
112 case PIPE_FORMAT_S8_UINT:
113 {
114 const ubyte *src = stmap + srcY * pt->stride;
115 memcpy(sValues, src, width);
116 }
117 break;
118 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
119 if (format == GL_DEPTH_STENCIL) {
120 const uint *src = (uint *) (stmap + srcY * pt->stride);
121 const GLfloat scale = 1.0f / (0xffffff);
122 GLint k;
123 for (k = 0; k < width; k++) {
124 sValues[k] = src[k] >> 24;
125 zValues[k] = (src[k] & 0xffffff) * scale;
126 }
127 }
128 else {
129 const uint *src = (uint *) (stmap + srcY * pt->stride);
130 GLint k;
131 for (k = 0; k < width; k++) {
132 sValues[k] = src[k] >> 24;
133 }
134 }
135 break;
136 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
137 if (format == GL_DEPTH_STENCIL) {
138 const uint *src = (uint *) (stmap + srcY * pt->stride);
139 const GLfloat scale = 1.0f / (0xffffff);
140 GLint k;
141 for (k = 0; k < width; k++) {
142 sValues[k] = src[k] & 0xff;
143 zValues[k] = (src[k] >> 8) * scale;
144 }
145 }
146 else {
147 const uint *src = (uint *) (stmap + srcY * pt->stride);
148 GLint k;
149 for (k = 0; k < width; k++) {
150 sValues[k] = src[k] & 0xff;
151 }
152 }
153 break;
154 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
155 if (format == GL_DEPTH_STENCIL) {
156 const uint *src = (uint *) (stmap + srcY * pt->stride);
157 const GLfloat *srcf = (const GLfloat*)src;
158 GLint k;
159 for (k = 0; k < width; k++) {
160 zValues[k] = srcf[k*2];
161 sValues[k] = src[k*2+1] & 0xff;
162 }
163 }
164 else {
165 const uint *src = (uint *) (stmap + srcY * pt->stride);
166 GLint k;
167 for (k = 0; k < width; k++) {
168 sValues[k] = src[k*2+1] & 0xff;
169 }
170 }
171 break;
172 default:
173 assert(0);
174 }
175
176 /* store */
177 dest = _mesa_image_address2d(packing, pixels, width, height,
178 format, type, j, 0);
179 if (format == GL_DEPTH_STENCIL) {
180 _mesa_pack_depth_stencil_span(ctx, width, type, dest,
181 zValues, sValues, packing);
182 }
183 else {
184 _mesa_pack_stencil_span(ctx, width, type, dest, sValues, packing);
185 }
186 }
187
188 /* unmap the stencil buffer */
189 pipe_transfer_unmap(pipe, pt);
190 pipe->transfer_destroy(pipe, pt);
191 }
192
193
194 /**
195 * Return renderbuffer to use for reading color pixels for glRead/CopyPixel
196 * commands.
197 */
198 static struct st_renderbuffer *
199 st_get_color_read_renderbuffer(struct gl_context *ctx)
200 {
201 struct gl_framebuffer *fb = ctx->ReadBuffer;
202 struct st_renderbuffer *strb =
203 st_renderbuffer(fb->_ColorReadBuffer);
204
205 return strb;
206 }
207
208
209 /**
210 * Try to do glReadPixels in a fast manner for common cases.
211 * \return GL_TRUE for success, GL_FALSE for failure
212 */
213 static GLboolean
214 st_fast_readpixels(struct gl_context *ctx, struct st_renderbuffer *strb,
215 GLint x, GLint y, GLsizei width, GLsizei height,
216 GLenum format, GLenum type,
217 const struct gl_pixelstore_attrib *pack,
218 GLvoid *dest)
219 {
220 GLubyte alphaORoperand;
221 enum combination {
222 A8R8G8B8_UNORM_TO_RGBA_UBYTE,
223 A8R8G8B8_UNORM_TO_RGB_UBYTE,
224 A8R8G8B8_UNORM_TO_BGRA_UINT,
225 A8R8G8B8_UNORM_TO_RGBA_UINT
226 } combo;
227
228 if (ctx->_ImageTransferState)
229 return GL_FALSE;
230
231 if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM) {
232 alphaORoperand = 0;
233 }
234 else if (strb->format == PIPE_FORMAT_B8G8R8X8_UNORM ) {
235 alphaORoperand = 0xff;
236 }
237 else {
238 return GL_FALSE;
239 }
240
241 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
242 combo = A8R8G8B8_UNORM_TO_RGBA_UBYTE;
243 }
244 else if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
245 combo = A8R8G8B8_UNORM_TO_RGB_UBYTE;
246 }
247 else if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) {
248 combo = A8R8G8B8_UNORM_TO_BGRA_UINT;
249 }
250 else if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8) {
251 combo = A8R8G8B8_UNORM_TO_RGBA_UINT;
252 }
253 else {
254 return GL_FALSE;
255 }
256
257 /*printf("st_fast_readpixels combo %d\n", (GLint) combo);*/
258
259 {
260 struct pipe_context *pipe = st_context(ctx)->pipe;
261 struct pipe_transfer *trans;
262 const GLubyte *map;
263 GLubyte *dst;
264 GLint row, col, dy, dstStride;
265
266 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
267 /* convert GL Y to Gallium Y */
268 y = strb->texture->height0 - y - height;
269 }
270
271 trans = pipe_get_transfer(pipe, strb->texture,
272 strb->rtt_level,
273 strb->rtt_face + strb->rtt_slice,
274 PIPE_TRANSFER_READ,
275 x, y, width, height);
276 if (!trans) {
277 return GL_FALSE;
278 }
279
280 map = pipe_transfer_map(pipe, trans);
281 if (!map) {
282 pipe->transfer_destroy(pipe, trans);
283 return GL_FALSE;
284 }
285
286 /* We always write to the user/dest buffer from low addr to high addr
287 * but the read order depends on renderbuffer orientation
288 */
289 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
290 /* read source rows from bottom to top */
291 y = height - 1;
292 dy = -1;
293 }
294 else {
295 /* read source rows from top to bottom */
296 y = 0;
297 dy = 1;
298 }
299
300 dst = _mesa_image_address2d(pack, dest, width, height,
301 format, type, 0, 0);
302 dstStride = _mesa_image_row_stride(pack, width, format, type);
303
304 switch (combo) {
305 case A8R8G8B8_UNORM_TO_RGBA_UBYTE:
306 for (row = 0; row < height; row++) {
307 const GLubyte *src = map + y * trans->stride;
308 for (col = 0; col < width; col++) {
309 GLuint pixel = ((GLuint *) src)[col];
310 dst[col*4+0] = (pixel >> 16) & 0xff;
311 dst[col*4+1] = (pixel >> 8) & 0xff;
312 dst[col*4+2] = (pixel >> 0) & 0xff;
313 dst[col*4+3] = ((pixel >> 24) & 0xff) | alphaORoperand;
314 }
315 dst += dstStride;
316 y += dy;
317 }
318 break;
319 case A8R8G8B8_UNORM_TO_RGB_UBYTE:
320 for (row = 0; row < height; row++) {
321 const GLubyte *src = map + y * trans->stride;
322 for (col = 0; col < width; col++) {
323 GLuint pixel = ((GLuint *) src)[col];
324 dst[col*3+0] = (pixel >> 16) & 0xff;
325 dst[col*3+1] = (pixel >> 8) & 0xff;
326 dst[col*3+2] = (pixel >> 0) & 0xff;
327 }
328 dst += dstStride;
329 y += dy;
330 }
331 break;
332 case A8R8G8B8_UNORM_TO_BGRA_UINT:
333 for (row = 0; row < height; row++) {
334 const GLubyte *src = map + y * trans->stride;
335 memcpy(dst, src, 4 * width);
336 if (alphaORoperand) {
337 assert(alphaORoperand == 0xff);
338 for (col = 0; col < width; col++) {
339 dst[col*4+3] = 0xff;
340 }
341 }
342 dst += dstStride;
343 y += dy;
344 }
345 break;
346 case A8R8G8B8_UNORM_TO_RGBA_UINT:
347 for (row = 0; row < height; row++) {
348 const GLubyte *src = map + y * trans->stride;
349 for (col = 0; col < width; col++) {
350 GLuint pixel = ((GLuint *) src)[col];
351 dst[col*4+0] = ((pixel >> 24) & 0xff) | alphaORoperand;
352 dst[col*4+1] = (pixel >> 0) & 0xff;
353 dst[col*4+2] = (pixel >> 8) & 0xff;
354 dst[col*4+3] = (pixel >> 16) & 0xff;
355 }
356 dst += dstStride;
357 y += dy;
358 }
359 break;
360 default:
361 ; /* nothing */
362 }
363
364 pipe_transfer_unmap(pipe, trans);
365 pipe->transfer_destroy(pipe, trans);
366 }
367
368 return GL_TRUE;
369 }
370
371
372 /**
373 * Do glReadPixels by getting rows from the framebuffer transfer with
374 * get_tile(). Convert to requested format/type with Mesa image routines.
375 * Image transfer ops are done in software too.
376 */
377 static void
378 st_readpixels(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height,
379 GLenum format, GLenum type,
380 const struct gl_pixelstore_attrib *pack,
381 GLvoid *dest)
382 {
383 struct st_context *st = st_context(ctx);
384 struct pipe_context *pipe = st->pipe;
385 GLfloat (*temp)[4];
386 GLbitfield transferOps = ctx->_ImageTransferState;
387 GLsizei i, j;
388 GLint yStep, dfStride;
389 GLfloat *df;
390 GLuint *dui;
391 GLint *di;
392 struct st_renderbuffer *strb;
393 struct gl_pixelstore_attrib clippedPacking = *pack;
394 struct pipe_transfer *trans;
395 enum pipe_format pformat;
396
397 assert(ctx->ReadBuffer->Width > 0);
398
399 st_validate_state(st);
400
401 /* Do all needed clipping here, so that we can forget about it later */
402 if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
403 /* The ReadPixels transfer is totally outside the window bounds */
404 return;
405 }
406
407 st_flush_bitmap_cache(st);
408
409 dest = _mesa_map_pbo_dest(ctx, &clippedPacking, dest);
410 if (!dest)
411 return;
412
413 if (format == GL_STENCIL_INDEX ||
414 format == GL_DEPTH_STENCIL) {
415 st_read_stencil_pixels(ctx, x, y, width, height,
416 format, type, pack, dest);
417 return;
418 }
419 else if (format == GL_DEPTH_COMPONENT) {
420 strb = st_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
421 if (strb->Base.Wrapped) {
422 strb = st_renderbuffer(strb->Base.Wrapped);
423 }
424 }
425 else {
426 /* Read color buffer */
427 strb = st_get_color_read_renderbuffer(ctx);
428 }
429
430 if (!strb)
431 return;
432
433 /* try a fast-path readpixels before anything else */
434 if (st_fast_readpixels(ctx, strb, x, y, width, height,
435 format, type, pack, dest)) {
436 /* success! */
437 _mesa_unmap_pbo_dest(ctx, &clippedPacking);
438 return;
439 }
440
441 /* allocate temp pixel row buffer */
442 temp = (GLfloat (*)[4]) malloc(4 * width * sizeof(GLfloat));
443 if (!temp) {
444 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
445 return;
446 }
447
448 if(ctx->Color._ClampReadColor)
449 transferOps |= IMAGE_CLAMP_BIT;
450
451 if (format == GL_RGBA && type == GL_FLOAT && !transferOps) {
452 /* write tile(row) directly into user's buffer */
453 df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width,
454 height, format, type, 0, 0);
455 dfStride = width * 4;
456 }
457 else {
458 /* write tile(row) into temp row buffer */
459 df = (GLfloat *)temp;
460 dfStride = 0;
461 }
462
463 dui = (GLuint *)df;
464 di = (GLint *)df;
465
466 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
467 /* convert GL Y to Gallium Y */
468 y = strb->Base.Height - y - height;
469 }
470
471 /* Create a read transfer from the renderbuffer's texture */
472 trans = pipe_get_transfer(pipe, strb->texture,
473 strb->rtt_level, /* level */
474 strb->rtt_face + strb->rtt_slice, /* layer */
475 PIPE_TRANSFER_READ,
476 x, y, width, height);
477
478 /* determine bottom-to-top vs. top-to-bottom order */
479 if (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP) {
480 y = height - 1;
481 yStep = -1;
482 }
483 else {
484 y = 0;
485 yStep = 1;
486 }
487
488 /* possibly convert sRGB format to linear RGB format */
489 pformat = util_format_linear(trans->resource->format);
490
491 if (ST_DEBUG & DEBUG_FALLBACK)
492 debug_printf("%s: fallback processing\n", __FUNCTION__);
493
494 /*
495 * Copy pixels from pipe_transfer to user memory
496 */
497 {
498 /* dest of first pixel in client memory */
499 GLubyte *dst = _mesa_image_address2d(&clippedPacking, dest, width,
500 height, format, type, 0, 0);
501 /* dest row stride */
502 const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width,
503 format, type);
504
505 if (pformat == PIPE_FORMAT_Z24_UNORM_S8_UINT ||
506 pformat == PIPE_FORMAT_Z24X8_UNORM) {
507 if (format == GL_DEPTH_COMPONENT) {
508 for (i = 0; i < height; i++) {
509 GLuint ztemp[MAX_WIDTH];
510 GLfloat zfloat[MAX_WIDTH];
511 const double scale = 1.0 / ((1 << 24) - 1);
512 pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
513 y += yStep;
514 for (j = 0; j < width; j++) {
515 zfloat[j] = (float) (scale * (ztemp[j] & 0xffffff));
516 }
517 _mesa_pack_depth_span(ctx, width, dst, type,
518 zfloat, &clippedPacking);
519 dst += dstStride;
520 }
521 }
522 else {
523 /* XXX: unreachable code -- should be before st_read_stencil_pixels */
524 assert(format == GL_DEPTH_STENCIL_EXT);
525 for (i = 0; i < height; i++) {
526 GLuint *zshort = (GLuint *)dst;
527 pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
528 y += yStep;
529 /* Reverse into 24/8 */
530 for (j = 0; j < width; j++) {
531 zshort[j] = (zshort[j] << 8) | (zshort[j] >> 24);
532 }
533 dst += dstStride;
534 }
535 }
536 }
537 else if (pformat == PIPE_FORMAT_S8_UINT_Z24_UNORM ||
538 pformat == PIPE_FORMAT_X8Z24_UNORM) {
539 if (format == GL_DEPTH_COMPONENT) {
540 for (i = 0; i < height; i++) {
541 GLuint ztemp[MAX_WIDTH];
542 GLfloat zfloat[MAX_WIDTH];
543 const double scale = 1.0 / ((1 << 24) - 1);
544 pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
545 y += yStep;
546 for (j = 0; j < width; j++) {
547 zfloat[j] = (float) (scale * ((ztemp[j] >> 8) & 0xffffff));
548 }
549 _mesa_pack_depth_span(ctx, width, dst, type,
550 zfloat, &clippedPacking);
551 dst += dstStride;
552 }
553 }
554 else {
555 /* XXX: unreachable code -- should be before st_read_stencil_pixels */
556 assert(format == GL_DEPTH_STENCIL_EXT);
557 for (i = 0; i < height; i++) {
558 pipe_get_tile_raw(pipe, trans, 0, y, width, 1, dst, 0);
559 y += yStep;
560 dst += dstStride;
561 }
562 }
563 }
564 else if (pformat == PIPE_FORMAT_Z16_UNORM) {
565 for (i = 0; i < height; i++) {
566 GLushort ztemp[MAX_WIDTH];
567 GLfloat zfloat[MAX_WIDTH];
568 const double scale = 1.0 / 0xffff;
569 pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
570 y += yStep;
571 for (j = 0; j < width; j++) {
572 zfloat[j] = (float) (scale * ztemp[j]);
573 }
574 _mesa_pack_depth_span(ctx, width, dst, type,
575 zfloat, &clippedPacking);
576 dst += dstStride;
577 }
578 }
579 else if (pformat == PIPE_FORMAT_Z32_UNORM) {
580 for (i = 0; i < height; i++) {
581 GLuint ztemp[MAX_WIDTH];
582 GLfloat zfloat[MAX_WIDTH];
583 const double scale = 1.0 / 0xffffffff;
584 pipe_get_tile_raw(pipe, trans, 0, y, width, 1, ztemp, 0);
585 y += yStep;
586 for (j = 0; j < width; j++) {
587 zfloat[j] = (float) (scale * ztemp[j]);
588 }
589 _mesa_pack_depth_span(ctx, width, dst, type,
590 zfloat, &clippedPacking);
591 dst += dstStride;
592 }
593 }
594 else if (pformat == PIPE_FORMAT_Z32_FLOAT) {
595 for (i = 0; i < height; i++) {
596 GLfloat zfloat[MAX_WIDTH];
597 pipe_get_tile_raw(pipe, trans, 0, y, width, 1, zfloat, 0);
598 y += yStep;
599 _mesa_pack_depth_span(ctx, width, dst, type,
600 zfloat, &clippedPacking);
601 dst += dstStride;
602 }
603 }
604 else if (pformat == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
605 assert(format == GL_DEPTH_COMPONENT);
606 for (i = 0; i < height; i++) {
607 GLfloat zfloat[MAX_WIDTH]; /* Z32 */
608 GLfloat zfloat2[MAX_WIDTH*2]; /* Z32X32 */
609 pipe_get_tile_raw(pipe, trans, 0, y, width, 1, zfloat2, 0);
610 y += yStep;
611 for (j = 0; j < width; j++) {
612 zfloat[j] = zfloat2[j*2];
613 }
614 _mesa_pack_depth_span(ctx, width, dst, type,
615 zfloat, &clippedPacking);
616 dst += dstStride;
617 }
618 }
619 else if (util_format_is_pure_sint(pformat)) {
620 for (i = 0; i < height; i++) {
621 if (type == GL_UNSIGNED_INT)
622 pipe_get_tile_ui_format(pipe, trans, 0, y, width, 1,
623 pformat, dui);
624 else
625 pipe_get_tile_i_format(pipe, trans, 0, y, width, 1,
626 pformat, di);
627 y += yStep;
628 if (!dfStride) {
629 _mesa_pack_rgba_span_int(ctx, width, (GLuint (*)[4])temp,
630 format, type, dst);
631 dst += dstStride;
632 }
633 }
634 } else if (util_format_is_pure_uint(pformat)) {
635 for (i = 0; i < height; i++) {
636 if (type == GL_UNSIGNED_INT)
637 pipe_get_tile_ui_format(pipe, trans, 0, y, width, 1,
638 pformat, dui);
639 else
640 pipe_get_tile_i_format(pipe, trans, 0, y, width, 1,
641 pformat, di);
642 y += yStep;
643 df += dfStride;
644 if (!dfStride) {
645 _mesa_pack_rgba_span_int(ctx, width, (GLuint (*)[4])temp,
646 format, type, dst);
647 dst += dstStride;
648 }
649 }
650 } else {
651 /* RGBA format */
652 /* Do a row at a time to flip image data vertically */
653 for (i = 0; i < height; i++) {
654 pipe_get_tile_rgba_format(pipe, trans, 0, y, width, 1,
655 pformat, df);
656 y += yStep;
657 df += dfStride;
658 if (!dfStride) {
659 _mesa_pack_rgba_span_float(ctx, width, temp, format, type, dst,
660 &clippedPacking, transferOps);
661 dst += dstStride;
662 }
663 }
664 }
665 }
666
667 free(temp);
668
669 pipe->transfer_destroy(pipe, trans);
670
671 _mesa_unmap_pbo_dest(ctx, &clippedPacking);
672 }
673
674
675 void st_init_readpixels_functions(struct dd_function_table *functions)
676 {
677 functions->ReadPixels = st_readpixels;
678 }