2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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.
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
+ (width
* zoomX
) + 1) || (srcx
+ width
+ 1 < dstx
)) {
76 else if ((srcy
< dsty
) && (srcy
+ height
< dsty
+ (height
* zoomY
))) {
79 else if ((srcy
> dsty
) && (srcy
+ height
> dsty
+ (height
* zoomY
))) {
90 * Convert GLfloat[n][4] colors to GLchan[n][4].
91 * XXX maybe move into image.c
94 float_span_to_chan(GLuint n
, CONST GLfloat in
[][4], GLchan out
[][4])
97 for (i
= 0; i
< n
; i
++) {
98 UNCLAMPED_FLOAT_TO_CHAN(out
[i
][RCOMP
], in
[i
][RCOMP
]);
99 UNCLAMPED_FLOAT_TO_CHAN(out
[i
][GCOMP
], in
[i
][GCOMP
]);
100 UNCLAMPED_FLOAT_TO_CHAN(out
[i
][BCOMP
], in
[i
][BCOMP
]);
101 UNCLAMPED_FLOAT_TO_CHAN(out
[i
][ACOMP
], in
[i
][ACOMP
]);
107 * Convert GLchan[n][4] colors to GLfloat[n][4].
108 * XXX maybe move into image.c
111 chan_span_to_float(GLuint n
, CONST GLchan in
[][4], GLfloat out
[][4])
114 for (i
= 0; i
< n
; i
++) {
115 out
[i
][RCOMP
] = CHAN_TO_FLOAT(in
[i
][RCOMP
]);
116 out
[i
][GCOMP
] = CHAN_TO_FLOAT(in
[i
][GCOMP
]);
117 out
[i
][BCOMP
] = CHAN_TO_FLOAT(in
[i
][BCOMP
]);
118 out
[i
][ACOMP
] = CHAN_TO_FLOAT(in
[i
][ACOMP
]);
125 * RGBA copypixels with convolution.
128 copy_conv_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
129 GLint width
, GLint height
, GLint destx
, GLint desty
)
131 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
132 struct gl_renderbuffer
*drawRb
= NULL
;
133 GLboolean quick_draw
;
135 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
136 const GLuint transferOps
= ctx
->_ImageTransferState
;
137 GLfloat
*dest
, *tmpImage
, *convImage
;
140 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
143 _swrast_span_default_z(ctx
, &span
);
144 if (swrast
->_FogEnabled
)
145 _swrast_span_default_fog(ctx
, &span
);
148 if (SWRAST_CONTEXT(ctx
)->_RasterMask
== 0
151 && destx
+ width
<= (GLint
) ctx
->DrawBuffer
->Width
) {
152 quick_draw
= GL_TRUE
;
153 drawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[0][0];
156 quick_draw
= GL_FALSE
;
159 /* allocate space for GLfloat image */
160 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
162 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
165 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
167 _mesa_free(tmpImage
);
168 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
172 /* read source image */
174 for (row
= 0; row
< height
; row
++) {
175 GLchan rgba
[MAX_WIDTH
][4];
176 /* Read GLchan and convert to GLfloat */
177 _swrast_read_rgba_span(ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
178 width
, srcx
, srcy
+ row
, rgba
);
179 chan_span_to_float(width
, (CONST
GLchan (*)[4]) rgba
,
180 (GLfloat (*)[4]) dest
);
184 /* do the image transfer ops which preceed convolution */
185 for (row
= 0; row
< height
; row
++) {
186 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (tmpImage
+ row
* width
* 4);
187 _mesa_apply_rgba_transfer_ops(ctx
,
188 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
,
193 if (ctx
->Pixel
.Convolution2DEnabled
) {
194 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
197 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
198 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
200 _mesa_free(tmpImage
);
202 /* do remaining post-convolution image transfer ops */
203 for (row
= 0; row
< height
; row
++) {
204 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (convImage
+ row
* width
* 4);
205 _mesa_apply_rgba_transfer_ops(ctx
,
206 transferOps
& IMAGE_POST_CONVOLUTION_BITS
,
210 /* write the new image */
211 for (row
= 0; row
< height
; row
++) {
212 const GLfloat
*src
= convImage
+ row
* width
* 4;
215 /* convert floats back to chan */
216 float_span_to_chan(width
, (const GLfloat (*)[4]) src
, span
.array
->rgba
);
218 /* write row to framebuffer */
220 if (quick_draw
&& dy
>= 0 && dy
< (GLint
) ctx
->DrawBuffer
->Height
) {
221 drawRb
->PutRow(ctx
, drawRb
, width
, destx
, dy
, span
.array
->rgba
, NULL
);
228 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
,
229 (CONST
GLchan (*)[4])span
.array
->rgba
);
232 _swrast_write_rgba_span(ctx
, &span
);
237 _mesa_free(convImage
);
245 copy_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
246 GLint width
, GLint height
, GLint destx
, GLint desty
)
248 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
249 struct gl_renderbuffer
*drawRb
;
251 GLboolean quick_draw
;
252 GLint sy
, dy
, stepy
, j
;
253 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
255 const GLuint transferOps
= ctx
->_ImageTransferState
;
258 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
259 /* no readbuffer - OK */
263 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
265 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
266 copy_conv_rgba_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
270 /* Determine if copy should be done bottom-to-top or top-to-bottom */
272 /* top-down max-to-min */
273 sy
= srcy
+ height
- 1;
274 dy
= desty
+ height
- 1;
278 /* bottom-up min-to-max */
284 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
285 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
286 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
289 overlapping
= GL_FALSE
;
293 _swrast_span_default_z(ctx
, &span
);
294 if (swrast
->_FogEnabled
)
295 _swrast_span_default_fog(ctx
, &span
);
297 if (SWRAST_CONTEXT(ctx
)->_RasterMask
== 0
300 && destx
+ width
<= (GLint
) ctx
->DrawBuffer
->Width
) {
301 quick_draw
= GL_TRUE
;
302 drawRb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[0][0];
305 quick_draw
= GL_FALSE
;
311 tmpImage
= (GLchan
*) _mesa_malloc(width
* height
* sizeof(GLchan
) * 4);
313 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
316 /* read the source image */
318 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
319 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
320 width
, srcx
, ssy
, (GLchan (*)[4]) p
);
326 tmpImage
= NULL
; /* silence compiler warnings */
330 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
331 /* Get source pixels */
333 /* get from buffered image */
334 ASSERT(width
< MAX_WIDTH
);
335 _mesa_memcpy(span
.array
->rgba
, p
, width
* sizeof(GLchan
) * 4);
339 /* get from framebuffer */
340 ASSERT(width
< MAX_WIDTH
);
341 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
342 width
, srcx
, sy
, span
.array
->rgba
);
346 GLfloat rgbaFloat
[MAX_WIDTH
][4];
347 /* convert to float, transfer, convert back to chan */
348 chan_span_to_float(width
, (CONST
GLchan (*)[4]) span
.array
->rgba
,
350 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, width
, rgbaFloat
);
351 float_span_to_chan(width
, (CONST
GLfloat (*)[4]) rgbaFloat
,
355 /* Write color span */
356 if (quick_draw
&& dy
>= 0 && dy
< (GLint
) ctx
->DrawBuffer
->Height
) {
357 drawRb
->PutRow(ctx
, drawRb
, width
, destx
, dy
, span
.array
->rgba
, NULL
);
364 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
,
365 (CONST
GLchan (*)[4]) span
.array
->rgba
);
368 _swrast_write_rgba_span(ctx
, &span
);
374 _mesa_free(tmpImage
);
379 copy_ci_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
380 GLint width
, GLint height
,
381 GLint destx
, GLint desty
)
383 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
387 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
388 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
392 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
393 /* no readbuffer - OK */
397 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
399 /* Determine if copy should be bottom-to-top or top-to-bottom */
401 /* top-down max-to-min */
402 sy
= srcy
+ height
- 1;
403 dy
= desty
+ height
- 1;
407 /* bottom-up min-to-max */
413 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
414 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
415 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
418 overlapping
= GL_FALSE
;
422 _swrast_span_default_z(ctx
, &span
);
423 if (swrast
->_FogEnabled
)
424 _swrast_span_default_fog(ctx
, &span
);
428 tmpImage
= (GLuint
*) _mesa_malloc(width
* height
* sizeof(GLuint
));
430 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
435 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
436 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
437 width
, srcx
, ssy
, p
);
443 tmpImage
= NULL
; /* silence compiler warning */
447 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
448 /* Get color indexes */
450 _mesa_memcpy(span
.array
->index
, p
, width
* sizeof(GLuint
));
454 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
455 width
, srcx
, sy
, span
.array
->index
);
458 /* Apply shift, offset, look-up table */
459 if (shift_or_offset
) {
460 _mesa_shift_and_offset_ci( ctx
, width
, span
.array
->index
);
462 if (ctx
->Pixel
.MapColorFlag
) {
463 _mesa_map_ci( ctx
, width
, span
.array
->index
);
466 /* write color indexes */
471 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
473 _swrast_write_index_span(ctx
, &span
);
477 _mesa_free(tmpImage
);
486 copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
487 GLint width
, GLint height
,
488 GLint destx
, GLint desty
)
490 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
491 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
492 struct gl_renderbuffer
*readRb
= fb
->_DepthBuffer
;
493 const GLfloat depthMax
= fb
->_DepthMaxF
;
494 GLfloat
*p
, *tmpImage
;
497 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
502 /* no readbuffer - OK */
506 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
508 /* Determine if copy should be bottom-to-top or top-to-bottom */
510 /* top-down max-to-min */
511 sy
= srcy
+ height
- 1;
512 dy
= desty
+ height
- 1;
516 /* bottom-up min-to-max */
522 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
523 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
524 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
527 overlapping
= GL_FALSE
;
530 _swrast_span_default_color(ctx
, &span
);
531 if (swrast
->_FogEnabled
)
532 _swrast_span_default_fog(ctx
, &span
);
536 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
538 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
542 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
543 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, ssy
, p
);
549 tmpImage
= NULL
; /* silence compiler warning */
553 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
554 GLfloat depth
[MAX_WIDTH
];
555 /* get depth values */
557 _mesa_memcpy(depth
, p
, width
* sizeof(GLfloat
));
561 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, sy
, depth
);
564 /* apply scale and bias */
565 for (i
= 0; i
< width
; i
++) {
566 GLfloat d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
567 span
.array
->z
[i
] = (GLuint
) (CLAMP(d
, 0.0F
, 1.0F
) * depthMax
);
570 /* write depth values */
574 if (fb
->Visual
.rgbMode
) {
576 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
,
577 (const GLchan (*)[4]) span
.array
->rgba
);
579 _swrast_write_rgba_span(ctx
, &span
);
583 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
585 _swrast_write_index_span(ctx
, &span
);
590 _mesa_free(tmpImage
);
596 copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
597 GLint width
, GLint height
,
598 GLint destx
, GLint desty
)
600 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
601 struct gl_renderbuffer
*rb
= fb
->_StencilBuffer
;
604 GLstencil
*p
, *tmpImage
;
605 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
606 const GLboolean shift_or_offset
= ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
610 /* no readbuffer - OK */
614 /* Determine if copy should be bottom-to-top or top-to-bottom */
616 /* top-down max-to-min */
617 sy
= srcy
+ height
- 1;
618 dy
= desty
+ height
- 1;
622 /* bottom-up min-to-max */
628 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
629 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
630 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
633 overlapping
= GL_FALSE
;
638 tmpImage
= (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
640 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
644 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
645 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, ssy
, p
);
651 tmpImage
= NULL
; /* silence compiler warning */
655 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
656 GLstencil stencil
[MAX_WIDTH
];
658 /* Get stencil values */
660 _mesa_memcpy(stencil
, p
, width
* sizeof(GLstencil
));
664 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, sy
, stencil
);
667 /* Apply shift, offset, look-up table */
668 if (shift_or_offset
) {
669 _mesa_shift_and_offset_stencil( ctx
, width
, stencil
);
671 if (ctx
->Pixel
.MapStencilFlag
) {
672 _mesa_map_stencil( ctx
, width
, stencil
);
675 /* Write stencil values */
677 _swrast_write_zoomed_stencil_span(ctx
, destx
, desty
, width
,
681 _swrast_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
686 _mesa_free(tmpImage
);
691 * This isn't terribly efficient. If a driver really has combined
692 * depth/stencil buffers the driver should implement an optimized
693 * CopyPixels function.
696 copy_depth_stencil_pixels(GLcontext
*ctx
,
697 const GLint srcX
, const GLint srcY
,
698 const GLint width
, const GLint height
,
699 const GLint destX
, const GLint destY
)
701 struct gl_renderbuffer
*stencilReadRb
, *depthReadRb
, *depthDrawRb
;
704 GLstencil
*tempStencilImage
= NULL
, *stencilPtr
= NULL
;
705 GLfloat
*tempDepthImage
= NULL
, *depthPtr
= NULL
;
706 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
707 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
708 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
709 const GLboolean shiftOrOffset
710 = ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
;
711 const GLboolean scaleOrBias
712 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
715 depthDrawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
716 depthReadRb
= ctx
->ReadBuffer
->_DepthBuffer
;
717 stencilReadRb
= ctx
->ReadBuffer
->_StencilBuffer
;
721 ASSERT(stencilReadRb
);
723 /* Determine if copy should be bottom-to-top or top-to-bottom */
725 /* top-down max-to-min */
726 sy
= srcY
+ height
- 1;
727 dy
= destY
+ height
- 1;
731 /* bottom-up min-to-max */
737 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
738 overlapping
= regions_overlap(srcX
, srcY
, destX
, destY
, width
, height
,
739 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
742 overlapping
= GL_FALSE
;
748 if (stencilMask
!= 0x0) {
750 = (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
751 if (!tempStencilImage
) {
752 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
756 /* get copy of stencil pixels */
757 stencilPtr
= tempStencilImage
;
758 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
759 _swrast_read_stencil_span(ctx
, stencilReadRb
,
760 width
, srcX
, ssy
, stencilPtr
);
763 stencilPtr
= tempStencilImage
;
766 if (ctx
->Depth
.Mask
) {
768 = (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
769 if (!tempDepthImage
) {
770 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
771 _mesa_free(tempStencilImage
);
775 /* get copy of depth pixels */
776 depthPtr
= tempDepthImage
;
777 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
778 _swrast_read_depth_span_float(ctx
, depthReadRb
,
779 width
, srcX
, ssy
, depthPtr
);
782 depthPtr
= tempDepthImage
;
786 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
787 if (stencilMask
!= 0x0) {
788 GLstencil stencil
[MAX_WIDTH
];
790 /* Get stencil values */
792 _mesa_memcpy(stencil
, stencilPtr
, width
* sizeof(GLstencil
));
796 _swrast_read_stencil_span(ctx
, stencilReadRb
,
797 width
, srcX
, sy
, stencil
);
800 /* Apply shift, offset, look-up table */
802 _mesa_shift_and_offset_stencil(ctx
, width
, stencil
);
804 if (ctx
->Pixel
.MapStencilFlag
) {
805 _mesa_map_stencil(ctx
, width
, stencil
);
810 _swrast_write_zoomed_stencil_span(ctx
, destX
, destY
, width
,
814 _swrast_write_stencil_span( ctx
, width
, destX
, dy
, stencil
);
818 if (ctx
->Depth
.Mask
) {
819 GLfloat depth
[MAX_WIDTH
];
820 GLuint zVals32
[MAX_WIDTH
];
821 GLushort zVals16
[MAX_WIDTH
];
825 /* get depth values */
827 _mesa_memcpy(depth
, depthPtr
, width
* sizeof(GLfloat
));
831 _swrast_read_depth_span_float(ctx
, depthReadRb
,
832 width
, srcX
, sy
, depth
);
837 _mesa_scale_and_bias_depth(ctx
, width
, depth
);
839 /* convert to integer Z values */
840 if (depthDrawRb
->DataType
== GL_UNSIGNED_SHORT
) {
842 for (k
= 0; k
< width
; k
++)
843 zVals16
[k
] = (GLushort
) (depth
[k
] * depthScale
);
849 for (k
= 0; k
< width
; k
++)
850 zVals32
[k
] = (GLuint
) (depth
[k
] * depthScale
);
857 _swrast_write_zoomed_z_span(ctx
, destX
, destY
, width
,
861 _swrast_put_row(ctx
, depthDrawRb
, width
, destX
, dy
, zVals
, zBytes
);
866 if (tempStencilImage
)
867 _mesa_free(tempStencilImage
);
870 _mesa_free(tempDepthImage
);
875 * Do software-based glCopyPixels.
876 * By time we get here, all parameters will have been error-checked.
879 _swrast_CopyPixels( GLcontext
*ctx
,
880 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
881 GLint destx
, GLint desty
, GLenum type
)
883 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
884 RENDER_START(swrast
,ctx
);
886 if (swrast
->NewState
)
887 _swrast_validate_derived( ctx
);
891 if (ctx
->Visual
.rgbMode
) {
892 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
895 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
899 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
902 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
904 case GL_DEPTH_STENCIL_EXT
:
905 copy_depth_stencil_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
908 _mesa_problem(ctx
, "unexpected type in _swrast_CopyPixels");
911 RENDER_FINISH(swrast
,ctx
);