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