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