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