a855fd80681ba7baffb3d0efd75364af9a37d6d5
[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 ASSERT(rb->DataType == GL_UNSIGNED_INT);
125 for (j = 0; j < height; j++, y++) {
126 GLuint *dest = (GLuint *)
127 _mesa_image_address2d(packing, pixels, width, height,
128 GL_DEPTH_COMPONENT, type, j, 0);
129 GLint k;
130 rb->GetRow(ctx, rb, width, x, y, dest);
131 /* convert range from 24-bit to 32-bit */
132 for (k = 0; k < width; k++) {
133 /* Note: put MSByte of 24-bit value into LSByte */
134 dest[k] = (dest[k] << 8) | ((dest[k] >> 16) & 0xff);
135 }
136 }
137 }
138 else if (type == GL_UNSIGNED_INT && fb->Visual.depthBits == 32
139 && !biasOrScale && !packing->SwapBytes) {
140 /* Special case: directly read 32-bit unsigned depth values. */
141 GLint j;
142 ASSERT(rb->Format == MESA_FORMAT_Z32);
143 ASSERT(rb->DataType == GL_UNSIGNED_INT);
144 for (j = 0; j < height; j++, y++) {
145 void *dest = _mesa_image_address2d(packing, pixels, width, height,
146 GL_DEPTH_COMPONENT, type, j, 0);
147 rb->GetRow(ctx, rb, width, x, y, dest);
148 }
149 }
150 else {
151 /* General case (slower) */
152 GLint j;
153 for (j = 0; j < height; j++, y++) {
154 GLfloat depthValues[MAX_WIDTH];
155 GLvoid *dest = _mesa_image_address2d(packing, pixels, width, height,
156 GL_DEPTH_COMPONENT, type, j, 0);
157 _swrast_read_depth_span_float(ctx, rb, width, x, y, depthValues);
158 _mesa_pack_depth_span(ctx, width, dest, type, depthValues, packing);
159 }
160 }
161 }
162
163
164 /**
165 * Read pixels for format=GL_STENCIL_INDEX.
166 */
167 static void
168 read_stencil_pixels( GLcontext *ctx,
169 GLint x, GLint y,
170 GLsizei width, GLsizei height,
171 GLenum type, GLvoid *pixels,
172 const struct gl_pixelstore_attrib *packing )
173 {
174 struct gl_framebuffer *fb = ctx->ReadBuffer;
175 struct gl_renderbuffer *rb = fb->_StencilBuffer;
176 GLint j;
177
178 if (!rb)
179 return;
180
181 /* width should never be > MAX_WIDTH since we did clipping earlier */
182 ASSERT(width <= MAX_WIDTH);
183
184 /* process image row by row */
185 for (j=0;j<height;j++,y++) {
186 GLvoid *dest;
187 GLstencil stencil[MAX_WIDTH];
188
189 _swrast_read_stencil_span(ctx, rb, width, x, y, stencil);
190
191 dest = _mesa_image_address2d(packing, pixels, width, height,
192 GL_STENCIL_INDEX, type, j, 0);
193
194 _mesa_pack_stencil_span(ctx, width, type, dest, stencil, packing);
195 }
196 }
197
198
199
200 /**
201 * Optimized glReadPixels for particular pixel formats when pixel
202 * scaling, biasing, mapping, etc. are disabled.
203 * \return GL_TRUE if success, GL_FALSE if unable to do the readpixels
204 */
205 static GLboolean
206 fast_read_rgba_pixels( GLcontext *ctx,
207 GLint x, GLint y,
208 GLsizei width, GLsizei height,
209 GLenum format, GLenum type,
210 GLvoid *pixels,
211 const struct gl_pixelstore_attrib *packing,
212 GLbitfield transferOps)
213 {
214 struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
215
216 if (!rb)
217 return GL_FALSE;
218
219 ASSERT(rb->_BaseFormat == GL_RGBA || rb->_BaseFormat == GL_RGB);
220
221 /* clipping should have already been done */
222 ASSERT(x + width <= (GLint) rb->Width);
223 ASSERT(y + height <= (GLint) rb->Height);
224
225 /* check for things we can't handle here */
226 if (transferOps ||
227 packing->SwapBytes ||
228 packing->LsbFirst) {
229 return GL_FALSE;
230 }
231
232 if (format == GL_RGBA && rb->DataType == type) {
233 const GLint dstStride = _mesa_image_row_stride(packing, width,
234 format, type);
235 GLubyte *dest
236 = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
237 format, type, 0, 0);
238 GLint row;
239 ASSERT(rb->GetRow);
240 for (row = 0; row < height; row++) {
241 rb->GetRow(ctx, rb, width, x, y + row, dest);
242 dest += dstStride;
243 }
244 return GL_TRUE;
245 }
246
247 if (format == GL_RGB &&
248 rb->DataType == GL_UNSIGNED_BYTE &&
249 type == GL_UNSIGNED_BYTE) {
250 const GLint dstStride = _mesa_image_row_stride(packing, width,
251 format, type);
252 GLubyte *dest
253 = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
254 format, type, 0, 0);
255 GLint row;
256 ASSERT(rb->GetRow);
257 for (row = 0; row < height; row++) {
258 GLubyte tempRow[MAX_WIDTH][4];
259 GLint col;
260 rb->GetRow(ctx, rb, width, x, y + row, tempRow);
261 /* convert RGBA to RGB */
262 for (col = 0; col < width; col++) {
263 dest[col * 3 + 0] = tempRow[col][0];
264 dest[col * 3 + 1] = tempRow[col][1];
265 dest[col * 3 + 2] = tempRow[col][2];
266 }
267 dest += dstStride;
268 }
269 return GL_TRUE;
270 }
271
272 /* not handled */
273 return GL_FALSE;
274 }
275
276
277 /**
278 * When we're using a low-precision color buffer (like 16-bit 5/6/5)
279 * we have to adjust our color values a bit to pass conformance.
280 * The problem is when a 5 or 6-bit color value is convert to an 8-bit
281 * value and then a floating point value, the floating point values don't
282 * increment uniformly as the 5 or 6-bit value is incremented.
283 *
284 * This function adjusts floating point values to compensate.
285 */
286 static void
287 adjust_colors(GLcontext *ctx, GLuint n, GLfloat rgba[][4])
288 {
289 const GLuint rShift = 8 - ctx->Visual.redBits;
290 const GLuint gShift = 8 - ctx->Visual.greenBits;
291 const GLuint bShift = 8 - ctx->Visual.blueBits;
292 const GLfloat rScale = 1.0F / (GLfloat) ((1 << ctx->Visual.redBits ) - 1);
293 const GLfloat gScale = 1.0F / (GLfloat) ((1 << ctx->Visual.greenBits) - 1);
294 const GLfloat bScale = 1.0F / (GLfloat) ((1 << ctx->Visual.blueBits ) - 1);
295 GLuint i;
296 for (i = 0; i < n; i++) {
297 GLint r, g, b;
298 /* convert float back to ubyte */
299 CLAMPED_FLOAT_TO_UBYTE(r, rgba[i][RCOMP]);
300 CLAMPED_FLOAT_TO_UBYTE(g, rgba[i][GCOMP]);
301 CLAMPED_FLOAT_TO_UBYTE(b, rgba[i][BCOMP]);
302 /* using only the N most significant bits of the ubyte value, convert to
303 * float in [0,1].
304 */
305 rgba[i][RCOMP] = (GLfloat) (r >> rShift) * rScale;
306 rgba[i][GCOMP] = (GLfloat) (g >> gShift) * gScale;
307 rgba[i][BCOMP] = (GLfloat) (b >> bShift) * bScale;
308 }
309 }
310
311
312
313 /*
314 * Read R, G, B, A, RGB, L, or LA pixels.
315 */
316 static void
317 read_rgba_pixels( GLcontext *ctx,
318 GLint x, GLint y,
319 GLsizei width, GLsizei height,
320 GLenum format, GLenum type, GLvoid *pixels,
321 const struct gl_pixelstore_attrib *packing )
322 {
323 SWcontext *swrast = SWRAST_CONTEXT(ctx);
324 GLbitfield transferOps = ctx->_ImageTransferState;
325 struct gl_framebuffer *fb = ctx->ReadBuffer;
326 struct gl_renderbuffer *rb = fb->_ColorReadBuffer;
327
328 if (!rb)
329 return;
330
331 if (type == GL_FLOAT && ((ctx->Color.ClampReadColor == GL_TRUE) ||
332 (ctx->Color.ClampReadColor == GL_FIXED_ONLY_ARB &&
333 rb->DataType != GL_FLOAT)))
334 transferOps |= IMAGE_CLAMP_BIT;
335
336 /* Try optimized path first */
337 if (fast_read_rgba_pixels(ctx, x, y, width, height,
338 format, type, pixels, packing, transferOps)) {
339 return; /* done! */
340 }
341
342 /* width should never be > MAX_WIDTH since we did clipping earlier */
343 ASSERT(width <= MAX_WIDTH);
344
345 if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) {
346 GLfloat *dest, *src, *tmpImage, *convImage;
347 GLint row;
348
349 tmpImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
350 if (!tmpImage) {
351 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
352 return;
353 }
354 convImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
355 if (!convImage) {
356 _mesa_free(tmpImage);
357 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
358 return;
359 }
360
361 /* read full RGBA, FLOAT image */
362 dest = tmpImage;
363 for (row = 0; row < height; row++, y++) {
364 if (fb->Visual.rgbMode) {
365 _swrast_read_rgba_span(ctx, rb, width, x, y, GL_FLOAT, dest);
366 }
367 else {
368 GLuint index[MAX_WIDTH];
369 ASSERT(rb->DataType == GL_UNSIGNED_INT);
370 rb->GetRow(ctx, rb, width, x, y, index);
371 _mesa_apply_ci_transfer_ops(ctx,
372 transferOps & IMAGE_SHIFT_OFFSET_BIT,
373 width, index);
374 _mesa_map_ci_to_rgba(ctx, width, index, (GLfloat (*)[4]) dest);
375 }
376 _mesa_apply_rgba_transfer_ops(ctx,
377 transferOps & IMAGE_PRE_CONVOLUTION_BITS,
378 width, (GLfloat (*)[4]) dest);
379 dest += width * 4;
380 }
381
382 /* do convolution */
383 if (ctx->Pixel.Convolution2DEnabled) {
384 _mesa_convolve_2d_image(ctx, &width, &height, tmpImage, convImage);
385 }
386 else {
387 ASSERT(ctx->Pixel.Separable2DEnabled);
388 _mesa_convolve_sep_image(ctx, &width, &height, tmpImage, convImage);
389 }
390 _mesa_free(tmpImage);
391
392 /* finish transfer ops and pack the resulting image */
393 src = convImage;
394 for (row = 0; row < height; row++) {
395 GLvoid *dest;
396 dest = _mesa_image_address2d(packing, pixels, width, height,
397 format, type, row, 0);
398 _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) src,
399 format, type, dest, packing,
400 transferOps & IMAGE_POST_CONVOLUTION_BITS);
401 src += width * 4;
402 }
403 _mesa_free(convImage);
404 }
405 else {
406 /* no convolution */
407 const GLint dstStride
408 = _mesa_image_row_stride(packing, width, format, type);
409 GLfloat (*rgba)[4] = swrast->SpanArrays->attribs[FRAG_ATTRIB_COL0];
410 GLint row;
411 GLubyte *dst
412 = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
413 format, type, 0, 0);
414
415 /* make sure we don't apply 1D convolution */
416 transferOps &= ~(IMAGE_CONVOLUTION_BIT |
417 IMAGE_POST_CONVOLUTION_SCALE_BIAS);
418
419 for (row = 0; row < height; row++, y++) {
420
421 /* Get float rgba pixels */
422 if (fb->Visual.rgbMode) {
423 _swrast_read_rgba_span(ctx, rb, width, x, y, GL_FLOAT, rgba);
424 }
425 else {
426 /* read CI and convert to RGBA */
427 GLuint index[MAX_WIDTH];
428 ASSERT(rb->DataType == GL_UNSIGNED_INT);
429 rb->GetRow(ctx, rb, width, x, y, index);
430 _mesa_apply_ci_transfer_ops(ctx,
431 transferOps & IMAGE_SHIFT_OFFSET_BIT,
432 width, index);
433 _mesa_map_ci_to_rgba(ctx, width, index, rgba);
434 }
435
436 /* apply fudge factor for shallow color buffers */
437 if (fb->Visual.redBits < 8 ||
438 fb->Visual.greenBits < 8 ||
439 fb->Visual.blueBits < 8) {
440 adjust_colors(ctx, width, rgba);
441 }
442
443 /* pack the row of RGBA pixels into user's buffer */
444 _mesa_pack_rgba_span_float(ctx, width, rgba, format, type, dst,
445 packing, transferOps);
446
447 dst += dstStride;
448 }
449 }
450 }
451
452
453 /**
454 * Read combined depth/stencil values.
455 * We'll have already done error checking to be sure the expected
456 * depth and stencil buffers really exist.
457 */
458 static void
459 read_depth_stencil_pixels(GLcontext *ctx,
460 GLint x, GLint y,
461 GLsizei width, GLsizei height,
462 GLenum type, GLvoid *pixels,
463 const struct gl_pixelstore_attrib *packing )
464 {
465 const GLboolean scaleOrBias
466 = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
467 const GLboolean stencilTransfer = ctx->Pixel.IndexShift
468 || ctx->Pixel.IndexOffset || ctx->Pixel.MapStencilFlag;
469 struct gl_renderbuffer *depthRb, *stencilRb;
470
471 depthRb = ctx->ReadBuffer->_DepthBuffer;
472 stencilRb = ctx->ReadBuffer->_StencilBuffer;
473
474 if (!depthRb || !stencilRb)
475 return;
476
477 depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
478 stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
479
480 if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
481 stencilRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
482 depthRb == stencilRb &&
483 !scaleOrBias &&
484 !stencilTransfer) {
485 /* This is the ideal case.
486 * Reading GL_DEPTH_STENCIL pixels from combined depth/stencil buffer.
487 * Plus, no pixel transfer ops to worry about!
488 */
489 GLint i;
490 GLint dstStride = _mesa_image_row_stride(packing, width,
491 GL_DEPTH_STENCIL_EXT, type);
492 GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, pixels,
493 width, height,
494 GL_DEPTH_STENCIL_EXT,
495 type, 0, 0);
496 for (i = 0; i < height; i++) {
497 depthRb->GetRow(ctx, depthRb, width, x, y + i, dst);
498 dst += dstStride;
499 }
500 }
501 else {
502 /* Reading GL_DEPTH_STENCIL pixels from separate depth/stencil buffers,
503 * or we need pixel transfer.
504 */
505 GLint i;
506 depthRb = ctx->ReadBuffer->_DepthBuffer;
507 stencilRb = ctx->ReadBuffer->_StencilBuffer;
508
509 for (i = 0; i < height; i++) {
510 GLstencil stencilVals[MAX_WIDTH];
511
512 GLuint *depthStencilDst = (GLuint *)
513 _mesa_image_address2d(packing, pixels, width, height,
514 GL_DEPTH_STENCIL_EXT, type, i, 0);
515
516 _swrast_read_stencil_span(ctx, stencilRb, width,
517 x, y + i, stencilVals);
518
519 if (!scaleOrBias && !stencilTransfer
520 && ctx->ReadBuffer->Visual.depthBits == 24) {
521 /* ideal case */
522 GLuint zVals[MAX_WIDTH]; /* 24-bit values! */
523 GLint j;
524 ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
525 /* note, we've already been clipped */
526 depthRb->GetRow(ctx, depthRb, width, x, y + i, zVals);
527 for (j = 0; j < width; j++) {
528 depthStencilDst[j] = (zVals[j] << 8) | (stencilVals[j] & 0xff);
529 }
530 }
531 else {
532 /* general case */
533 GLfloat depthVals[MAX_WIDTH];
534 _swrast_read_depth_span_float(ctx, depthRb, width, x, y + i,
535 depthVals);
536 _mesa_pack_depth_stencil_span(ctx, width, depthStencilDst,
537 depthVals, stencilVals, packing);
538 }
539 }
540 }
541 }
542
543
544
545 /**
546 * Software fallback routine for ctx->Driver.ReadPixels().
547 * By time we get here, all error checking will have been done.
548 */
549 void
550 _swrast_ReadPixels( GLcontext *ctx,
551 GLint x, GLint y, GLsizei width, GLsizei height,
552 GLenum format, GLenum type,
553 const struct gl_pixelstore_attrib *packing,
554 GLvoid *pixels )
555 {
556 SWcontext *swrast = SWRAST_CONTEXT(ctx);
557 struct gl_pixelstore_attrib clippedPacking = *packing;
558
559 if (ctx->NewState)
560 _mesa_update_state(ctx);
561
562 /* Need to do swrast_render_start() before clipping or anything else
563 * since this is where a driver may grab the hw lock and get an updated
564 * window size.
565 */
566 swrast_render_start(ctx);
567
568 if (swrast->NewState)
569 _swrast_validate_derived( ctx );
570
571 /* Do all needed clipping here, so that we can forget about it later */
572 if (!_mesa_clip_readpixels(ctx, &x, &y, &width, &height, &clippedPacking)) {
573 /* The ReadPixels region is totally outside the window bounds */
574 swrast_render_finish(ctx);
575 return;
576 }
577
578 pixels = _mesa_map_pbo_dest(ctx, &clippedPacking, pixels);
579 if (!pixels)
580 return;
581
582 switch (format) {
583 case GL_COLOR_INDEX:
584 read_index_pixels(ctx, x, y, width, height, type, pixels,
585 &clippedPacking);
586 break;
587 case GL_STENCIL_INDEX:
588 read_stencil_pixels(ctx, x, y, width, height, type, pixels,
589 &clippedPacking);
590 break;
591 case GL_DEPTH_COMPONENT:
592 read_depth_pixels(ctx, x, y, width, height, type, pixels,
593 &clippedPacking);
594 break;
595 case GL_RED:
596 case GL_GREEN:
597 case GL_BLUE:
598 case GL_ALPHA:
599 case GL_RGB:
600 case GL_LUMINANCE:
601 case GL_LUMINANCE_ALPHA:
602 case GL_RGBA:
603 case GL_BGR:
604 case GL_BGRA:
605 case GL_ABGR_EXT:
606 read_rgba_pixels(ctx, x, y, width, height,
607 format, type, pixels, &clippedPacking);
608 break;
609 case GL_DEPTH_STENCIL_EXT:
610 read_depth_stencil_pixels(ctx, x, y, width, height,
611 type, pixels, &clippedPacking);
612 break;
613 default:
614 _mesa_problem(ctx, "unexpected format in _swrast_ReadPixels");
615 /* don't return yet, clean-up */
616 }
617
618 swrast_render_finish(ctx);
619
620 _mesa_unmap_pbo_dest(ctx, &clippedPacking);
621 }