2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 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
)
97 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
99 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
100 const GLbitfield transferOps
= ctx
->_ImageTransferState
;
101 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
102 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
103 GLfloat
*dest
, *tmpImage
, *convImage
;
106 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
109 _swrast_span_default_z(ctx
, &span
);
110 if (swrast
->_FogEnabled
)
111 _swrast_span_default_fog(ctx
, &span
);
114 /* allocate space for GLfloat image */
115 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
117 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
120 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
122 _mesa_free(tmpImage
);
123 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
127 /* read source image as float/RGBA */
129 for (row
= 0; row
< height
; row
++) {
130 _swrast_read_rgba_span(ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
131 width
, srcx
, srcy
+ row
, GL_FLOAT
, dest
);
135 /* do the image transfer ops which preceed convolution */
136 for (row
= 0; row
< height
; row
++) {
137 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (tmpImage
+ row
* width
* 4);
138 _mesa_apply_rgba_transfer_ops(ctx
,
139 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
,
144 if (ctx
->Pixel
.Convolution2DEnabled
) {
145 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
148 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
149 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
151 _mesa_free(tmpImage
);
153 /* do remaining post-convolution image transfer ops */
154 for (row
= 0; row
< height
; row
++) {
155 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (convImage
+ row
* width
* 4);
156 _mesa_apply_rgba_transfer_ops(ctx
,
157 transferOps
& IMAGE_POST_CONVOLUTION_BITS
,
162 /* write the new image */
163 for (row
= 0; row
< height
; row
++) {
164 const GLfloat
*src
= convImage
+ row
* width
* 4;
165 GLvoid
*rgba
= span
.array
->color
.sz1
.rgba
; /* row storage */
167 /* copy convolved colors into span array */
168 _mesa_memcpy(rgba
, src
, width
* 4 * sizeof(GLfloat
));
172 span
.y
= desty
+ row
;
174 span
.array
->ChanType
= GL_FLOAT
;
176 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
, rgba
);
179 _swrast_write_rgba_span(ctx
, &span
);
183 span
.array
->ChanType
= CHAN_TYPE
;
186 _mesa_free(convImage
);
194 copy_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
195 GLint width
, GLint height
, GLint destx
, GLint desty
)
197 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
198 GLfloat
*tmpImage
, *p
;
199 GLint sy
, dy
, stepy
, row
;
200 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
202 const GLuint transferOps
= ctx
->_ImageTransferState
;
205 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
206 /* no readbuffer - OK */
210 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
211 copy_conv_rgba_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
215 /* Determine if copy should be done bottom-to-top or top-to-bottom */
217 /* top-down max-to-min */
218 sy
= srcy
+ height
- 1;
219 dy
= desty
+ height
- 1;
223 /* bottom-up min-to-max */
229 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
230 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
231 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
234 overlapping
= GL_FALSE
;
237 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
239 _swrast_span_default_z(ctx
, &span
);
240 if (swrast
->_FogEnabled
)
241 _swrast_span_default_fog(ctx
, &span
);
244 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
) * 4);
246 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
249 /* read the source image as RGBA/float */
251 for (row
= 0; row
< height
; row
++) {
252 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
253 width
, srcx
, sy
+ row
, GL_FLOAT
, p
);
259 tmpImage
= NULL
; /* silence compiler warnings */
263 ASSERT(width
< MAX_WIDTH
);
265 for (row
= 0; row
< height
; row
++, sy
+= stepy
, dy
+= stepy
) {
266 GLvoid
*rgba
= span
.array
->color
.sz4
.rgba
;
268 /* Get row/span of source pixels */
270 /* get from buffered image */
271 _mesa_memcpy(rgba
, p
, width
* sizeof(GLfloat
) * 4);
275 /* get from framebuffer */
276 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
277 width
, srcx
, sy
, GL_FLOAT
, rgba
);
281 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, width
,
282 (GLfloat (*)[4]) rgba
);
285 /* Write color span */
289 span
.array
->ChanType
= GL_FLOAT
;
291 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
, rgba
);
294 _swrast_write_rgba_span(ctx
, &span
);
298 span
.array
->ChanType
= CHAN_TYPE
; /* restore */
301 _mesa_free(tmpImage
);
306 copy_ci_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
307 GLint width
, GLint height
,
308 GLint destx
, GLint desty
)
310 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
314 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
318 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
319 /* no readbuffer - OK */
323 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
325 /* Determine if copy should be bottom-to-top or top-to-bottom */
327 /* top-down max-to-min */
328 sy
= srcy
+ height
- 1;
329 dy
= desty
+ height
- 1;
333 /* bottom-up min-to-max */
339 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
340 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
341 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
344 overlapping
= GL_FALSE
;
348 _swrast_span_default_z(ctx
, &span
);
349 if (swrast
->_FogEnabled
)
350 _swrast_span_default_fog(ctx
, &span
);
354 tmpImage
= (GLuint
*) _mesa_malloc(width
* height
* sizeof(GLuint
));
356 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
361 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
362 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
363 width
, srcx
, ssy
, p
);
369 tmpImage
= NULL
; /* silence compiler warning */
373 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
374 /* Get color indexes */
376 _mesa_memcpy(span
.array
->index
, p
, width
* sizeof(GLuint
));
380 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
381 width
, srcx
, sy
, span
.array
->index
);
384 if (ctx
->_ImageTransferState
)
385 _mesa_apply_ci_transfer_ops(ctx
, ctx
->_ImageTransferState
,
386 width
, span
.array
->index
);
388 /* write color indexes */
393 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
395 _swrast_write_index_span(ctx
, &span
);
399 _mesa_free(tmpImage
);
404 * Convert floating point Z values to integer Z values with pixel transfer's
408 scale_and_bias_z(GLcontext
*ctx
, GLuint width
,
409 const GLfloat depth
[], GLuint z
[])
411 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
414 if (depthMax
<= 0xffffff &&
415 ctx
->Pixel
.DepthScale
== 1.0 &&
416 ctx
->Pixel
.DepthBias
== 0.0) {
417 /* no scale or bias and no clamping and no worry of overflow */
418 const GLfloat depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
419 for (i
= 0; i
< width
; i
++) {
420 z
[i
] = (GLuint
) (depth
[i
] * depthMaxF
);
424 /* need to be careful with overflow */
425 const GLdouble depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
426 for (i
= 0; i
< width
; i
++) {
427 GLdouble d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
428 d
= CLAMP(d
, 0.0, 1.0) * depthMaxF
;
443 copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
444 GLint width
, GLint height
,
445 GLint destx
, GLint desty
)
447 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
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
, 0, 0, SPAN_Z
);
464 /* Determine if copy should be bottom-to-top or top-to-bottom */
466 /* top-down max-to-min */
467 sy
= srcy
+ height
- 1;
468 dy
= desty
+ height
- 1;
472 /* bottom-up min-to-max */
478 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
479 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
480 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
483 overlapping
= GL_FALSE
;
486 _swrast_span_default_color(ctx
, &span
);
487 if (swrast
->_FogEnabled
)
488 _swrast_span_default_fog(ctx
, &span
);
492 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
494 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
498 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
499 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, ssy
, p
);
505 tmpImage
= NULL
; /* silence compiler warning */
509 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
510 GLfloat depth
[MAX_WIDTH
];
511 /* get depth values */
513 _mesa_memcpy(depth
, p
, width
* sizeof(GLfloat
));
517 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, sy
, depth
);
520 /* apply scale and bias */
521 scale_and_bias_z(ctx
, width
, depth
, span
.array
->z
);
523 /* write depth values */
527 if (fb
->Visual
.rgbMode
) {
529 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
,
532 _swrast_write_rgba_span(ctx
, &span
);
536 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
538 _swrast_write_index_span(ctx
, &span
);
543 _mesa_free(tmpImage
);
549 copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
550 GLint width
, GLint height
,
551 GLint destx
, GLint desty
)
553 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
554 struct gl_renderbuffer
*rb
= fb
->_StencilBuffer
;
557 GLstencil
*p
, *tmpImage
;
558 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
562 /* no readbuffer - OK */
566 /* Determine if copy should be bottom-to-top or top-to-bottom */
568 /* top-down max-to-min */
569 sy
= srcy
+ height
- 1;
570 dy
= desty
+ height
- 1;
574 /* bottom-up min-to-max */
580 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
581 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
582 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
585 overlapping
= GL_FALSE
;
590 tmpImage
= (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
592 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
596 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
597 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, ssy
, p
);
603 tmpImage
= NULL
; /* silence compiler warning */
607 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
608 GLstencil stencil
[MAX_WIDTH
];
610 /* Get stencil values */
612 _mesa_memcpy(stencil
, p
, width
* sizeof(GLstencil
));
616 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, sy
, stencil
);
619 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
621 /* Write stencil values */
623 _swrast_write_zoomed_stencil_span(ctx
, destx
, desty
, width
,
627 _swrast_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
632 _mesa_free(tmpImage
);
637 * This isn't terribly efficient. If a driver really has combined
638 * depth/stencil buffers the driver should implement an optimized
639 * CopyPixels function.
642 copy_depth_stencil_pixels(GLcontext
*ctx
,
643 const GLint srcX
, const GLint srcY
,
644 const GLint width
, const GLint height
,
645 const GLint destX
, const GLint destY
)
647 struct gl_renderbuffer
*stencilReadRb
, *depthReadRb
, *depthDrawRb
;
650 GLstencil
*tempStencilImage
= NULL
, *stencilPtr
= NULL
;
651 GLfloat
*tempDepthImage
= NULL
, *depthPtr
= NULL
;
652 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
653 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
654 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
655 const GLboolean scaleOrBias
656 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
659 depthDrawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
660 depthReadRb
= ctx
->ReadBuffer
->_DepthBuffer
;
661 stencilReadRb
= ctx
->ReadBuffer
->_StencilBuffer
;
665 ASSERT(stencilReadRb
);
667 /* Determine if copy should be bottom-to-top or top-to-bottom */
669 /* top-down max-to-min */
670 sy
= srcY
+ height
- 1;
671 dy
= destY
+ height
- 1;
675 /* bottom-up min-to-max */
681 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
682 overlapping
= regions_overlap(srcX
, srcY
, destX
, destY
, width
, height
,
683 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
686 overlapping
= GL_FALSE
;
692 if (stencilMask
!= 0x0) {
694 = (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
695 if (!tempStencilImage
) {
696 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
700 /* get copy of stencil pixels */
701 stencilPtr
= tempStencilImage
;
702 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
703 _swrast_read_stencil_span(ctx
, stencilReadRb
,
704 width
, srcX
, ssy
, stencilPtr
);
707 stencilPtr
= tempStencilImage
;
710 if (ctx
->Depth
.Mask
) {
712 = (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
713 if (!tempDepthImage
) {
714 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
715 _mesa_free(tempStencilImage
);
719 /* get copy of depth pixels */
720 depthPtr
= tempDepthImage
;
721 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
722 _swrast_read_depth_span_float(ctx
, depthReadRb
,
723 width
, srcX
, ssy
, depthPtr
);
726 depthPtr
= tempDepthImage
;
730 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
731 if (stencilMask
!= 0x0) {
732 GLstencil stencil
[MAX_WIDTH
];
734 /* Get stencil values */
736 _mesa_memcpy(stencil
, stencilPtr
, width
* sizeof(GLstencil
));
740 _swrast_read_stencil_span(ctx
, stencilReadRb
,
741 width
, srcX
, sy
, stencil
);
744 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
748 _swrast_write_zoomed_stencil_span(ctx
, destX
, destY
, width
,
752 _swrast_write_stencil_span( ctx
, width
, destX
, dy
, stencil
);
756 if (ctx
->Depth
.Mask
) {
757 GLfloat depth
[MAX_WIDTH
];
758 GLuint zVals32
[MAX_WIDTH
];
759 GLushort zVals16
[MAX_WIDTH
];
763 /* get depth values */
765 _mesa_memcpy(depth
, depthPtr
, width
* sizeof(GLfloat
));
769 _swrast_read_depth_span_float(ctx
, depthReadRb
,
770 width
, srcX
, sy
, depth
);
775 _mesa_scale_and_bias_depth(ctx
, width
, depth
);
777 /* convert to integer Z values */
778 if (depthDrawRb
->DataType
== GL_UNSIGNED_SHORT
) {
780 for (k
= 0; k
< width
; k
++)
781 zVals16
[k
] = (GLushort
) (depth
[k
] * depthScale
);
787 for (k
= 0; k
< width
; k
++)
788 zVals32
[k
] = (GLuint
) (depth
[k
] * depthScale
);
795 _swrast_write_zoomed_z_span(ctx
, destX
, destY
, width
,
799 _swrast_put_row(ctx
, depthDrawRb
, width
, destX
, dy
, zVals
, zBytes
);
804 if (tempStencilImage
)
805 _mesa_free(tempStencilImage
);
808 _mesa_free(tempDepthImage
);
814 * Try to do a fast copy pixels.
817 fast_copy_pixels(GLcontext
*ctx
,
818 GLint srcX
, GLint srcY
, GLsizei width
, GLsizei height
,
819 GLint dstX
, GLint dstY
, GLenum type
)
821 struct gl_framebuffer
*srcFb
= ctx
->ReadBuffer
;
822 struct gl_framebuffer
*dstFb
= ctx
->DrawBuffer
;
823 struct gl_renderbuffer
*srcRb
, *dstRb
;
826 if (SWRAST_CONTEXT(ctx
)->_RasterMask
!= 0x0 ||
827 ctx
->Pixel
.ZoomX
!= 1.0F
||
828 ctx
->Pixel
.ZoomY
!= 1.0F
||
829 ctx
->_ImageTransferState
) {
830 /* can't handle these */
834 if (type
== GL_COLOR
) {
835 if (dstFb
->_NumColorDrawBuffers
[0] != 1)
837 srcRb
= srcFb
->_ColorReadBuffer
;
838 dstRb
= dstFb
->_ColorDrawBuffers
[0][0];
840 else if (type
== GL_STENCIL
) {
841 srcRb
= srcFb
->_StencilBuffer
;
842 dstRb
= dstFb
->_StencilBuffer
;
844 else if (type
== GL_DEPTH
) {
845 srcRb
= srcFb
->_DepthBuffer
;
846 dstRb
= dstFb
->_DepthBuffer
;
849 ASSERT(type
== GL_DEPTH_STENCIL_EXT
);
851 srcRb
= srcFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
852 dstRb
= dstFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
855 /* src and dst renderbuffers must be same format and type */
856 if (!srcRb
|| !dstRb
||
857 srcRb
->DataType
!= dstRb
->DataType
||
858 srcRb
->_BaseFormat
!= dstRb
->_BaseFormat
) {
862 /* clipping not supported */
863 if (srcX
< 0 || srcX
+ width
> srcFb
->Width
||
864 srcY
< 0 || srcY
+ height
> srcFb
->Height
||
865 dstX
< dstFb
->_Xmin
|| dstX
+ width
> dstFb
->_Xmax
||
866 dstY
< dstFb
->_Ymin
|| dstY
+ height
> dstFb
->_Ymax
) {
870 /* overlapping src/dst doesn't matter, just determine Y direction */
872 /* top-down max-to-min */
873 srcY
= srcY
+ height
- 1;
874 dstY
= dstY
+ height
- 1;
878 /* bottom-up min-to-max */
882 for (row
= 0; row
< height
; row
++) {
883 GLuint temp
[MAX_WIDTH
][4];
884 srcRb
->GetRow(ctx
, srcRb
, width
, srcX
, srcY
, temp
);
885 dstRb
->PutRow(ctx
, dstRb
, width
, dstX
, dstY
, temp
, NULL
);
895 * Do software-based glCopyPixels.
896 * By time we get here, all parameters will have been error-checked.
899 _swrast_CopyPixels( GLcontext
*ctx
,
900 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
901 GLint destx
, GLint desty
, GLenum type
)
903 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
904 RENDER_START(swrast
,ctx
);
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 RENDER_FINISH(swrast
,ctx
);