1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * glReadPixels interface to pipe
36 #include "main/imports.h"
37 #include "main/context.h"
38 #include "main/image.h"
40 #include "pipe/p_context.h"
41 #include "pipe/p_defines.h"
42 #include "st_context.h"
43 #include "st_cb_readpixels.h"
44 #include "st_cb_fbo.h"
45 #include "st_format.h"
46 #include "st_public.h"
50 * Do glReadPixels by getting rows from the framebuffer surface with
51 * get_tile(). Convert to requested format/type with Mesa image routines.
52 * Image transfer ops are done in software too.
55 st_readpixels(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei width
, GLsizei height
,
56 GLenum format
, GLenum type
,
57 const struct gl_pixelstore_attrib
*pack
,
60 struct pipe_context
*pipe
= ctx
->st
->pipe
;
61 GLfloat temp
[MAX_WIDTH
][4];
62 const GLbitfield transferOps
= ctx
->_ImageTransferState
;
63 GLint i
, yStep
, dfStride
;
65 struct st_renderbuffer
*strb
;
66 struct gl_pixelstore_attrib clippedPacking
= *pack
;
68 /* XXX convolution not done yet */
69 assert((transferOps
& IMAGE_CONVOLUTION_BIT
) == 0);
71 /* Do all needed clipping here, so that we can forget about it later */
72 if (!_mesa_clip_readpixels(ctx
, &x
, &y
, &width
, &height
, &clippedPacking
)) {
73 /* The ReadPixels region is totally outside the window bounds */
77 /* make sure rendering has completed */
78 pipe
->flush(pipe
, 0x0);
80 if (pack
->BufferObj
&& pack
->BufferObj
->Name
) {
81 /* reading into a PBO */
85 /* reading into user memory/buffer */
89 strb
= st_renderbuffer(ctx
->ReadBuffer
->_ColorReadBuffer
);
93 pipe
->region_map(pipe
, strb
->surface
->region
);
95 if (format
== GL_RGBA
&& type
== GL_FLOAT
) {
96 /* write tile(row) directly into user's buffer */
97 df
= (GLfloat
*) _mesa_image_address2d(&clippedPacking
, dest
, width
,
98 height
, format
, type
, 0, 0);
102 /* write tile(row) into temp row buffer */
103 df
= (GLfloat
*) temp
;
107 /* determine bottom-to-top vs. top-to-bottom order */
108 if (st_fb_orientation(ctx
->ReadBuffer
) == Y_0_TOP
) {
109 y
= strb
->Base
.Height
- 1 - y
;
116 /* Do a row at a time to flip image data vertically */
117 for (i
= 0; i
< height
; i
++) {
118 strb
->surface
->get_tile(strb
->surface
, x
, y
, width
, 1, df
);
122 /* convert GLfloat to user's format/type */
123 GLvoid
*dst
= _mesa_image_address2d(&clippedPacking
, dest
, width
,
124 height
, format
, type
, i
, 0);
125 _mesa_pack_rgba_span_float(ctx
, width
, temp
, format
, type
, dst
,
126 &clippedPacking
, transferOps
);
130 pipe
->region_unmap(pipe
, strb
->surface
->region
);
134 void st_init_readpixels_functions(struct dd_function_table
*functions
)
136 functions
->ReadPixels
= st_readpixels
;