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.
30 #include "histogram.h"
36 #include "s_context.h"
39 #include "s_stencil.h"
45 * Determine if there's overlap in an image copy.
46 * This test also compensates for the fact that copies are done from
47 * bottom to top and overlaps can sometimes be handled correctly
48 * without making a temporary image copy.
49 * \return GL_TRUE if the regions overlap, GL_FALSE otherwise.
52 regions_overlap(GLint srcx
, GLint srcy
,
53 GLint dstx
, GLint dsty
,
54 GLint width
, GLint height
,
55 GLfloat zoomX
, GLfloat zoomY
)
57 if (zoomX
== 1.0 && zoomY
== 1.0) {
59 if (srcx
>= dstx
+ width
|| (srcx
+ width
<= dstx
)) {
62 else if (srcy
< dsty
) { /* this is OK */
65 else if (srcy
> dsty
+ height
) {
73 /* add one pixel of slop when zooming, just to be safe */
74 if ((srcx
> dstx
+ (width
* zoomX
) + 1) || (srcx
+ width
+ 1 < dstx
)) {
77 else if ((srcy
< dsty
) && (srcy
+ height
< dsty
+ (height
* zoomY
))) {
80 else if ((srcy
> dsty
) && (srcy
+ height
> dsty
+ (height
* zoomY
))) {
91 * RGBA copypixels with convolution.
94 copy_conv_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
95 GLint width
, GLint height
, GLint destx
, GLint desty
)
98 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
99 const GLbitfield transferOps
= ctx
->_ImageTransferState
;
100 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
101 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
102 GLfloat
*dest
, *tmpImage
, *convImage
;
105 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
106 _swrast_span_default_attribs(ctx
, &span
);
108 /* allocate space for GLfloat image */
109 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
111 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
114 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
116 _mesa_free(tmpImage
);
117 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
121 /* read source image as float/RGBA */
123 for (row
= 0; row
< height
; row
++) {
124 _swrast_read_rgba_span(ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
125 width
, srcx
, srcy
+ row
, GL_FLOAT
, dest
);
129 /* do the image transfer ops which preceed convolution */
130 for (row
= 0; row
< height
; row
++) {
131 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (tmpImage
+ row
* width
* 4);
132 _mesa_apply_rgba_transfer_ops(ctx
,
133 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
,
138 if (ctx
->Pixel
.Convolution2DEnabled
) {
139 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
142 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
143 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
145 _mesa_free(tmpImage
);
147 /* do remaining post-convolution image transfer ops */
148 for (row
= 0; row
< height
; row
++) {
149 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (convImage
+ row
* width
* 4);
150 _mesa_apply_rgba_transfer_ops(ctx
,
151 transferOps
& IMAGE_POST_CONVOLUTION_BITS
,
156 /* write the new image */
157 for (row
= 0; row
< height
; row
++) {
158 const GLfloat
*src
= convImage
+ row
* width
* 4;
159 GLvoid
*rgba
= (GLvoid
*) span
.array
->attribs
[FRAG_ATTRIB_COL0
];
161 /* copy convolved colors into span array */
162 _mesa_memcpy(rgba
, src
, width
* 4 * sizeof(GLfloat
));
166 span
.y
= desty
+ row
;
168 span
.array
->ChanType
= GL_FLOAT
;
170 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
, rgba
);
173 _swrast_write_rgba_span(ctx
, &span
);
177 span
.array
->ChanType
= CHAN_TYPE
;
180 _mesa_free(convImage
);
188 copy_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
189 GLint width
, GLint height
, GLint destx
, GLint desty
)
191 GLfloat
*tmpImage
, *p
;
192 GLint sy
, dy
, stepy
, row
;
193 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
195 GLuint transferOps
= ctx
->_ImageTransferState
;
198 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
199 /* no readbuffer - OK */
203 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
204 copy_conv_rgba_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
207 else if (ctx
->Pixel
.Convolution1DEnabled
) {
208 /* make sure we don't apply 1D convolution */
209 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
210 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
213 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
214 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
215 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
218 overlapping
= GL_FALSE
;
221 /* Determine if copy should be done bottom-to-top or top-to-bottom */
222 if (!overlapping
&& srcy
< desty
) {
223 /* top-down max-to-min */
224 sy
= srcy
+ height
- 1;
225 dy
= desty
+ height
- 1;
229 /* bottom-up min-to-max */
235 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
236 _swrast_span_default_attribs(ctx
, &span
);
239 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
) * 4);
241 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
244 /* read the source image as RGBA/float */
246 for (row
= 0; row
< height
; row
++) {
247 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
248 width
, srcx
, sy
+ row
, GL_FLOAT
, p
);
254 tmpImage
= NULL
; /* silence compiler warnings */
258 ASSERT(width
< MAX_WIDTH
);
260 for (row
= 0; row
< height
; row
++, sy
+= stepy
, dy
+= stepy
) {
261 GLvoid
*rgba
= span
.array
->attribs
[FRAG_ATTRIB_COL0
];
263 /* Get row/span of source pixels */
265 /* get from buffered image */
266 _mesa_memcpy(rgba
, p
, width
* sizeof(GLfloat
) * 4);
270 /* get from framebuffer */
271 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
272 width
, srcx
, sy
, GL_FLOAT
, rgba
);
276 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, width
,
277 (GLfloat (*)[4]) rgba
);
280 /* Write color span */
284 span
.array
->ChanType
= GL_FLOAT
;
286 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
, rgba
);
289 _swrast_write_rgba_span(ctx
, &span
);
293 span
.array
->ChanType
= CHAN_TYPE
; /* restore */
296 _mesa_free(tmpImage
);
301 copy_ci_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
302 GLint width
, GLint height
,
303 GLint destx
, GLint desty
)
308 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
312 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
313 /* no readbuffer - OK */
317 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
318 _swrast_span_default_attribs(ctx
, &span
);
320 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
321 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
322 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
325 overlapping
= GL_FALSE
;
328 /* Determine if copy should be bottom-to-top or top-to-bottom */
329 if (!overlapping
&& srcy
< desty
) {
330 /* top-down max-to-min */
331 sy
= srcy
+ height
- 1;
332 dy
= desty
+ height
- 1;
336 /* bottom-up min-to-max */
344 tmpImage
= (GLuint
*) _mesa_malloc(width
* height
* sizeof(GLuint
));
346 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
351 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
352 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
353 width
, srcx
, ssy
, p
);
359 tmpImage
= NULL
; /* silence compiler warning */
363 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
364 /* Get color indexes */
366 _mesa_memcpy(span
.array
->index
, p
, width
* sizeof(GLuint
));
370 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
371 width
, srcx
, sy
, span
.array
->index
);
374 if (ctx
->_ImageTransferState
)
375 _mesa_apply_ci_transfer_ops(ctx
, ctx
->_ImageTransferState
,
376 width
, span
.array
->index
);
378 /* write color indexes */
383 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
385 _swrast_write_index_span(ctx
, &span
);
389 _mesa_free(tmpImage
);
394 * Convert floating point Z values to integer Z values with pixel transfer's
398 scale_and_bias_z(GLcontext
*ctx
, GLuint width
,
399 const GLfloat depth
[], GLuint z
[])
401 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
404 if (depthMax
<= 0xffffff &&
405 ctx
->Pixel
.DepthScale
== 1.0 &&
406 ctx
->Pixel
.DepthBias
== 0.0) {
407 /* no scale or bias and no clamping and no worry of overflow */
408 const GLfloat depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
409 for (i
= 0; i
< width
; i
++) {
410 z
[i
] = (GLuint
) (depth
[i
] * depthMaxF
);
414 /* need to be careful with overflow */
415 const GLdouble depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
416 for (i
= 0; i
< width
; i
++) {
417 GLdouble d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
418 d
= CLAMP(d
, 0.0, 1.0) * depthMaxF
;
433 copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
434 GLint width
, GLint height
,
435 GLint destx
, GLint desty
)
437 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
438 struct gl_renderbuffer
*readRb
= fb
->_DepthBuffer
;
439 GLfloat
*p
, *tmpImage
;
442 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
447 /* no readbuffer - OK */
451 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
452 _swrast_span_default_attribs(ctx
, &span
);
454 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
455 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
456 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
459 overlapping
= GL_FALSE
;
462 /* Determine if copy should be bottom-to-top or top-to-bottom */
463 if (!overlapping
&& srcy
< desty
) {
464 /* top-down max-to-min */
465 sy
= srcy
+ height
- 1;
466 dy
= desty
+ height
- 1;
470 /* bottom-up min-to-max */
478 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
480 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
484 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
485 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, ssy
, p
);
491 tmpImage
= NULL
; /* silence compiler warning */
495 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
496 GLfloat depth
[MAX_WIDTH
];
497 /* get depth values */
499 _mesa_memcpy(depth
, p
, width
* sizeof(GLfloat
));
503 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, sy
, depth
);
506 /* apply scale and bias */
507 scale_and_bias_z(ctx
, width
, depth
, span
.array
->z
);
509 /* write depth values */
513 if (fb
->Visual
.rgbMode
) {
515 _swrast_write_zoomed_depth_span(ctx
, destx
, desty
, &span
);
517 _swrast_write_rgba_span(ctx
, &span
);
521 _swrast_write_zoomed_depth_span(ctx
, destx
, desty
, &span
);
523 _swrast_write_index_span(ctx
, &span
);
528 _mesa_free(tmpImage
);
534 copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
535 GLint width
, GLint height
,
536 GLint destx
, GLint desty
)
538 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
539 struct gl_renderbuffer
*rb
= fb
->_StencilBuffer
;
542 GLstencil
*p
, *tmpImage
;
543 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
547 /* no readbuffer - OK */
551 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
552 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
553 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
556 overlapping
= GL_FALSE
;
559 /* Determine if copy should be bottom-to-top or top-to-bottom */
560 if (!overlapping
&& srcy
< desty
) {
561 /* top-down max-to-min */
562 sy
= srcy
+ height
- 1;
563 dy
= desty
+ height
- 1;
567 /* bottom-up min-to-max */
575 tmpImage
= (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
577 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
581 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
582 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, ssy
, p
);
588 tmpImage
= NULL
; /* silence compiler warning */
592 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
593 GLstencil stencil
[MAX_WIDTH
];
595 /* Get stencil values */
597 _mesa_memcpy(stencil
, p
, width
* sizeof(GLstencil
));
601 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, sy
, stencil
);
604 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
606 /* Write stencil values */
608 _swrast_write_zoomed_stencil_span(ctx
, destx
, desty
, width
,
612 _swrast_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
617 _mesa_free(tmpImage
);
622 * This isn't terribly efficient. If a driver really has combined
623 * depth/stencil buffers the driver should implement an optimized
624 * CopyPixels function.
627 copy_depth_stencil_pixels(GLcontext
*ctx
,
628 const GLint srcX
, const GLint srcY
,
629 const GLint width
, const GLint height
,
630 const GLint destX
, const GLint destY
)
632 struct gl_renderbuffer
*stencilReadRb
, *depthReadRb
, *depthDrawRb
;
635 GLstencil
*tempStencilImage
= NULL
, *stencilPtr
= NULL
;
636 GLfloat
*tempDepthImage
= NULL
, *depthPtr
= NULL
;
637 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
638 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
639 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
640 const GLboolean scaleOrBias
641 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
644 depthDrawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
645 depthReadRb
= ctx
->ReadBuffer
->_DepthBuffer
;
646 stencilReadRb
= ctx
->ReadBuffer
->_StencilBuffer
;
650 ASSERT(stencilReadRb
);
652 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
653 overlapping
= regions_overlap(srcX
, srcY
, destX
, destY
, width
, height
,
654 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
657 overlapping
= GL_FALSE
;
660 /* Determine if copy should be bottom-to-top or top-to-bottom */
661 if (!overlapping
&& srcY
< destY
) {
662 /* top-down max-to-min */
663 sy
= srcY
+ height
- 1;
664 dy
= destY
+ height
- 1;
668 /* bottom-up min-to-max */
677 if (stencilMask
!= 0x0) {
679 = (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
680 if (!tempStencilImage
) {
681 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
685 /* get copy of stencil pixels */
686 stencilPtr
= tempStencilImage
;
687 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
688 _swrast_read_stencil_span(ctx
, stencilReadRb
,
689 width
, srcX
, ssy
, stencilPtr
);
692 stencilPtr
= tempStencilImage
;
695 if (ctx
->Depth
.Mask
) {
697 = (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
698 if (!tempDepthImage
) {
699 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
700 _mesa_free(tempStencilImage
);
704 /* get copy of depth pixels */
705 depthPtr
= tempDepthImage
;
706 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
707 _swrast_read_depth_span_float(ctx
, depthReadRb
,
708 width
, srcX
, ssy
, depthPtr
);
711 depthPtr
= tempDepthImage
;
715 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
716 if (stencilMask
!= 0x0) {
717 GLstencil stencil
[MAX_WIDTH
];
719 /* Get stencil values */
721 _mesa_memcpy(stencil
, stencilPtr
, width
* sizeof(GLstencil
));
725 _swrast_read_stencil_span(ctx
, stencilReadRb
,
726 width
, srcX
, sy
, stencil
);
729 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
733 _swrast_write_zoomed_stencil_span(ctx
, destX
, destY
, width
,
737 _swrast_write_stencil_span( ctx
, width
, destX
, dy
, stencil
);
741 if (ctx
->Depth
.Mask
) {
742 GLfloat depth
[MAX_WIDTH
];
743 GLuint zVals32
[MAX_WIDTH
];
744 GLushort zVals16
[MAX_WIDTH
];
748 /* get depth values */
750 _mesa_memcpy(depth
, depthPtr
, width
* sizeof(GLfloat
));
754 _swrast_read_depth_span_float(ctx
, depthReadRb
,
755 width
, srcX
, sy
, depth
);
760 _mesa_scale_and_bias_depth(ctx
, width
, depth
);
762 /* convert to integer Z values */
763 if (depthDrawRb
->DataType
== GL_UNSIGNED_SHORT
) {
765 for (k
= 0; k
< width
; k
++)
766 zVals16
[k
] = (GLushort
) (depth
[k
] * depthScale
);
772 for (k
= 0; k
< width
; k
++)
773 zVals32
[k
] = (GLuint
) (depth
[k
] * depthScale
);
780 _swrast_write_zoomed_z_span(ctx
, destX
, destY
, width
,
784 _swrast_put_row(ctx
, depthDrawRb
, width
, destX
, dy
, zVals
, zBytes
);
789 if (tempStencilImage
)
790 _mesa_free(tempStencilImage
);
793 _mesa_free(tempDepthImage
);
799 * Try to do a fast copy pixels.
802 fast_copy_pixels(GLcontext
*ctx
,
803 GLint srcX
, GLint srcY
, GLsizei width
, GLsizei height
,
804 GLint dstX
, GLint dstY
, GLenum type
)
806 struct gl_framebuffer
*srcFb
= ctx
->ReadBuffer
;
807 struct gl_framebuffer
*dstFb
= ctx
->DrawBuffer
;
808 struct gl_renderbuffer
*srcRb
, *dstRb
;
811 if (SWRAST_CONTEXT(ctx
)->_RasterMask
!= 0x0 ||
812 ctx
->Pixel
.ZoomX
!= 1.0F
||
813 ctx
->Pixel
.ZoomY
!= 1.0F
||
814 ctx
->_ImageTransferState
) {
815 /* can't handle these */
819 if (type
== GL_COLOR
) {
820 if (dstFb
->_NumColorDrawBuffers
[0] != 1)
822 srcRb
= srcFb
->_ColorReadBuffer
;
823 dstRb
= dstFb
->_ColorDrawBuffers
[0][0];
825 else if (type
== GL_STENCIL
) {
826 srcRb
= srcFb
->_StencilBuffer
;
827 dstRb
= dstFb
->_StencilBuffer
;
829 else if (type
== GL_DEPTH
) {
830 srcRb
= srcFb
->_DepthBuffer
;
831 dstRb
= dstFb
->_DepthBuffer
;
834 ASSERT(type
== GL_DEPTH_STENCIL_EXT
);
836 srcRb
= srcFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
837 dstRb
= dstFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
840 /* src and dst renderbuffers must be same format and type */
841 if (!srcRb
|| !dstRb
||
842 srcRb
->DataType
!= dstRb
->DataType
||
843 srcRb
->_BaseFormat
!= dstRb
->_BaseFormat
) {
847 /* clipping not supported */
848 if (srcX
< 0 || srcX
+ width
> (GLint
) srcFb
->Width
||
849 srcY
< 0 || srcY
+ height
> (GLint
) srcFb
->Height
||
850 dstX
< dstFb
->_Xmin
|| dstX
+ width
> dstFb
->_Xmax
||
851 dstY
< dstFb
->_Ymin
|| dstY
+ height
> dstFb
->_Ymax
) {
855 /* overlapping src/dst doesn't matter, just determine Y direction */
857 /* top-down max-to-min */
858 srcY
= srcY
+ height
- 1;
859 dstY
= dstY
+ height
- 1;
863 /* bottom-up min-to-max */
867 for (row
= 0; row
< height
; row
++) {
868 GLuint temp
[MAX_WIDTH
][4];
869 srcRb
->GetRow(ctx
, srcRb
, width
, srcX
, srcY
, temp
);
870 dstRb
->PutRow(ctx
, dstRb
, width
, dstX
, dstY
, temp
, NULL
);
880 * Do software-based glCopyPixels.
881 * By time we get here, all parameters will have been error-checked.
884 _swrast_CopyPixels( GLcontext
*ctx
,
885 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
886 GLint destx
, GLint desty
, GLenum type
)
888 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
889 RENDER_START(swrast
,ctx
);
891 if (swrast
->NewState
)
892 _swrast_validate_derived( ctx
);
894 if (!fast_copy_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
)) {
897 if (ctx
->Visual
.rgbMode
) {
898 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
901 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
905 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
908 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
910 case GL_DEPTH_STENCIL_EXT
:
911 copy_depth_stencil_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
914 _mesa_problem(ctx
, "unexpected type in _swrast_CopyPixels");
918 RENDER_FINISH(swrast
,ctx
);