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 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
192 const GLbitfield prevActiveAttribs
= swrast
->_ActiveAttribMask
;
193 GLfloat
*tmpImage
, *p
;
194 GLint sy
, dy
, stepy
, row
;
195 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
197 GLuint transferOps
= ctx
->_ImageTransferState
;
200 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
201 /* no readbuffer - OK */
205 /* don't interpolate COL0 and overwrite the glDrawPixel colors! */
206 swrast
->_ActiveAttribMask
&= ~FRAG_BIT_COL0
;
208 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
209 copy_conv_rgba_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
212 else if (ctx
->Pixel
.Convolution1DEnabled
) {
213 /* make sure we don't apply 1D convolution */
214 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
215 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
218 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
219 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
220 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
223 overlapping
= GL_FALSE
;
226 /* Determine if copy should be done bottom-to-top or top-to-bottom */
227 if (!overlapping
&& srcy
< desty
) {
228 /* top-down max-to-min */
229 sy
= srcy
+ height
- 1;
230 dy
= desty
+ height
- 1;
234 /* bottom-up min-to-max */
240 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
241 _swrast_span_default_attribs(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
->attribs
[FRAG_ATTRIB_COL0
];
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
);
304 swrast
->_ActiveAttribMask
= prevActiveAttribs
;
309 copy_ci_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
310 GLint width
, GLint height
,
311 GLint destx
, GLint desty
)
316 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
320 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
321 /* no readbuffer - OK */
325 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
326 _swrast_span_default_attribs(ctx
, &span
);
328 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
329 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
330 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
333 overlapping
= GL_FALSE
;
336 /* Determine if copy should be bottom-to-top or top-to-bottom */
337 if (!overlapping
&& srcy
< desty
) {
338 /* top-down max-to-min */
339 sy
= srcy
+ height
- 1;
340 dy
= desty
+ height
- 1;
344 /* bottom-up min-to-max */
352 tmpImage
= (GLuint
*) _mesa_malloc(width
* height
* sizeof(GLuint
));
354 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
359 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
360 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
361 width
, srcx
, ssy
, p
);
367 tmpImage
= NULL
; /* silence compiler warning */
371 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
372 /* Get color indexes */
374 _mesa_memcpy(span
.array
->index
, p
, width
* sizeof(GLuint
));
378 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
379 width
, srcx
, sy
, span
.array
->index
);
382 if (ctx
->_ImageTransferState
)
383 _mesa_apply_ci_transfer_ops(ctx
, ctx
->_ImageTransferState
,
384 width
, span
.array
->index
);
386 /* write color indexes */
391 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
393 _swrast_write_index_span(ctx
, &span
);
397 _mesa_free(tmpImage
);
402 * Convert floating point Z values to integer Z values with pixel transfer's
406 scale_and_bias_z(GLcontext
*ctx
, GLuint width
,
407 const GLfloat depth
[], GLuint z
[])
409 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
412 if (depthMax
<= 0xffffff &&
413 ctx
->Pixel
.DepthScale
== 1.0 &&
414 ctx
->Pixel
.DepthBias
== 0.0) {
415 /* no scale or bias and no clamping and no worry of overflow */
416 const GLfloat depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
417 for (i
= 0; i
< width
; i
++) {
418 z
[i
] = (GLuint
) (depth
[i
] * depthMaxF
);
422 /* need to be careful with overflow */
423 const GLdouble depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
424 for (i
= 0; i
< width
; i
++) {
425 GLdouble d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
426 d
= CLAMP(d
, 0.0, 1.0) * depthMaxF
;
441 copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
442 GLint width
, GLint height
,
443 GLint destx
, GLint desty
)
445 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
446 struct gl_renderbuffer
*readRb
= fb
->_DepthBuffer
;
447 GLfloat
*p
, *tmpImage
;
450 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
455 /* no readbuffer - OK */
459 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
460 _swrast_span_default_attribs(ctx
, &span
);
462 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
463 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
464 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
467 overlapping
= GL_FALSE
;
470 /* Determine if copy should be bottom-to-top or top-to-bottom */
471 if (!overlapping
&& srcy
< desty
) {
472 /* top-down max-to-min */
473 sy
= srcy
+ height
- 1;
474 dy
= desty
+ height
- 1;
478 /* bottom-up min-to-max */
486 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
488 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
492 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
493 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, ssy
, p
);
499 tmpImage
= NULL
; /* silence compiler warning */
503 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
504 GLfloat depth
[MAX_WIDTH
];
505 /* get depth values */
507 _mesa_memcpy(depth
, p
, width
* sizeof(GLfloat
));
511 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, sy
, depth
);
514 /* apply scale and bias */
515 scale_and_bias_z(ctx
, width
, depth
, span
.array
->z
);
517 /* write depth values */
521 if (fb
->Visual
.rgbMode
) {
523 _swrast_write_zoomed_depth_span(ctx
, destx
, desty
, &span
);
525 _swrast_write_rgba_span(ctx
, &span
);
529 _swrast_write_zoomed_depth_span(ctx
, destx
, desty
, &span
);
531 _swrast_write_index_span(ctx
, &span
);
536 _mesa_free(tmpImage
);
542 copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
543 GLint width
, GLint height
,
544 GLint destx
, GLint desty
)
546 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
547 struct gl_renderbuffer
*rb
= fb
->_StencilBuffer
;
550 GLstencil
*p
, *tmpImage
;
551 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
555 /* no readbuffer - OK */
559 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
560 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
561 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
564 overlapping
= GL_FALSE
;
567 /* Determine if copy should be bottom-to-top or top-to-bottom */
568 if (!overlapping
&& srcy
< desty
) {
569 /* top-down max-to-min */
570 sy
= srcy
+ height
- 1;
571 dy
= desty
+ height
- 1;
575 /* bottom-up min-to-max */
583 tmpImage
= (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
585 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
589 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
590 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, ssy
, p
);
596 tmpImage
= NULL
; /* silence compiler warning */
600 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
601 GLstencil stencil
[MAX_WIDTH
];
603 /* Get stencil values */
605 _mesa_memcpy(stencil
, p
, width
* sizeof(GLstencil
));
609 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, sy
, stencil
);
612 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
614 /* Write stencil values */
616 _swrast_write_zoomed_stencil_span(ctx
, destx
, desty
, width
,
620 _swrast_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
625 _mesa_free(tmpImage
);
630 * This isn't terribly efficient. If a driver really has combined
631 * depth/stencil buffers the driver should implement an optimized
632 * CopyPixels function.
635 copy_depth_stencil_pixels(GLcontext
*ctx
,
636 const GLint srcX
, const GLint srcY
,
637 const GLint width
, const GLint height
,
638 const GLint destX
, const GLint destY
)
640 struct gl_renderbuffer
*stencilReadRb
, *depthReadRb
, *depthDrawRb
;
643 GLstencil
*tempStencilImage
= NULL
, *stencilPtr
= NULL
;
644 GLfloat
*tempDepthImage
= NULL
, *depthPtr
= NULL
;
645 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
646 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
647 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
648 const GLboolean scaleOrBias
649 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
652 depthDrawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
653 depthReadRb
= ctx
->ReadBuffer
->_DepthBuffer
;
654 stencilReadRb
= ctx
->ReadBuffer
->_StencilBuffer
;
658 ASSERT(stencilReadRb
);
660 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
661 overlapping
= regions_overlap(srcX
, srcY
, destX
, destY
, width
, height
,
662 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
665 overlapping
= GL_FALSE
;
668 /* Determine if copy should be bottom-to-top or top-to-bottom */
669 if (!overlapping
&& srcY
< destY
) {
670 /* top-down max-to-min */
671 sy
= srcY
+ height
- 1;
672 dy
= destY
+ height
- 1;
676 /* bottom-up min-to-max */
685 if (stencilMask
!= 0x0) {
687 = (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
688 if (!tempStencilImage
) {
689 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
693 /* get copy of stencil pixels */
694 stencilPtr
= tempStencilImage
;
695 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
696 _swrast_read_stencil_span(ctx
, stencilReadRb
,
697 width
, srcX
, ssy
, stencilPtr
);
700 stencilPtr
= tempStencilImage
;
703 if (ctx
->Depth
.Mask
) {
705 = (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
706 if (!tempDepthImage
) {
707 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
708 _mesa_free(tempStencilImage
);
712 /* get copy of depth pixels */
713 depthPtr
= tempDepthImage
;
714 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
715 _swrast_read_depth_span_float(ctx
, depthReadRb
,
716 width
, srcX
, ssy
, depthPtr
);
719 depthPtr
= tempDepthImage
;
723 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
724 if (stencilMask
!= 0x0) {
725 GLstencil stencil
[MAX_WIDTH
];
727 /* Get stencil values */
729 _mesa_memcpy(stencil
, stencilPtr
, width
* sizeof(GLstencil
));
733 _swrast_read_stencil_span(ctx
, stencilReadRb
,
734 width
, srcX
, sy
, stencil
);
737 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
741 _swrast_write_zoomed_stencil_span(ctx
, destX
, destY
, width
,
745 _swrast_write_stencil_span( ctx
, width
, destX
, dy
, stencil
);
749 if (ctx
->Depth
.Mask
) {
750 GLfloat depth
[MAX_WIDTH
];
751 GLuint zVals32
[MAX_WIDTH
];
752 GLushort zVals16
[MAX_WIDTH
];
756 /* get depth values */
758 _mesa_memcpy(depth
, depthPtr
, width
* sizeof(GLfloat
));
762 _swrast_read_depth_span_float(ctx
, depthReadRb
,
763 width
, srcX
, sy
, depth
);
768 _mesa_scale_and_bias_depth(ctx
, width
, depth
);
770 /* convert to integer Z values */
771 if (depthDrawRb
->DataType
== GL_UNSIGNED_SHORT
) {
773 for (k
= 0; k
< width
; k
++)
774 zVals16
[k
] = (GLushort
) (depth
[k
] * depthScale
);
780 for (k
= 0; k
< width
; k
++)
781 zVals32
[k
] = (GLuint
) (depth
[k
] * depthScale
);
788 _swrast_write_zoomed_z_span(ctx
, destX
, destY
, width
,
792 _swrast_put_row(ctx
, depthDrawRb
, width
, destX
, dy
, zVals
, zBytes
);
797 if (tempStencilImage
)
798 _mesa_free(tempStencilImage
);
801 _mesa_free(tempDepthImage
);
807 * Try to do a fast copy pixels.
810 fast_copy_pixels(GLcontext
*ctx
,
811 GLint srcX
, GLint srcY
, GLsizei width
, GLsizei height
,
812 GLint dstX
, GLint dstY
, GLenum type
)
814 struct gl_framebuffer
*srcFb
= ctx
->ReadBuffer
;
815 struct gl_framebuffer
*dstFb
= ctx
->DrawBuffer
;
816 struct gl_renderbuffer
*srcRb
, *dstRb
;
819 if (SWRAST_CONTEXT(ctx
)->_RasterMask
!= 0x0 ||
820 ctx
->Pixel
.ZoomX
!= 1.0F
||
821 ctx
->Pixel
.ZoomY
!= 1.0F
||
822 ctx
->_ImageTransferState
) {
823 /* can't handle these */
827 if (type
== GL_COLOR
) {
828 if (dstFb
->_NumColorDrawBuffers
[0] != 1)
830 srcRb
= srcFb
->_ColorReadBuffer
;
831 dstRb
= dstFb
->_ColorDrawBuffers
[0][0];
833 else if (type
== GL_STENCIL
) {
834 srcRb
= srcFb
->_StencilBuffer
;
835 dstRb
= dstFb
->_StencilBuffer
;
837 else if (type
== GL_DEPTH
) {
838 srcRb
= srcFb
->_DepthBuffer
;
839 dstRb
= dstFb
->_DepthBuffer
;
842 ASSERT(type
== GL_DEPTH_STENCIL_EXT
);
844 srcRb
= srcFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
845 dstRb
= dstFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
848 /* src and dst renderbuffers must be same format and type */
849 if (!srcRb
|| !dstRb
||
850 srcRb
->DataType
!= dstRb
->DataType
||
851 srcRb
->_BaseFormat
!= dstRb
->_BaseFormat
) {
855 /* clipping not supported */
856 if (srcX
< 0 || srcX
+ width
> (GLint
) srcFb
->Width
||
857 srcY
< 0 || srcY
+ height
> (GLint
) srcFb
->Height
||
858 dstX
< dstFb
->_Xmin
|| dstX
+ width
> dstFb
->_Xmax
||
859 dstY
< dstFb
->_Ymin
|| dstY
+ height
> dstFb
->_Ymax
) {
863 /* overlapping src/dst doesn't matter, just determine Y direction */
865 /* top-down max-to-min */
866 srcY
= srcY
+ height
- 1;
867 dstY
= dstY
+ height
- 1;
871 /* bottom-up min-to-max */
875 for (row
= 0; row
< height
; row
++) {
876 GLuint temp
[MAX_WIDTH
][4];
877 srcRb
->GetRow(ctx
, srcRb
, width
, srcX
, srcY
, temp
);
878 dstRb
->PutRow(ctx
, dstRb
, width
, dstX
, dstY
, temp
, NULL
);
888 * Do software-based glCopyPixels.
889 * By time we get here, all parameters will have been error-checked.
892 _swrast_CopyPixels( GLcontext
*ctx
,
893 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
894 GLint destx
, GLint desty
, GLenum type
)
896 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
897 RENDER_START(swrast
,ctx
);
899 if (swrast
->NewState
)
900 _swrast_validate_derived( ctx
);
902 if (!fast_copy_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
)) {
905 if (ctx
->Visual
.rgbMode
) {
906 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
909 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
913 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
916 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
918 case GL_DEPTH_STENCIL_EXT
:
919 copy_depth_stencil_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
922 _mesa_problem(ctx
, "unexpected type in _swrast_CopyPixels");
926 RENDER_FINISH(swrast
,ctx
);