~ubuntu-branches/ubuntu/raring/mesa/raring-proposed

« back to all changes in this revision

Viewing changes to src/mesa/state_tracker/st_cb_readpixels.c

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2011-06-19 21:26:00 UTC
  • mfrom: (1.6.1 upstream) (3.3.18 sid)
  • mto: (3.3.20 sid)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: james.westby@ubuntu.com-20110619212600-rleaapdmnbtstekb
Tags: 7.11~0-2
Thank you sbuild for giving a green light when that's not actually the
case. Fix missing Pre-Depends for the libegl1-mesa-drivers package
(multiarch-support).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include "main/context.h"
39
39
#include "main/image.h"
40
40
#include "main/pack.h"
 
41
#include "main/pbo.h"
41
42
 
42
43
#include "pipe/p_context.h"
43
44
#include "pipe/p_defines.h"
 
45
#include "util/u_format.h"
44
46
#include "util/u_inlines.h"
45
47
#include "util/u_tile.h"
46
48
 
80
82
   /* Create a read transfer from the renderbuffer's texture */
81
83
 
82
84
   pt = pipe_get_transfer(pipe, strb->texture,
83
 
                          0, 0,
 
85
                          strb->rtt_level,
 
86
                          strb->rtt_face + strb->rtt_slice,
84
87
                          PIPE_TRANSFER_READ,
85
88
                          x, y, width, height);
86
89
 
196
199
                   const struct gl_pixelstore_attrib *pack,
197
200
                   GLvoid *dest)
198
201
{
 
202
   GLubyte alphaORoperand;
199
203
   enum combination {
200
204
      A8R8G8B8_UNORM_TO_RGBA_UBYTE,
201
205
      A8R8G8B8_UNORM_TO_RGB_UBYTE,
202
 
      A8R8G8B8_UNORM_TO_BGRA_UINT
 
206
      A8R8G8B8_UNORM_TO_BGRA_UINT,
 
207
      A8R8G8B8_UNORM_TO_RGBA_UINT
203
208
   } combo;
204
209
 
205
210
   if (ctx->_ImageTransferState)
206
211
      return GL_FALSE;
207
212
 
208
 
   if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
209
 
       format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
 
213
   if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM) {
 
214
      alphaORoperand = 0;
 
215
   }
 
216
   else if (strb->format == PIPE_FORMAT_B8G8R8X8_UNORM ) {
 
217
      alphaORoperand = 0xff;
 
218
   }
 
219
   else {
 
220
      return GL_FALSE;
 
221
   }
 
222
 
 
223
   if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
210
224
      combo = A8R8G8B8_UNORM_TO_RGBA_UBYTE;
211
225
   }
212
 
   else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
213
 
            format == GL_RGB && type == GL_UNSIGNED_BYTE) {
 
226
   else if (format == GL_RGB && type == GL_UNSIGNED_BYTE) {
214
227
      combo = A8R8G8B8_UNORM_TO_RGB_UBYTE;
215
228
   }
216
 
   else if (strb->format == PIPE_FORMAT_B8G8R8A8_UNORM &&
217
 
            format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) {
 
229
   else if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV) {
218
230
      combo = A8R8G8B8_UNORM_TO_BGRA_UINT;
219
231
   }
 
232
   else if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8) {
 
233
      combo = A8R8G8B8_UNORM_TO_RGBA_UINT;
 
234
   }
220
235
   else {
221
236
      return GL_FALSE;
222
237
   }
236
251
      }
237
252
 
238
253
      trans = pipe_get_transfer(pipe, strb->texture,
239
 
                                0, 0,
 
254
                                strb->rtt_level,
 
255
                                strb->rtt_face + strb->rtt_slice,
240
256
                                PIPE_TRANSFER_READ,
241
257
                                x, y, width, height);
242
258
      if (!trans) {
276
292
               dst[col*4+0] = (pixel >> 16) & 0xff;
277
293
               dst[col*4+1] = (pixel >>  8) & 0xff;
278
294
               dst[col*4+2] = (pixel >>  0) & 0xff;
279
 
               dst[col*4+3] = (pixel >> 24) & 0xff;
 
295
               dst[col*4+3] = ((pixel >> 24) & 0xff) | alphaORoperand;
280
296
            }
281
297
            dst += dstStride;
282
298
            y += dy;
299
315
         for (row = 0; row < height; row++) {
300
316
            const GLubyte *src = map + y * trans->stride;
301
317
            memcpy(dst, src, 4 * width);
 
318
            if (alphaORoperand) {
 
319
               assert(alphaORoperand == 0xff);
 
320
               for (col = 0; col < width; col++) {
 
321
                  dst[col*4+3] = 0xff;
 
322
               }
 
323
            }
 
324
            dst += dstStride;
 
325
            y += dy;
 
326
         }
 
327
         break;
 
328
      case A8R8G8B8_UNORM_TO_RGBA_UINT:
 
329
         for (row = 0; row < height; row++) {
 
330
            const GLubyte *src = map + y * trans->stride;
 
331
            for (col = 0; col < width; col++) {
 
332
               GLuint pixel = ((GLuint *) src)[col];
 
333
               dst[col*4+0] = ((pixel >> 24) & 0xff) | alphaORoperand;
 
334
               dst[col*4+1] = (pixel >> 0) & 0xff;
 
335
               dst[col*4+2] = (pixel >> 8) & 0xff;
 
336
               dst[col*4+3] = (pixel >> 16) & 0xff;
 
337
            }
302
338
            dst += dstStride;
303
339
            y += dy;
304
340
         }
329
365
   struct st_context *st = st_context(ctx);
330
366
   struct pipe_context *pipe = st->pipe;
331
367
   GLfloat (*temp)[4];
332
 
   const GLbitfield transferOps = ctx->_ImageTransferState;
 
368
   GLbitfield transferOps = ctx->_ImageTransferState;
333
369
   GLsizei i, j;
334
370
   GLint yStep, dfStride;
335
371
   GLfloat *df;
336
372
   struct st_renderbuffer *strb;
337
373
   struct gl_pixelstore_attrib clippedPacking = *pack;
338
374
   struct pipe_transfer *trans;
 
375
   enum pipe_format pformat;
339
376
 
340
377
   assert(ctx->ReadBuffer->Width > 0);
341
378
 
388
425
      return;
389
426
   }
390
427
 
391
 
   if (format == GL_RGBA && type == GL_FLOAT) {
 
428
   if(ctx->Color._ClampReadColor)
 
429
      transferOps |= IMAGE_CLAMP_BIT;
 
430
 
 
431
   if (format == GL_RGBA && type == GL_FLOAT && !transferOps) {
392
432
      /* write tile(row) directly into user's buffer */
393
433
      df = (GLfloat *) _mesa_image_address2d(&clippedPacking, dest, width,
394
434
                                             height, format, type, 0, 0);
407
447
 
408
448
   /* Create a read transfer from the renderbuffer's texture */
409
449
   trans = pipe_get_transfer(pipe, strb->texture,
410
 
                             0, 0,
 
450
                             strb->rtt_level, /* level */
 
451
                             strb->rtt_face + strb->rtt_slice, /* layer */
411
452
                             PIPE_TRANSFER_READ,
412
453
                             x, y, width, height);
413
454
 
421
462
      yStep = 1;
422
463
   }
423
464
 
 
465
   /* possibly convert sRGB format to linear RGB format */
 
466
   pformat = util_format_linear(trans->resource->format);
 
467
 
424
468
   if (ST_DEBUG & DEBUG_FALLBACK)
425
469
      debug_printf("%s: fallback processing\n", __FUNCTION__);
426
470
 
435
479
      const GLint dstStride = _mesa_image_row_stride(&clippedPacking, width,
436
480
                                                     format, type);
437
481
 
438
 
      if (trans->resource->format == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
439
 
          trans->resource->format == PIPE_FORMAT_Z24X8_UNORM) {
 
482
      if (pformat == PIPE_FORMAT_Z24_UNORM_S8_USCALED ||
 
483
          pformat == PIPE_FORMAT_Z24X8_UNORM) {
440
484
         if (format == GL_DEPTH_COMPONENT) {
441
485
            for (i = 0; i < height; i++) {
442
486
               GLuint ztemp[MAX_WIDTH];
467
511
            }
468
512
         }
469
513
      }
470
 
      else if (trans->resource->format == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
471
 
               trans->resource->format == PIPE_FORMAT_X8Z24_UNORM) {
 
514
      else if (pformat == PIPE_FORMAT_S8_USCALED_Z24_UNORM ||
 
515
               pformat == PIPE_FORMAT_X8Z24_UNORM) {
472
516
         if (format == GL_DEPTH_COMPONENT) {
473
517
            for (i = 0; i < height; i++) {
474
518
               GLuint ztemp[MAX_WIDTH];
494
538
            }
495
539
         }
496
540
      }
497
 
      else if (trans->resource->format == PIPE_FORMAT_Z16_UNORM) {
 
541
      else if (pformat == PIPE_FORMAT_Z16_UNORM) {
498
542
         for (i = 0; i < height; i++) {
499
543
            GLushort ztemp[MAX_WIDTH];
500
544
            GLfloat zfloat[MAX_WIDTH];
509
553
            dst += dstStride;
510
554
         }
511
555
      }
512
 
      else if (trans->resource->format == PIPE_FORMAT_Z32_UNORM) {
 
556
      else if (pformat == PIPE_FORMAT_Z32_UNORM) {
513
557
         for (i = 0; i < height; i++) {
514
558
            GLuint ztemp[MAX_WIDTH];
515
559
            GLfloat zfloat[MAX_WIDTH];
528
572
         /* RGBA format */
529
573
         /* Do a row at a time to flip image data vertically */
530
574
         for (i = 0; i < height; i++) {
531
 
            pipe_get_tile_rgba(pipe, trans, 0, y, width, 1, df);
 
575
            pipe_get_tile_rgba_format(pipe, trans, 0, y, width, 1,
 
576
                                      pformat, df);
532
577
            y += yStep;
533
578
            df += dfStride;
534
579
            if (!dfStride) {