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
);
112 if (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)
113 _swrast_span_default_secondary_color(ctx
, &span
);
115 /* allocate space for GLfloat image */
116 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
118 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
121 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
123 _mesa_free(tmpImage
);
124 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
128 /* read source image as float/RGBA */
130 for (row
= 0; row
< height
; row
++) {
131 _swrast_read_rgba_span(ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
132 width
, srcx
, srcy
+ row
, GL_FLOAT
, dest
);
136 /* do the image transfer ops which preceed convolution */
137 for (row
= 0; row
< height
; row
++) {
138 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (tmpImage
+ row
* width
* 4);
139 _mesa_apply_rgba_transfer_ops(ctx
,
140 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
,
145 if (ctx
->Pixel
.Convolution2DEnabled
) {
146 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
149 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
150 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
152 _mesa_free(tmpImage
);
154 /* do remaining post-convolution image transfer ops */
155 for (row
= 0; row
< height
; row
++) {
156 GLfloat (*rgba
)[4] = (GLfloat (*)[4]) (convImage
+ row
* width
* 4);
157 _mesa_apply_rgba_transfer_ops(ctx
,
158 transferOps
& IMAGE_POST_CONVOLUTION_BITS
,
163 /* write the new image */
164 for (row
= 0; row
< height
; row
++) {
165 const GLfloat
*src
= convImage
+ row
* width
* 4;
166 GLvoid
*rgba
= span
.array
->color
.sz1
.rgba
; /* row storage */
168 /* copy convolved colors into span array */
169 _mesa_memcpy(rgba
, src
, width
* 4 * sizeof(GLfloat
));
173 span
.y
= desty
+ row
;
175 span
.array
->ChanType
= GL_FLOAT
;
177 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
, rgba
);
180 _swrast_write_rgba_span(ctx
, &span
);
184 span
.array
->ChanType
= CHAN_TYPE
;
187 _mesa_free(convImage
);
195 copy_rgba_pixels(GLcontext
*ctx
, GLint srcx
, GLint srcy
,
196 GLint width
, GLint height
, GLint destx
, GLint desty
)
198 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
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 /* Determine if copy should be done bottom-to-top or top-to-bottom */
223 /* top-down max-to-min */
224 sy
= srcy
+ height
- 1;
225 dy
= desty
+ height
- 1;
229 /* bottom-up min-to-max */
235 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
236 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
237 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
240 overlapping
= GL_FALSE
;
243 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
245 _swrast_span_default_z(ctx
, &span
);
246 if (swrast
->_FogEnabled
)
247 _swrast_span_default_fog(ctx
, &span
);
248 if (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)
249 _swrast_span_default_secondary_color(ctx
, &span
);
252 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
) * 4);
254 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
257 /* read the source image as RGBA/float */
259 for (row
= 0; row
< height
; row
++) {
260 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
261 width
, srcx
, sy
+ row
, GL_FLOAT
, p
);
267 tmpImage
= NULL
; /* silence compiler warnings */
271 ASSERT(width
< MAX_WIDTH
);
273 for (row
= 0; row
< height
; row
++, sy
+= stepy
, dy
+= stepy
) {
274 GLvoid
*rgba
= span
.array
->attribs
[FRAG_ATTRIB_COL0
];
276 /* Get row/span of source pixels */
278 /* get from buffered image */
279 _mesa_memcpy(rgba
, p
, width
* sizeof(GLfloat
) * 4);
283 /* get from framebuffer */
284 _swrast_read_rgba_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
285 width
, srcx
, sy
, GL_FLOAT
, rgba
);
289 _mesa_apply_rgba_transfer_ops(ctx
, transferOps
, width
,
290 (GLfloat (*)[4]) rgba
);
293 /* Write color span */
297 span
.array
->ChanType
= GL_FLOAT
;
299 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
, rgba
);
302 _swrast_write_rgba_span(ctx
, &span
);
306 span
.array
->ChanType
= CHAN_TYPE
; /* restore */
309 _mesa_free(tmpImage
);
314 copy_ci_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
315 GLint width
, GLint height
,
316 GLint destx
, GLint desty
)
318 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
322 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
326 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
327 /* no readbuffer - OK */
331 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
333 /* Determine if copy should be bottom-to-top or top-to-bottom */
335 /* top-down max-to-min */
336 sy
= srcy
+ height
- 1;
337 dy
= desty
+ height
- 1;
341 /* bottom-up min-to-max */
347 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
348 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
349 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
352 overlapping
= GL_FALSE
;
356 _swrast_span_default_z(ctx
, &span
);
357 if (swrast
->_FogEnabled
)
358 _swrast_span_default_fog(ctx
, &span
);
362 tmpImage
= (GLuint
*) _mesa_malloc(width
* height
* sizeof(GLuint
));
364 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
369 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
370 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
371 width
, srcx
, ssy
, p
);
377 tmpImage
= NULL
; /* silence compiler warning */
381 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
382 /* Get color indexes */
384 _mesa_memcpy(span
.array
->index
, p
, width
* sizeof(GLuint
));
388 _swrast_read_index_span( ctx
, ctx
->ReadBuffer
->_ColorReadBuffer
,
389 width
, srcx
, sy
, span
.array
->index
);
392 if (ctx
->_ImageTransferState
)
393 _mesa_apply_ci_transfer_ops(ctx
, ctx
->_ImageTransferState
,
394 width
, span
.array
->index
);
396 /* write color indexes */
401 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
403 _swrast_write_index_span(ctx
, &span
);
407 _mesa_free(tmpImage
);
412 * Convert floating point Z values to integer Z values with pixel transfer's
416 scale_and_bias_z(GLcontext
*ctx
, GLuint width
,
417 const GLfloat depth
[], GLuint z
[])
419 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
422 if (depthMax
<= 0xffffff &&
423 ctx
->Pixel
.DepthScale
== 1.0 &&
424 ctx
->Pixel
.DepthBias
== 0.0) {
425 /* no scale or bias and no clamping and no worry of overflow */
426 const GLfloat depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
427 for (i
= 0; i
< width
; i
++) {
428 z
[i
] = (GLuint
) (depth
[i
] * depthMaxF
);
432 /* need to be careful with overflow */
433 const GLdouble depthMaxF
= ctx
->DrawBuffer
->_DepthMaxF
;
434 for (i
= 0; i
< width
; i
++) {
435 GLdouble d
= depth
[i
] * ctx
->Pixel
.DepthScale
+ ctx
->Pixel
.DepthBias
;
436 d
= CLAMP(d
, 0.0, 1.0) * depthMaxF
;
451 copy_depth_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
452 GLint width
, GLint height
,
453 GLint destx
, GLint desty
)
455 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
456 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
457 struct gl_renderbuffer
*readRb
= fb
->_DepthBuffer
;
458 GLfloat
*p
, *tmpImage
;
461 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
466 /* no readbuffer - OK */
470 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
472 /* Determine if copy should be bottom-to-top or top-to-bottom */
474 /* top-down max-to-min */
475 sy
= srcy
+ height
- 1;
476 dy
= desty
+ height
- 1;
480 /* bottom-up min-to-max */
486 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
487 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
488 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
491 overlapping
= GL_FALSE
;
494 _swrast_span_default_color(ctx
, &span
);
495 if (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)
496 _swrast_span_default_secondary_color(ctx
, &span
);
497 if (swrast
->_FogEnabled
)
498 _swrast_span_default_fog(ctx
, &span
);
502 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
504 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
508 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
509 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, ssy
, p
);
515 tmpImage
= NULL
; /* silence compiler warning */
519 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
520 GLfloat depth
[MAX_WIDTH
];
521 /* get depth values */
523 _mesa_memcpy(depth
, p
, width
* sizeof(GLfloat
));
527 _swrast_read_depth_span_float(ctx
, readRb
, width
, srcx
, sy
, depth
);
530 /* apply scale and bias */
531 scale_and_bias_z(ctx
, width
, depth
, span
.array
->z
);
533 /* write depth values */
537 if (fb
->Visual
.rgbMode
) {
539 _swrast_write_zoomed_rgba_span(ctx
, destx
, desty
, &span
,
542 _swrast_write_rgba_span(ctx
, &span
);
546 _swrast_write_zoomed_index_span(ctx
, destx
, desty
, &span
);
548 _swrast_write_index_span(ctx
, &span
);
553 _mesa_free(tmpImage
);
559 copy_stencil_pixels( GLcontext
*ctx
, GLint srcx
, GLint srcy
,
560 GLint width
, GLint height
,
561 GLint destx
, GLint desty
)
563 struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
564 struct gl_renderbuffer
*rb
= fb
->_StencilBuffer
;
567 GLstencil
*p
, *tmpImage
;
568 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
572 /* no readbuffer - OK */
576 /* Determine if copy should be bottom-to-top or top-to-bottom */
578 /* top-down max-to-min */
579 sy
= srcy
+ height
- 1;
580 dy
= desty
+ height
- 1;
584 /* bottom-up min-to-max */
590 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
591 overlapping
= regions_overlap(srcx
, srcy
, destx
, desty
, width
, height
,
592 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
595 overlapping
= GL_FALSE
;
600 tmpImage
= (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
602 _mesa_error( ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels" );
606 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
607 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, ssy
, p
);
613 tmpImage
= NULL
; /* silence compiler warning */
617 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
618 GLstencil stencil
[MAX_WIDTH
];
620 /* Get stencil values */
622 _mesa_memcpy(stencil
, p
, width
* sizeof(GLstencil
));
626 _swrast_read_stencil_span( ctx
, rb
, width
, srcx
, sy
, stencil
);
629 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
631 /* Write stencil values */
633 _swrast_write_zoomed_stencil_span(ctx
, destx
, desty
, width
,
637 _swrast_write_stencil_span( ctx
, width
, destx
, dy
, stencil
);
642 _mesa_free(tmpImage
);
647 * This isn't terribly efficient. If a driver really has combined
648 * depth/stencil buffers the driver should implement an optimized
649 * CopyPixels function.
652 copy_depth_stencil_pixels(GLcontext
*ctx
,
653 const GLint srcX
, const GLint srcY
,
654 const GLint width
, const GLint height
,
655 const GLint destX
, const GLint destY
)
657 struct gl_renderbuffer
*stencilReadRb
, *depthReadRb
, *depthDrawRb
;
660 GLstencil
*tempStencilImage
= NULL
, *stencilPtr
= NULL
;
661 GLfloat
*tempDepthImage
= NULL
, *depthPtr
= NULL
;
662 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
663 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
664 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
;
665 const GLboolean scaleOrBias
666 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
669 depthDrawRb
= ctx
->DrawBuffer
->_DepthBuffer
;
670 depthReadRb
= ctx
->ReadBuffer
->_DepthBuffer
;
671 stencilReadRb
= ctx
->ReadBuffer
->_StencilBuffer
;
675 ASSERT(stencilReadRb
);
677 /* Determine if copy should be bottom-to-top or top-to-bottom */
679 /* top-down max-to-min */
680 sy
= srcY
+ height
- 1;
681 dy
= destY
+ height
- 1;
685 /* bottom-up min-to-max */
691 if (ctx
->DrawBuffer
== ctx
->ReadBuffer
) {
692 overlapping
= regions_overlap(srcX
, srcY
, destX
, destY
, width
, height
,
693 ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
696 overlapping
= GL_FALSE
;
702 if (stencilMask
!= 0x0) {
704 = (GLstencil
*) _mesa_malloc(width
* height
* sizeof(GLstencil
));
705 if (!tempStencilImage
) {
706 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
710 /* get copy of stencil pixels */
711 stencilPtr
= tempStencilImage
;
712 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
713 _swrast_read_stencil_span(ctx
, stencilReadRb
,
714 width
, srcX
, ssy
, stencilPtr
);
717 stencilPtr
= tempStencilImage
;
720 if (ctx
->Depth
.Mask
) {
722 = (GLfloat
*) _mesa_malloc(width
* height
* sizeof(GLfloat
));
723 if (!tempDepthImage
) {
724 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyPixels");
725 _mesa_free(tempStencilImage
);
729 /* get copy of depth pixels */
730 depthPtr
= tempDepthImage
;
731 for (j
= 0; j
< height
; j
++, ssy
+= stepy
) {
732 _swrast_read_depth_span_float(ctx
, depthReadRb
,
733 width
, srcX
, ssy
, depthPtr
);
736 depthPtr
= tempDepthImage
;
740 for (j
= 0; j
< height
; j
++, sy
+= stepy
, dy
+= stepy
) {
741 if (stencilMask
!= 0x0) {
742 GLstencil stencil
[MAX_WIDTH
];
744 /* Get stencil values */
746 _mesa_memcpy(stencil
, stencilPtr
, width
* sizeof(GLstencil
));
750 _swrast_read_stencil_span(ctx
, stencilReadRb
,
751 width
, srcX
, sy
, stencil
);
754 _mesa_apply_stencil_transfer_ops(ctx
, width
, stencil
);
758 _swrast_write_zoomed_stencil_span(ctx
, destX
, destY
, width
,
762 _swrast_write_stencil_span( ctx
, width
, destX
, dy
, stencil
);
766 if (ctx
->Depth
.Mask
) {
767 GLfloat depth
[MAX_WIDTH
];
768 GLuint zVals32
[MAX_WIDTH
];
769 GLushort zVals16
[MAX_WIDTH
];
773 /* get depth values */
775 _mesa_memcpy(depth
, depthPtr
, width
* sizeof(GLfloat
));
779 _swrast_read_depth_span_float(ctx
, depthReadRb
,
780 width
, srcX
, sy
, depth
);
785 _mesa_scale_and_bias_depth(ctx
, width
, depth
);
787 /* convert to integer Z values */
788 if (depthDrawRb
->DataType
== GL_UNSIGNED_SHORT
) {
790 for (k
= 0; k
< width
; k
++)
791 zVals16
[k
] = (GLushort
) (depth
[k
] * depthScale
);
797 for (k
= 0; k
< width
; k
++)
798 zVals32
[k
] = (GLuint
) (depth
[k
] * depthScale
);
805 _swrast_write_zoomed_z_span(ctx
, destX
, destY
, width
,
809 _swrast_put_row(ctx
, depthDrawRb
, width
, destX
, dy
, zVals
, zBytes
);
814 if (tempStencilImage
)
815 _mesa_free(tempStencilImage
);
818 _mesa_free(tempDepthImage
);
824 * Try to do a fast copy pixels.
827 fast_copy_pixels(GLcontext
*ctx
,
828 GLint srcX
, GLint srcY
, GLsizei width
, GLsizei height
,
829 GLint dstX
, GLint dstY
, GLenum type
)
831 struct gl_framebuffer
*srcFb
= ctx
->ReadBuffer
;
832 struct gl_framebuffer
*dstFb
= ctx
->DrawBuffer
;
833 struct gl_renderbuffer
*srcRb
, *dstRb
;
836 if (SWRAST_CONTEXT(ctx
)->_RasterMask
!= 0x0 ||
837 ctx
->Pixel
.ZoomX
!= 1.0F
||
838 ctx
->Pixel
.ZoomY
!= 1.0F
||
839 ctx
->_ImageTransferState
) {
840 /* can't handle these */
844 if (type
== GL_COLOR
) {
845 if (dstFb
->_NumColorDrawBuffers
[0] != 1)
847 srcRb
= srcFb
->_ColorReadBuffer
;
848 dstRb
= dstFb
->_ColorDrawBuffers
[0][0];
850 else if (type
== GL_STENCIL
) {
851 srcRb
= srcFb
->_StencilBuffer
;
852 dstRb
= dstFb
->_StencilBuffer
;
854 else if (type
== GL_DEPTH
) {
855 srcRb
= srcFb
->_DepthBuffer
;
856 dstRb
= dstFb
->_DepthBuffer
;
859 ASSERT(type
== GL_DEPTH_STENCIL_EXT
);
861 srcRb
= srcFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
862 dstRb
= dstFb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
865 /* src and dst renderbuffers must be same format and type */
866 if (!srcRb
|| !dstRb
||
867 srcRb
->DataType
!= dstRb
->DataType
||
868 srcRb
->_BaseFormat
!= dstRb
->_BaseFormat
) {
872 /* clipping not supported */
873 if (srcX
< 0 || srcX
+ width
> (GLint
) srcFb
->Width
||
874 srcY
< 0 || srcY
+ height
> (GLint
) srcFb
->Height
||
875 dstX
< dstFb
->_Xmin
|| dstX
+ width
> dstFb
->_Xmax
||
876 dstY
< dstFb
->_Ymin
|| dstY
+ height
> dstFb
->_Ymax
) {
880 /* overlapping src/dst doesn't matter, just determine Y direction */
882 /* top-down max-to-min */
883 srcY
= srcY
+ height
- 1;
884 dstY
= dstY
+ height
- 1;
888 /* bottom-up min-to-max */
892 for (row
= 0; row
< height
; row
++) {
893 GLuint temp
[MAX_WIDTH
][4];
894 srcRb
->GetRow(ctx
, srcRb
, width
, srcX
, srcY
, temp
);
895 dstRb
->PutRow(ctx
, dstRb
, width
, dstX
, dstY
, temp
, NULL
);
905 * Do software-based glCopyPixels.
906 * By time we get here, all parameters will have been error-checked.
909 _swrast_CopyPixels( GLcontext
*ctx
,
910 GLint srcx
, GLint srcy
, GLsizei width
, GLsizei height
,
911 GLint destx
, GLint desty
, GLenum type
)
913 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
914 RENDER_START(swrast
,ctx
);
916 if (swrast
->NewState
)
917 _swrast_validate_derived( ctx
);
919 if (!fast_copy_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
)) {
922 if (ctx
->Visual
.rgbMode
) {
923 copy_rgba_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
926 copy_ci_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
930 copy_depth_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
933 copy_stencil_pixels( ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
935 case GL_DEPTH_STENCIL_EXT
:
936 copy_depth_stencil_pixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
);
939 _mesa_problem(ctx
, "unexpected type in _swrast_CopyPixels");
943 RENDER_FINISH(swrast
,ctx
);