Merge commit 'mesa_7_6_branch' into mesa_7_7_branch
[mesa.git] / src / mesa / swrast / s_readpix.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.0.3
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "main/glheader.h"
27 #include "main/bufferobj.h"
28 #include "main/colormac.h"
29 #include "main/convolve.h"
30 #include "main/context.h"
31 #include "main/feedback.h"
32 #include "main/formats.h"
33 #include "main/image.h"
34 #include "main/macros.h"
35 #include "main/imports.h"
36 #include "main/pixel.h"
37 #include "main/state.h"
38
39 #include "s_context.h"
40 #include "s_depth.h"
41 #include "s_span.h"
42 #include "s_stencil.h"
43
44
45 /*
46 * Read a block of color index pixels.
47 */
48 static void
49 read_index_pixels( GLcontext *ctx,
50 GLint x, GLint y,
51 GLsizei width, GLsizei height,
52 GLenum type, GLvoid *pixels,
53 const struct gl_pixelstore_attrib *packing )
54 {
55 struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
56 GLint i;
57
58 if (!rb)
59 return;
60
61 /* width should never be > MAX_WIDTH since we did clipping earlier */
62 ASSERT(width <= MAX_WIDTH);
63
64 /* process image row by row */
65 for (i = 0; i < height; i++) {
66 GLuint index[MAX_WIDTH];
67 GLvoid *dest;
68 ASSERT(rb->DataType == GL_UNSIGNED_INT);
69 rb->GetRow(ctx, rb, width, x, y + i, index);
70
71 dest = _mesa_image_address2d(packing, pixels, width, height,
72 GL_COLOR_INDEX, type, i, 0);
73
74 _mesa_pack_index_span(ctx, width, type, dest, index,
75 &ctx->Pack, ctx->_ImageTransferState);
76 }
77 }
78
79
80
81 /**
82 * Read pixels for format=GL_DEPTH_COMPONENT.
83 */
84 static void
85 read_depth_pixels( GLcontext *ctx,
86 GLint x, GLint y,
87 GLsizei width, GLsizei height,
88 GLenum type, GLvoid *pixels,
89 const struct gl_pixelstore_attrib *packing )
90 {
91 struct gl_framebuffer *fb = ctx->ReadBuffer;
92 struct gl_renderbuffer *rb = fb->_DepthBuffer;
93 const GLboolean biasOrScale
94 = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
95
96 if (!rb)
97 return;
98
99 /* clipping should have been done already */
100 ASSERT(x >= 0);
101 ASSERT(y >= 0);
102 ASSERT(x + width <= (GLint) rb->Width);
103 ASSERT(y + height <= (GLint) rb->Height);
104 /* width should never be > MAX_WIDTH since we did clipping earlier */
105 ASSERT(width <= MAX_WIDTH);
106
107 if (type == GL_UNSIGNED_SHORT && fb->Visual.depthBits == 16
108 && !biasOrScale && !packing->SwapBytes) {
109 /* Special case: directly read 16-bit unsigned depth values. */
110 GLint j;
111 ASSERT(rb->Format == MESA_FORMAT_Z16);
112 ASSERT(rb->DataType == GL_UNSIGNED_SHORT);
113 for (j = 0; j < height; j++, y++) {
114 void *dest =_mesa_image_address2d(packing, pixels, width, height,
115 GL_DEPTH_COMPONENT, type, j, 0);
116 rb->GetRow(ctx, rb, width, x, y, dest);
117 }
118 }
119 else if (type == GL_UNSIGNED_INT && fb->Visual.depthBits == 24
120 && !biasOrScale && !packing->SwapBytes) {
121 /* Special case: directly read 24-bit unsigned depth values. */
122 GLint j;
123 ASSERT(rb->Format == MESA_FORMAT_X8_Z24 ||
124 rb->Format == MESA_FORMAT_S8_Z24 ||
125 rb->Format == MESA_FORMAT_Z24_X8 ||
126 rb->Format == MESA_FORMAT_Z24_S8);
127 ASSERT(rb->DataType == GL_UNSIGNED_INT ||
128 rb->DataType == GL_UNSIGNED_INT_24_8);
129 for (j = 0; j < height; j++, y++) {
130 GLuint *dest = (GLuint *)
131 _mesa_image_address2d(packing, pixels, width, height,
132 GL_DEPTH_COMPONENT, type, j, 0);
133 GLint k;
134 rb->GetRow(ctx, rb, width, x, y, dest);
135 /* convert range from 24-bit to 32-bit */
136 if (rb->Format == MESA_FORMAT_X8_Z24 ||
137 rb->Format == MESA_FORMAT_S8_Z24) {
138 for (k = 0; k < width; k++) {
139 /* Note: put MSByte of 24-bit value into LSByte */
140 dest[k] = (dest[k] << 8) | ((dest[k] >> 16) & 0xff);
141 }
142 }
143 else {
144 for (k = 0; k < width; k++) {
145 /* Note: fill in LSByte by replication */
146 dest[k] = dest[k] | ((dest[k] >> 8) & 0xff);
147 }
148 }
149 }
150 }
151 else if (type == GL_UNSIGNED_INT && fb->Visual.depthBits == 32
152 && !biasOrScale && !packing->SwapBytes) {
153 /* Special case: directly read 32-bit unsigned depth values. */
154 GLint j;
155 ASSERT(rb->Format == MESA_FORMAT_Z32);
156 ASSERT(rb->DataType == GL_UNSIGNED_INT);
157 for (j = 0; j < height; j++, y++) {
158 void *dest = _mesa_image_address2d(packing, pixels, width, height,
159 GL_DEPTH_COMPONENT, type, j, 0);
160 rb->GetRow(ctx, rb, width, x, y, dest);
161 }
162 }
163 else {
164 /* General case (slower) */
165 GLint j;
166 for (j = 0; j < height; j++, y++) {
167 GLfloat depthValues[MAX_WIDTH];
168 GLvoid *dest = _mesa_image_address2d(packing, pixels, width, height,
169 GL_DEPTH_COMPONENT, type, j, 0);
170 _swrast_read_depth_span_float(ctx, rb, width, x, y, depthValues);
171 _mesa_pack_depth_span(ctx, width, dest, type, depthValues, packing);
172 }
173 }
174 }
175
176
177 /**
178 * Read pixels for format=GL_STENCIL_INDEX.
179 */
180 static void
181 read_stencil_pixels( GLcontext *ctx,
182 GLint x, GLint y,
183 GLsizei width, GLsizei height,
184 GLenum type, GLvoid *pixels,
185 const struct gl_pixelstore_attrib *packing )
186 {
187 struct gl_framebuffer *fb = ctx->ReadBuffer;
188 struct gl_renderbuffer *rb = fb->_StencilBuffer;
189 GLint j;
190
191 if (!rb)
192 return;
193
194 /* width should never be > MAX_WIDTH since we did clipping earlier */
195 ASSERT(width <= MAX_WIDTH);
196
197 /* process image row by row */
198 for (j=0;j<height;j++,y++) {
199 GLvoid *dest;
200 GLstencil stencil[MAX_WIDTH];
201
202 _swrast_read_stencil_span(ctx, rb, width, x, y, stencil);
203
204 dest = _mesa_image_address2d(packing, pixels, width, height,
205 GL_STENCIL_INDEX, type, j, 0);
206
207 _mesa_pack_stencil_span(ctx, width, type, dest, stencil, packing);
208 }
209 }
210
211
212
213 /**
214 * Optimized glReadPixels for particular pixel formats when pixel
215 * scaling, biasing, mapping, etc. are disabled.
216 * \return GL_TRUE if success, GL_FALSE if unable to do the readpixels
217 */
218 static GLboolean
219 fast_read_rgba_pixels( GLcontext *ctx,
220 GLint x, GLint y,
221 GLsizei width, GLsizei height,
222 GLenum format, GLenum type,
223 GLvoid *pixels,
224 const struct gl_pixelstore_attrib *packing,
225 GLbitfield transferOps)
226 {
227 struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
228
229 if (!rb)
230 return GL_FALSE;
231
232 ASSERT(rb->_BaseFormat == GL_RGBA || rb->_BaseFormat == GL_RGB);
233
234 /* clipping should have already been done */
235 ASSERT(x + width <= (GLint) rb->Width);
236 ASSERT(y + height <= (GLint) rb->Height);
237
238 /* check for things we can't handle here */
239 if (transferOps ||
240 packing->SwapBytes ||
241 packing->LsbFirst) {
242 return GL_FALSE;
243 }
244
245 if (format == GL_RGBA && rb->DataType == type) {
246 const GLint dstStride = _mesa_image_row_stride(packing, width,
247 format, type);
248 GLubyte *dest
249 = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
250 format, type, 0, 0);
251 GLint row;
252 ASSERT(rb->GetRow);
253 for (row = 0; row < height; row++) {
254 rb->GetRow(ctx, rb, width, x, y + row, dest);
255 dest += dstStride;
256 }
257 return GL_TRUE;
258 }
259
260 if (format == GL_RGB &&
261 rb->DataType == GL_UNSIGNED_BYTE &&
262 type == GL_UNSIGNED_BYTE) {
263 const GLint dstStride = _mesa_image_row_stride(packing, width,
264 format, type);
265 GLubyte *dest
266 = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
267 format, type, 0, 0);
268 GLint row;
269 ASSERT(rb->GetRow);
270 for (row = 0; row < height; row++) {
271 GLubyte tempRow[MAX_WIDTH][4];
272 GLint col;
273 rb->GetRow(ctx, rb, width, x, y + row, tempRow);
274 /* convert RGBA to RGB */
275 for (col = 0; col < width; col++) {
276 dest[col * 3 + 0] = tempRow[col][0];
277 dest[col * 3 + 1] = tempRow[col][1];
278 dest[col * 3 + 2] = tempRow[col][2];
279 }
280 dest += dstStride;
281 }
282 return GL_TRUE;
283 }
284
285 /* not handled */
286 return GL_FALSE;
287 }
288
289
290 /**
291 * When we're using a low-precision color buffer (like 16-bit 5/6/5)
292 * we have to adjust our color values a bit to pass conformance.
293 * The problem is when a 5 or 6-bit color value is convert to an 8-bit
294 * value and then a floating point value, the floating point values don't
295 * increment uniformly as the 5 or 6-bit value is incremented.
296 *
297 * This function adjusts floating point values to compensate.
298 */
299 static void
300 adjust_colors(GLcontext *ctx, GLuint n, GLfloat rgba[][4])
301 {
302 const GLuint rShift = 8 - ctx->Visual.redBits;
303 const GLuint gShift = 8 - ctx->Visual.greenBits;
304 const GLuint bShift = 8 - ctx->Visual.blueBits;
305 const GLfloat rScale = 1.0F / (GLfloat) ((1 << ctx->Visual.redBits ) - 1);
306 const GLfloat gScale = 1.0F / (GLfloat) ((1 << ctx->Visual.greenBits) - 1);
307 const GLfloat bScale = 1.0F / (GLfloat) ((1 << ctx->Visual.blueBits ) - 1);
308 GLuint i;
309 for (i = 0; i < n; i++) {
310 GLint r, g, b;
311 /* convert float back to ubyte */
312 CLAMPED_FLOAT_TO_UBYTE(r, rgba[i][RCOMP]);
313 CLAMPED_FLOAT_TO_UBYTE(g, rgba[i][GCOMP]);
314 CLAMPED_FLOAT_TO_UBYTE(b, rgba[i][BCOMP]);
315 /* using only the N most significant bits of the ubyte value, convert to
316 * float in [0,1].
317 */
318 rgba[i][RCOMP] = (GLfloat) (r >> rShift) * rScale;
319 rgba[i][GCOMP] = (GLfloat) (g >> gShift) * gScale;
320 rgba[i][BCOMP] = (GLfloat) (b >> bShift) * bScale;
321 }
322 }
323
324
325
326 /*
327 * Read R, G, B, A, RGB, L, or LA pixels.
328 */
329 static void
330 read_rgba_pixels( GLcontext *ctx,
331 GLint x, GLint y,
332 GLsizei width, GLsizei height,
333 GLenum format, GLenum type, GLvoid *pixels,
334 const struct gl_pixelstore_attrib *packing )
335 {
336 SWcontext *swrast = SWRAST_CONTEXT(ctx);
337 GLbitfield transferOps = ctx->_ImageTransferState;
338 struct gl_framebuffer *fb = ctx->ReadBuffer;
339 struct gl_renderbuffer *rb = fb->_ColorReadBuffer;
340
341 if (!rb)
342 return;
343
344 if (type == GL_FLOAT && ((ctx->Color.ClampReadColor == GL_TRUE) ||
345 (ctx->Color.ClampReadColor == GL_FIXED_ONLY_ARB &&
346 rb->DataType != GL_FLOAT)))
347 transferOps |= IMAGE_CLAMP_BIT;
348
349 /* Try optimized path first */
350 if (fast_read_rgba_pixels(ctx, x, y, width, height,
351 format, type, pixels, packing, transferOps)) {
352 return; /* done! */
353 }
354
355 /* width should never be > MAX_WIDTH since we did clipping earlier */
356 ASSERT(width <= MAX_WIDTH);
357
358 if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) {
359 GLfloat *dest, *src, *tmpImage, *convImage;
360 GLint row;
361
362 tmpImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
363 if (!tmpImage) {
364 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
365 return;
366 }
367 convImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
368 if (!convImage) {
369 _mesa_free(tmpImage);
370 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
371 return;
372 }
373
374 /* read full RGBA, FLOAT image */
375 dest = tmpImage;
376 for (row = 0; row < height; row++, y++) {
377 if (fb->Visual.rgbMode) {
378 _swrast_read_rgba_span(ctx, rb, width, x, y, GL_FLOAT, dest);
379 }
380 else {
381 GLuint index[MAX_WIDTH];
382 ASSERT(rb->DataType == GL_UNSIGNED_INT);
383 rb->GetRow(ctx, rb, width, x, y, index);
384 _mesa_apply_ci_transfer_ops(ctx,
385 transferOps & IMAGE_SHIFT_OFFSET_BIT,
386 width, index);
387 _mesa_map_ci_to_rgba(ctx, width, index, (GLfloat (*)[4]) dest);
388 }
389 _mesa_apply_rgba_transfer_ops(ctx,
390 transferOps & IMAGE_PRE_CONVOLUTION_BITS,
391 width, (GLfloat (*)[4]) dest);
392 dest += width * 4;
393 }
394
395 /* do convolution */
396 if (ctx->Pixel.Convolution2DEnabled) {
397 _mesa_convolve_2d_image(ctx, &width, &height, tmpImage, convImage);
398 }
399 else {
400 ASSERT(ctx->Pixel.Separable2DEnabled);
401 _mesa_convolve_sep_image(ctx, &width, &height, tmpImage, convImage);
402 }
403 _mesa_free(tmpImage);
404
405 /* finish transfer ops and pack the resulting image */
406 src = convImage;
407 for (row = 0; row < height; row++) {
408 GLvoid *dest;
409 dest = _mesa_image_address2d(packing, pixels, width, height,
410 format, type, row, 0);
411 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) src,
412 format, type, dest, packing,
413 transferOps & IMAGE_POST_CONVOLUTION_BITS);
414 src += width * 4;
415 }
416 _mesa_free(convImage);
417 }
418 else {
419 /* no convolution */
420 const GLint dstStride
421 = _mesa_image_row_stride(packing, width, format, type);
422 GLfloat (*rgba)[4] = swrast->SpanArrays->attribs[FRAG_ATTRIB_COL0];
423 GLint row;
424 GLubyte *dst
425 = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
426 format, type, 0, 0);
427
428 /* make sure we don't apply 1D convolution */
429 transferOps &= ~(IMAGE_CONVOLUTION_BIT |
430 IMAGE_POST_CONVOLUTION_SCALE_BIAS);
431
432 for (row = 0; row < height; row++, y++) {
433
434 /* Get float rgba pixels */
435 if (fb->Visual.rgbMode) {
436 _swrast_read_rgba_span(ctx, rb, width, x, y, GL_FLOAT, rgba);
437 }
438 else {
439 /* read CI and convert to RGBA */
440 GLuint index[MAX_WIDTH];
441 ASSERT(rb->DataType == GL_UNSIGNED_INT);
442 rb->GetRow(ctx, rb, width, x, y, index);
443 _mesa_apply_ci_transfer_ops(ctx,
444 transferOps & IMAGE_SHIFT_OFFSET_BIT,
445 width, index);
446 _mesa_map_ci_to_rgba(ctx, width, index, rgba);
447 }
448
449 /* apply fudge factor for shallow color buffers */
450 if (fb->Visual.redBits < 8 ||
451 fb->Visual.greenBits < 8 ||
452 fb->Visual.blueBits < 8) {
453 adjust_colors(ctx, width, rgba);
454 }
455
456 /* pack the row of RGBA pixels into user's buffer */
457 _mesa_pack_rgba_span_float(ctx, width, rgba, format, type, dst,
458 packing, transferOps);
459
460 dst += dstStride;
461 }
462 }
463 }
464
465
466 /**
467 * Read combined depth/stencil values.
468 * We'll have already done error checking to be sure the expected
469 * depth and stencil buffers really exist.
470 */
471 static void
472 read_depth_stencil_pixels(GLcontext *ctx,
473 GLint x, GLint y,
474 GLsizei width, GLsizei height,
475 GLenum type, GLvoid *pixels,
476 const struct gl_pixelstore_attrib *packing )
477 {
478 const GLboolean scaleOrBias
479 = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
480 const GLboolean stencilTransfer = ctx->Pixel.IndexShift
481 || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag;
482 struct gl_renderbuffer *depthRb, *stencilRb;
483
484 depthRb = ctx->ReadBuffer->_DepthBuffer;
485 stencilRb = ctx->ReadBuffer->_StencilBuffer;
486
487 if (!depthRb || !stencilRb)
488 return;
489
490 depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
491 stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
492
493 if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
494 stencilRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
495 depthRb == stencilRb &&
496 !scaleOrBias &&
497 !stencilTransfer) {
498 /* This is the ideal case.
499 * Reading GL_DEPTH_STENCIL pixels from combined depth/stencil buffer.
500 * Plus, no pixel transfer ops to worry about!
501 */
502 GLint i;
503 GLint dstStride = _mesa_image_row_stride(packing, width,
504 GL_DEPTH_STENCIL_EXT, type);
505 GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, pixels,
506 width, height,
507 GL_DEPTH_STENCIL_EXT,
508 type, 0, 0);
509 for (i = 0; i < height; i++) {
510 depthRb->GetRow(ctx, depthRb, width, x, y + i, dst);
511 dst += dstStride;
512 }
513 }
514 else {
515 /* Reading GL_DEPTH_STENCIL pixels from separate depth/stencil buffers,
516 * or we need pixel transfer.
517 */
518 GLint i;
519 depthRb = ctx->ReadBuffer->_DepthBuffer;
520 stencilRb = ctx->ReadBuffer->_StencilBuffer;
521
522 for (i = 0; i < height; i++) {
523 GLstencil stencilVals[MAX_WIDTH];
524
525 GLuint *depthStencilDst = (GLuint *)
526 _mesa_image_address2d(packing, pixels, width, height,
527 GL_DEPTH_STENCIL_EXT, type, i, 0);
528
529 _swrast_read_stencil_span(ctx, stencilRb, width,
530 x, y + i, stencilVals);
531
532 if (!scaleOrBias && !stencilTransfer
533 && ctx->ReadBuffer->Visual.depthBits == 24) {
534 /* ideal case */
535 GLuint zVals[MAX_WIDTH]; /* 24-bit values! */
536 GLint j;
537 ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
538 /* note, we've already been clipped */
539 depthRb->GetRow(ctx, depthRb, width, x, y + i, zVals);
540 for (j = 0; j < width; j++) {
541 depthStencilDst[j] = (zVals[j] << 8) | (stencilVals[j] & 0xff);
542 }
543 }
544 else {
545 /* general case */
546 GLfloat depthVals[MAX_WIDTH];
547 _swrast_read_depth_span_float(ctx, depthRb, width, x, y + i,
548 depthVals);
549 _mesa_pack_depth_stencil_span(ctx, width, depthStencilDst,
550 depthVals, stencilVals, packing);
551 }
552 }
553 }
554 }
555
556
557
558 /**
559 * Software fallback routine for ctx->Driver.ReadPixels().
560 * By time we get here, all error checking will have been done.
561 */
562 void
563 _swrast_ReadPixels( GLcontext *ctx,
564 GLint x, GLint y, GLsizei width, GLsizei height,
565 GLenum format, GLenum type,
566 const struct gl_pixelstore_attrib *packing,
567 GLvoid *pixels )
568 {
569 SWcontext *swrast = SWRAST_CONTEXT(ctx);
570 struct gl_pixelstore_attrib clippedPacking = *packing;
571
572 if (ctx->NewState)
573 _mesa_update_state(ctx);
574
575 /* Need to do swrast_render_start() before clipping or anything else
576 * since this is where a driver may grab the hw lock and get an updated
577 * window size.
578 */
579 swrast_render_start(ctx);
580
581 if (swrast->NewState)
582 _swrast_validate_derived( ctx );
583
584 /* Do all needed clipping here, so that we can forget about it later */
585 if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
586 /* The ReadPixels region is totally outside the window bounds */
587 swrast_render_finish(ctx);
588 return;
589 }
590
591 pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels);
592 if (!pixels)
593 return;
594
595 switch (format) {
596 case GL_COLOR_INDEX:
597 read_index_pixels(ctx, x, y, width, height, type, pixels,
598 &clippedPacking);
599 break;
600 case GL_STENCIL_INDEX:
601 read_stencil_pixels(ctx, x, y, width, height, type, pixels,
602 &clippedPacking);
603 break;
604 case GL_DEPTH_COMPONENT:
605 read_depth_pixels(ctx, x, y, width, height, type, pixels,
606 &clippedPacking);
607 break;
608 case GL_RED:
609 case GL_GREEN:
610 case GL_BLUE:
611 case GL_ALPHA:
612 case GL_RGB:
613 case GL_LUMINANCE:
614 case GL_LUMINANCE_ALPHA:
615 case GL_RGBA:
616 case GL_BGR:
617 case GL_BGRA:
618 case GL_ABGR_EXT:
619 read_rgba_pixels(ctx, x, y, width, height,
620 format, type, pixels, &clippedPacking);
621 break;
622 case GL_DEPTH_STENCIL_EXT:
623 read_depth_stencil_pixels(ctx, x, y, width, height,
624 type, pixels, &clippedPacking);
625 break;
626 default:
627 _mesa_problem(ctx, "unexpected format in _swrast_ReadPixels");
628 /* don't return yet, clean-up */
629 }
630
631 swrast_render_finish(ctx);
632
633 _mesa_unmap_pbo_dest(ctx, &clippedPacking);
634 }