2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
26 #include "main/glheader.h"
27 #include "main/context.h"
28 #include "main/colormac.h"
29 #include "main/condrender.h"
30 #include "main/convolve.h"
31 #include "main/image.h"
32 #include "main/macros.h"
33 #include "main/imports.h"
35 #include "s_context.h"
38 #include "s_stencil.h"
44 * Determine if there's overlap in an image copy.
45 * This test also compensates for the fact that copies are done from
46 * bottom to top and overlaps can sometimes be handled correctly
47 * without making a temporary image copy.
48 * \return GL_TRUE if the regions overlap, GL_FALSE otherwise.
51 regions_overlap(GLint srcx
, GLint srcy
,
52 GLint dstx
, GLint dsty
,
53 GLint width
, GLint height
,
54 GLfloat zoomX
, GLfloat zoomY
)
56 if (zoomX
== 1.0 && zoomY
== 1.0) {
58 if (srcx
>= dstx
+ width
|| (srcx
+ width
<= dstx
)) {
61 else if (srcy
< dsty
) { /* this is OK */
64 else if (srcy
> dsty
+ height
) {
72 /* add one pixel of slop when zooming, just to be safe */
73 if (srcx
> (dstx
+ ((zoomX
> 0.0F
) ? (width
* zoomX
+ 1.0F
) : 0.0F
))) {
74 /* src is completely right of dest */
77 else if (srcx
+ width
+ 1.0F
< dstx
+ ((zoomX
> 0.0F
) ? 0.0F
: (width
* zoomX
))) {
78 /* src is completely left of dest */
81 else if ((srcy
< dsty
) && (srcy
+ height
< dsty
+ (height
* zoomY
))) {
82 /* src is completely below dest */
85 else if ((srcy
> dsty
) && (srcy
+ height
> dsty
+ (height
* zoomY
))) {
86 /* src is completely above dest */
97 * RGBA copypixels with convolution.
100 copy_conv_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
101 GLint width
, GLint height
, GLint destx
, GLint desty
)
104 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
105 const GLbitfield transferOps
= ctx
->_ImageTransferState
;
106 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
107 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
108 GLfloat
*dest
, *tmpImage
, *convImage
;
111 INIT_SPAN(span
, GL_BITMAP
);
112 _swrast_span_default_attribs(ctx
, &span
);
113 span
.arrayMask
= SPAN_RGBA
;
114 span
.arrayAttribs
= FRAG_BIT_COL0
;
116 /* allocate space for GLfloat image */
117 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
119 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
122 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
124 _mesa_free(tmpImage
);
125 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
129 /* read source image as float/RGBA */
131 for (row
= 0; row
< height
; row
++) {
132 _swrast_read_rgba_span(ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
133 width
, srcx
, srcy
+ row
, GL_FLOAT
, dest
);
137 /* do the image transfer ops which preceed convolution */
138 for (row
= 0; row
< height
; row
++) {
139 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (tmpImage
+ row
* width
* 4);
140 _mesa_apply_rgba_transfer_ops(ctx
,
141 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
,
146 if (ctx
->Pixel
.Convolution2DEnabled
) {
147 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
150 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
151 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
153 _mesa_free(tmpImage
);
155 /* do remaining post-convolution image transfer ops */
156 for (row
= 0; row
< height
; row
++) {
157 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (convImage
+ row
* width
* 4);
158 _mesa_apply_rgba_transfer_ops(ctx
,
159 transferOps
& IMAGE_POST_CONVOLUTION_BITS
,
164 /* write the new image */
165 for (row
= 0; row
< height
; row
++) {
166 const GLfloat
*src
= convImage
+ row
* width
* 4;
167 GLfloat
*rgba
= (GLfloat
*) span
.array
->attribs
[FRAG_ATTRIB_COL0
];
169 /* copy convolved colors into span array */
170 _mesa_memcpy(rgba
, src
, width
* 4 * sizeof(GLfloat
));
174 span
.y
= desty
+ row
;
176 span
.array
->ChanType
= GL_FLOAT
;
178 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
, rgba
);
181 _swrast_write_rgba_span(ctx
, &span
);
185 span
.array
->ChanType
= CHAN_TYPE
;
188 _mesa_free(convImage
);
196 copy_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
197 GLint width
, GLint height
, GLint destx
, GLint desty
)
199 GLfloat
*tmpImage
, *p
;
200 GLint sy
, dy
, stepy
, row
;
201 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
203 GLuint transferOps
= ctx
->_ImageTransferState
;
206 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
207 /* no readbuffer - OK */
211 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
212 copy_conv_rgba_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
215 else if (ctx
->Pixel
.Convolution1DEnabled
) {
216 /* make sure we don't apply 1D convolution */
217 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
218 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
221 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
222 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
223 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
226 overlapping
= GL_FALSE
;
229 /* Determine if copy should be done bottom-to-top or top-to-bottom */
230 if (!overlapping
&& srcy
< desty
) {
231 /* top-down max-to-min */
232 sy
= srcy
+ height
- 1;
233 dy
= desty
+ height
- 1;
237 /* bottom-up min-to-max */
243 INIT_SPAN(span
, GL_BITMAP
);
244 _swrast_span_default_attribs(ctx
, &span
);
245 span
.arrayMask
= SPAN_RGBA
;
246 span
.arrayAttribs
= FRAG_BIT_COL0
; /* we'll fill in COL0 attrib values */
249 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
) * 4);
251 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
254 /* read the source image as RGBA/float */
256 for (row
= 0; row
< height
; row
++) {
257 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
258 width
, srcx
, sy
+ row
, GL_FLOAT
, p
);
264 tmpImage
= NULL
; /* silence compiler warnings */
268 ASSERT(width
< MAX_WIDTH
);
270 for (row
= 0; row
< height
; row
++, sy
+= stepy
, dy
+= stepy
) {
271 GLvoid
*rgba
= span
.array
->attribs
[FRAG_ATTRIB_COL0
];
273 /* Get row/span of source pixels */
275 /* get from buffered image */
276 _mesa_memcpy(rgba
, p
, width
* sizeof(GLfloat
) * 4);
280 /* get from framebuffer */
281 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
282 width
, srcx
, sy
, GL_FLOAT
, rgba
);
286 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, width
,
287 (GLfloat (*)[4]) rgba
);
290 /* Write color span */
294 span
.array
->ChanType
= GL_FLOAT
;
296 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
, rgba
);
299 _swrast_write_rgba_span(ctx
, &span
);
303 span
.array
->ChanType
= CHAN_TYPE
; /* restore */
306 _mesa_free(tmpImage
);
311 copy_ci_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
312 GLint width
, GLint height
,
313 GLint destx
, GLint desty
)
318 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
322 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
323 /* no readbuffer - OK */
327 INIT_SPAN(span
, GL_BITMAP
);
328 _swrast_span_default_attribs(ctx
, &span
);
329 span
.arrayMask
= SPAN_INDEX
;
331 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
332 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
333 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
336 overlapping
= GL_FALSE
;
339 /* Determine if copy should be bottom-to-top or top-to-bottom */
340 if (!overlapping
&& srcy
< desty
) {
341 /* top-down max-to-min */
342 sy
= srcy
+ height
- 1;
343 dy
= desty
+ height
- 1;
347 /* bottom-up min-to-max */
355 tmpImage
= (GLuint
*) _mesa_malloc(width
* height
* sizeof(GLuint
));
357 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
362 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
363 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
364 width
, srcx
, ssy
, p
);
370 tmpImage
= NULL
; /* silence compiler warning */
374 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
375 /* Get color indexes */
377 _mesa_memcpy(span
.array
->index
, p
, width
* sizeof(GLuint
));
381 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
382 width
, srcx
, sy
, span
.array
->index
);
385 if (ctx
->_ImageTransferState
)
386 _mesa_apply_ci_transfer_ops(ctx
, ctx
->_ImageTransferState
,
387 width
, span
.array
->index
);
389 /* write color indexes */
394 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
396 _swrast_write_index_span(ctx
, &span
);
400 _mesa_free(tmpImage
);
405 * Convert floating point Z values to integer Z values with pixel transfer's
409 scale_and_bias_z(GLcontext
*ctx
, GLuint width
,
410 const GLfloat depth
[], GLuint z
[])
412 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
415 if (depthMax
<= 0xffffff &&
416 ctx
->Pixel
.DepthScale
== 1.0 &&
417 ctx
->Pixel
.DepthBias
== 0.0) {
418 /* no scale or bias and no clamping and no worry of overflow */
419 const GLfloat depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
420 for (i
= 0; i
< width
; i
++) {
421 z
[i
] = (GLuint
) (depth
[i
] * depthMaxF
);
425 /* need to be careful with overflow */
426 const GLdouble depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
427 for (i
= 0; i
< width
; i
++) {
428 GLdouble d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
429 d
= CLAMP(d
, 0.0, 1.0) * depthMaxF
;
444 copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
445 GLint width
, GLint height
,
446 GLint destx
, GLint desty
)
448 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
449 struct gl_renderbuffer
*readRb
= fb
->_DepthBuffer
;
450 GLfloat
*p
, *tmpImage
;
453 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
458 /* no readbuffer - OK */
462 INIT_SPAN(span
, GL_BITMAP
);
463 _swrast_span_default_attribs(ctx
, &span
);
464 span
.arrayMask
= SPAN_Z
;
466 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
467 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
468 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
471 overlapping
= GL_FALSE
;
474 /* Determine if copy should be bottom-to-top or top-to-bottom */
475 if (!overlapping
&& srcy
< desty
) {
476 /* top-down max-to-min */
477 sy
= srcy
+ height
- 1;
478 dy
= desty
+ height
- 1;
482 /* bottom-up min-to-max */
490 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
492 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
496 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
497 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, ssy
, p
);
503 tmpImage
= NULL
; /* silence compiler warning */
507 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
508 GLfloat depth
[MAX_WIDTH
];
509 /* get depth values */
511 _mesa_memcpy(depth
, p
, width
* sizeof(GLfloat
));
515 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, sy
, depth
);
518 /* apply scale and bias */
519 scale_and_bias_z(ctx
, width
, depth
, span
.array
->z
);
521 /* write depth values */
525 if (fb
->Visual
.rgbMode
) {
527 _swrast_write_zoomed_depth_span(ctx
, destx
, desty
, &span
);
529 _swrast_write_rgba_span(ctx
, &span
);
533 _swrast_write_zoomed_depth_span(ctx
, destx
, desty
, &span
);
535 _swrast_write_index_span(ctx
, &span
);
540 _mesa_free(tmpImage
);
546 copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
547 GLint width
, GLint height
,
548 GLint destx
, GLint desty
)
550 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
551 struct gl_renderbuffer
*rb
= fb
->_StencilBuffer
;
554 GLstencil
*p
, *tmpImage
;
555 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
559 /* no readbuffer - OK */
563 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
564 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
565 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
568 overlapping
= GL_FALSE
;
571 /* Determine if copy should be bottom-to-top or top-to-bottom */
572 if (!overlapping
&& srcy
< desty
) {
573 /* top-down max-to-min */
574 sy
= srcy
+ height
- 1;
575 dy
= desty
+ height
- 1;
579 /* bottom-up min-to-max */
587 tmpImage
= (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
589 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
593 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
594 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, ssy
, p
);
600 tmpImage
= NULL
; /* silence compiler warning */
604 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
605 GLstencil stencil
[MAX_WIDTH
];
607 /* Get stencil values */
609 _mesa_memcpy(stencil
, p
, width
* sizeof(GLstencil
));
613 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, sy
, stencil
);
616 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
618 /* Write stencil values */
620 _swrast_write_zoomed_stencil_span(ctx
, destx
, desty
, width
,
624 _swrast_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
629 _mesa_free(tmpImage
);
634 * This isn't terribly efficient. If a driver really has combined
635 * depth/stencil buffers the driver should implement an optimized
636 * CopyPixels function.
639 copy_depth_stencil_pixels(GLcontext
*ctx
,
640 const GLint srcX
, const GLint srcY
,
641 const GLint width
, const GLint height
,
642 const GLint destX
, const GLint destY
)
644 struct gl_renderbuffer
*stencilReadRb
, *depthReadRb
, *depthDrawRb
;
647 GLstencil
*tempStencilImage
= NULL
, *stencilPtr
= NULL
;
648 GLfloat
*tempDepthImage
= NULL
, *depthPtr
= NULL
;
649 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
650 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
651 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
652 const GLboolean scaleOrBias
653 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
656 depthDrawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
657 depthReadRb
= ctx
->ReadBuffer
->_DepthBuffer
;
658 stencilReadRb
= ctx
->ReadBuffer
->_StencilBuffer
;
662 ASSERT(stencilReadRb
);
664 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
665 overlapping
= regions_overlap(srcX
, srcY
, destX
, destY
, width
, height
,
666 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
669 overlapping
= GL_FALSE
;
672 /* Determine if copy should be bottom-to-top or top-to-bottom */
673 if (!overlapping
&& srcY
< destY
) {
674 /* top-down max-to-min */
675 sy
= srcY
+ height
- 1;
676 dy
= destY
+ height
- 1;
680 /* bottom-up min-to-max */
689 if (stencilMask
!= 0x0) {
691 = (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
692 if (!tempStencilImage
) {
693 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
697 /* get copy of stencil pixels */
698 stencilPtr
= tempStencilImage
;
699 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
700 _swrast_read_stencil_span(ctx
, stencilReadRb
,
701 width
, srcX
, ssy
, stencilPtr
);
704 stencilPtr
= tempStencilImage
;
707 if (ctx
->Depth
.Mask
) {
709 = (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
710 if (!tempDepthImage
) {
711 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
712 _mesa_free(tempStencilImage
);
716 /* get copy of depth pixels */
717 depthPtr
= tempDepthImage
;
718 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
719 _swrast_read_depth_span_float(ctx
, depthReadRb
,
720 width
, srcX
, ssy
, depthPtr
);
723 depthPtr
= tempDepthImage
;
727 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
728 if (stencilMask
!= 0x0) {
729 GLstencil stencil
[MAX_WIDTH
];
731 /* Get stencil values */
733 _mesa_memcpy(stencil
, stencilPtr
, width
* sizeof(GLstencil
));
737 _swrast_read_stencil_span(ctx
, stencilReadRb
,
738 width
, srcX
, sy
, stencil
);
741 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
745 _swrast_write_zoomed_stencil_span(ctx
, destX
, destY
, width
,
749 _swrast_write_stencil_span( ctx
, width
, destX
, dy
, stencil
);
753 if (ctx
->Depth
.Mask
) {
754 GLfloat depth
[MAX_WIDTH
];
755 GLuint zVals32
[MAX_WIDTH
];
756 GLushort zVals16
[MAX_WIDTH
];
760 /* get depth values */
762 _mesa_memcpy(depth
, depthPtr
, width
* sizeof(GLfloat
));
766 _swrast_read_depth_span_float(ctx
, depthReadRb
,
767 width
, srcX
, sy
, depth
);
772 _mesa_scale_and_bias_depth(ctx
, width
, depth
);
774 /* convert to integer Z values */
775 if (depthDrawRb
->DataType
== GL_UNSIGNED_SHORT
) {
777 for (k
= 0; k
< width
; k
++)
778 zVals16
[k
] = (GLushort
) (depth
[k
] * depthScale
);
784 for (k
= 0; k
< width
; k
++)
785 zVals32
[k
] = (GLuint
) (depth
[k
] * depthScale
);
792 _swrast_write_zoomed_z_span(ctx
, destX
, destY
, width
,
796 _swrast_put_row(ctx
, depthDrawRb
, width
, destX
, dy
, zVals
, zBytes
);
801 if (tempStencilImage
)
802 _mesa_free(tempStencilImage
);
805 _mesa_free(tempDepthImage
);
811 * Try to do a fast copy pixels.
814 fast_copy_pixels(GLcontext
*ctx
,
815 GLint srcX
, GLint srcY
, GLsizei width
, GLsizei height
,
816 GLint dstX
, GLint dstY
, GLenum type
)
818 struct gl_framebuffer
*srcFb
= ctx
->ReadBuffer
;
819 struct gl_framebuffer
*dstFb
= ctx
->DrawBuffer
;
820 struct gl_renderbuffer
*srcRb
, *dstRb
;
823 if (SWRAST_CONTEXT(ctx
)->_RasterMask
!= 0x0 ||
824 ctx
->Pixel
.ZoomX
!= 1.0F
||
825 ctx
->Pixel
.ZoomY
!= 1.0F
||
826 ctx
->_ImageTransferState
) {
827 /* can't handle these */
831 if (type
== GL_COLOR
) {
832 if (dstFb
->_NumColorDrawBuffers
!= 1)
834 srcRb
= srcFb
->_ColorReadBuffer
;
835 dstRb
= dstFb
->_ColorDrawBuffers
[0];
837 else if (type
== GL_STENCIL
) {
838 srcRb
= srcFb
->_StencilBuffer
;
839 dstRb
= dstFb
->_StencilBuffer
;
841 else if (type
== GL_DEPTH
) {
842 srcRb
= srcFb
->_DepthBuffer
;
843 dstRb
= dstFb
->_DepthBuffer
;
846 ASSERT(type
== GL_DEPTH_STENCIL_EXT
);
848 srcRb
= srcFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
849 dstRb
= dstFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
852 /* src and dst renderbuffers must be same format and type */
853 if (!srcRb
|| !dstRb
||
854 srcRb
->DataType
!= dstRb
->DataType
||
855 srcRb
->_BaseFormat
!= dstRb
->_BaseFormat
) {
859 /* clipping not supported */
860 if (srcX
< 0 || srcX
+ width
> (GLint
) srcFb
->Width
||
861 srcY
< 0 || srcY
+ height
> (GLint
) srcFb
->Height
||
862 dstX
< dstFb
->_Xmin
|| dstX
+ width
> dstFb
->_Xmax
||
863 dstY
< dstFb
->_Ymin
|| dstY
+ height
> dstFb
->_Ymax
) {
867 /* overlapping src/dst doesn't matter, just determine Y direction */
869 /* top-down max-to-min */
870 srcY
= srcY
+ height
- 1;
871 dstY
= dstY
+ height
- 1;
875 /* bottom-up min-to-max */
879 for (row
= 0; row
< height
; row
++) {
880 GLuint temp
[MAX_WIDTH
][4];
881 srcRb
->GetRow(ctx
, srcRb
, width
, srcX
, srcY
, temp
);
882 dstRb
->PutRow(ctx
, dstRb
, width
, dstX
, dstY
, temp
, NULL
);
892 * Do software-based glCopyPixels.
893 * By time we get here, all parameters will have been error-checked.
896 _swrast_CopyPixels( GLcontext
*ctx
,
897 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
898 GLint destx
, GLint desty
, GLenum type
)
900 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
901 swrast_render_start(ctx
);
903 if (!_mesa_check_conditional_render(ctx
))
904 return; /* don't copy */
906 if (swrast
->NewState
)
907 _swrast_validate_derived( ctx
);
909 if (!fast_copy_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
)) {
912 if (ctx
->Visual
.rgbMode
) {
913 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
916 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
920 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
923 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
925 case GL_DEPTH_STENCIL_EXT
:
926 copy_depth_stencil_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
929 _mesa_problem(ctx
, "unexpected type in _swrast_CopyPixels");
933 swrast_render_finish(ctx
);