Remove last remnants of pre-renderbuffer code.
[mesa.git] / src / mesa / swrast / s_copypix.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25
26 #include "glheader.h"
27 #include "context.h"
28 #include "colormac.h"
29 #include "convolve.h"
30 #include "histogram.h"
31 #include "image.h"
32 #include "macros.h"
33 #include "imports.h"
34 #include "pixel.h"
35
36 #include "s_context.h"
37 #include "s_depth.h"
38 #include "s_pixeltex.h"
39 #include "s_span.h"
40 #include "s_stencil.h"
41 #include "s_texture.h"
42 #include "s_zoom.h"
43
44
45
46 /*
47 * Determine if there's overlap in an image copy.
48 * This test also compensates for the fact that copies are done from
49 * bottom to top and overlaps can sometimes be handled correctly
50 * without making a temporary image copy.
51 */
52 static GLboolean
53 regions_overlap(GLint srcx, GLint srcy,
54 GLint dstx, GLint dsty,
55 GLint width, GLint height,
56 GLfloat zoomX, GLfloat zoomY)
57 {
58 if (zoomX == 1.0 && zoomY == 1.0) {
59 /* no zoom */
60 if (srcx >= dstx + width || (srcx + width <= dstx)) {
61 return GL_FALSE;
62 }
63 else if (srcy < dsty) { /* this is OK */
64 return GL_FALSE;
65 }
66 else if (srcy > dsty + height) {
67 return GL_FALSE;
68 }
69 else {
70 return GL_TRUE;
71 }
72 }
73 else {
74 /* add one pixel of slop when zooming, just to be safe */
75 if ((srcx > dstx + (width * zoomX) + 1) || (srcx + width + 1 < dstx)) {
76 return GL_FALSE;
77 }
78 else if ((srcy < dsty) && (srcy + height < dsty + (height * zoomY))) {
79 return GL_FALSE;
80 }
81 else if ((srcy > dsty) && (srcy + height > dsty + (height * zoomY))) {
82 return GL_FALSE;
83 }
84 else {
85 return GL_TRUE;
86 }
87 }
88 }
89
90
91 /**
92 * Convert GLfloat[n][4] colors to GLchan[n][4].
93 * XXX maybe move into image.c
94 */
95 static void
96 float_span_to_chan(GLuint n, CONST GLfloat in[][4], GLchan out[][4])
97 {
98 GLuint i;
99 for (i = 0; i < n; i++) {
100 UNCLAMPED_FLOAT_TO_CHAN(out[i][RCOMP], in[i][RCOMP]);
101 UNCLAMPED_FLOAT_TO_CHAN(out[i][GCOMP], in[i][GCOMP]);
102 UNCLAMPED_FLOAT_TO_CHAN(out[i][BCOMP], in[i][BCOMP]);
103 UNCLAMPED_FLOAT_TO_CHAN(out[i][ACOMP], in[i][ACOMP]);
104 }
105 }
106
107
108 /**
109 * Convert GLchan[n][4] colors to GLfloat[n][4].
110 * XXX maybe move into image.c
111 */
112 static void
113 chan_span_to_float(GLuint n, CONST GLchan in[][4], GLfloat out[][4])
114 {
115 GLuint i;
116 for (i = 0; i < n; i++) {
117 out[i][RCOMP] = CHAN_TO_FLOAT(in[i][RCOMP]);
118 out[i][GCOMP] = CHAN_TO_FLOAT(in[i][GCOMP]);
119 out[i][BCOMP] = CHAN_TO_FLOAT(in[i][BCOMP]);
120 out[i][ACOMP] = CHAN_TO_FLOAT(in[i][ACOMP]);
121 }
122 }
123
124
125
126 /*
127 * RGBA copypixels with convolution.
128 */
129 static void
130 copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
131 GLint width, GLint height, GLint destx, GLint desty)
132 {
133 struct gl_renderbuffer *drawRb = NULL;
134 GLboolean quick_draw;
135 GLint row;
136 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
137 const GLuint transferOps = ctx->_ImageTransferState;
138 GLfloat *dest, *tmpImage, *convImage;
139 struct sw_span span;
140
141 INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_RGBA);
142
143 if (ctx->Depth.Test)
144 _swrast_span_default_z(ctx, &span);
145 if (ctx->Fog.Enabled)
146 _swrast_span_default_fog(ctx, &span);
147
148
149 if (SWRAST_CONTEXT(ctx)->_RasterMask == 0
150 && !zoom
151 && destx >= 0
152 && destx + width <= (GLint) ctx->DrawBuffer->Width) {
153 quick_draw = GL_TRUE;
154 drawRb = ctx->DrawBuffer->_ColorDrawBuffers[0][0];
155 }
156 else {
157 quick_draw = GL_FALSE;
158 }
159
160 /* allocate space for GLfloat image */
161 tmpImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
162 if (!tmpImage) {
163 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
164 return;
165 }
166 convImage = (GLfloat *) MALLOC(width * height * 4 * sizeof(GLfloat));
167 if (!convImage) {
168 FREE(tmpImage);
169 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
170 return;
171 }
172
173 /* read source image */
174 dest = tmpImage;
175 for (row = 0; row < height; row++) {
176 GLchan rgba[MAX_WIDTH][4];
177 /* Read GLchan and convert to GLfloat */
178 _swrast_read_rgba_span(ctx, ctx->ReadBuffer->_ColorReadBuffer,
179 width, srcx, srcy + row, rgba);
180 chan_span_to_float(width, (CONST GLchan (*)[4]) rgba,
181 (GLfloat (*)[4]) dest);
182 dest += 4 * width;
183 }
184
185 /* do the image transfer ops which preceed convolution */
186 for (row = 0; row < height; row++) {
187 GLfloat (*rgba)[4] = (GLfloat (*)[4]) (tmpImage + row * width * 4);
188 _mesa_apply_rgba_transfer_ops(ctx,
189 transferOps & IMAGE_PRE_CONVOLUTION_BITS,
190 width, rgba);
191 }
192
193 /* do convolution */
194 if (ctx->Pixel.Convolution2DEnabled) {
195 _mesa_convolve_2d_image(ctx, &width, &height, tmpImage, convImage);
196 }
197 else {
198 ASSERT(ctx->Pixel.Separable2DEnabled);
199 _mesa_convolve_sep_image(ctx, &width, &height, tmpImage, convImage);
200 }
201 FREE(tmpImage);
202
203 /* do remaining post-convolution image transfer ops */
204 for (row = 0; row < height; row++) {
205 GLfloat (*rgba)[4] = (GLfloat (*)[4]) (convImage + row * width * 4);
206 _mesa_apply_rgba_transfer_ops(ctx,
207 transferOps & IMAGE_POST_CONVOLUTION_BITS,
208 width, rgba);
209 }
210
211 /* write the new image */
212 for (row = 0; row < height; row++) {
213 const GLfloat *src = convImage + row * width * 4;
214 GLint dy;
215
216 /* convert floats back to chan */
217 float_span_to_chan(width, (const GLfloat (*)[4]) src, span.array->rgba);
218
219 if (ctx->Pixel.PixelTextureEnabled && ctx->Texture._EnabledUnits) {
220 span.end = width;
221 _swrast_pixel_texture(ctx, &span);
222 }
223
224 /* write row to framebuffer */
225
226 dy = desty + row;
227 if (quick_draw && dy >= 0 && dy < (GLint) ctx->DrawBuffer->Height) {
228 drawRb->PutRow(ctx, drawRb, width, destx, dy, span.array->rgba, NULL);
229 }
230 else if (zoom) {
231 span.x = destx;
232 span.y = dy;
233 span.end = width;
234 _swrast_write_zoomed_rgba_span(ctx, &span,
235 (CONST GLchan (*)[4])span.array->rgba,
236 desty, 0);
237 }
238 else {
239 span.x = destx;
240 span.y = dy;
241 span.end = width;
242 _swrast_write_rgba_span(ctx, &span);
243 }
244 }
245
246 FREE(convImage);
247 }
248
249
250 /*
251 * RGBA copypixels
252 */
253 static void
254 copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
255 GLint width, GLint height, GLint destx, GLint desty)
256 {
257 struct gl_renderbuffer *drawRb;
258 GLchan *tmpImage,*p;
259 GLboolean quick_draw;
260 GLint sy, dy, stepy, j;
261 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
262 GLint overlapping;
263 const GLuint transferOps = ctx->_ImageTransferState;
264 struct sw_span span;
265
266 if (!ctx->ReadBuffer->_ColorReadBuffer) {
267 /* no readbuffer - OK */
268 return;
269 }
270
271 INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_RGBA);
272
273 if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) {
274 copy_conv_rgba_pixels(ctx, srcx, srcy, width, height, destx, desty);
275 return;
276 }
277
278 /* Determine if copy should be done bottom-to-top or top-to-bottom */
279 if (srcy < desty) {
280 /* top-down max-to-min */
281 sy = srcy + height - 1;
282 dy = desty + height - 1;
283 stepy = -1;
284 }
285 else {
286 /* bottom-up min-to-max */
287 sy = srcy;
288 dy = desty;
289 stepy = 1;
290 }
291
292 if (ctx->DrawBuffer == ctx->ReadBuffer) {
293 overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
294 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
295 }
296 else {
297 overlapping = GL_FALSE;
298 }
299
300 if (ctx->Depth.Test)
301 _swrast_span_default_z(ctx, &span);
302 if (ctx->Fog.Enabled)
303 _swrast_span_default_fog(ctx, &span);
304
305 if (SWRAST_CONTEXT(ctx)->_RasterMask == 0
306 && !zoom
307 && destx >= 0
308 && destx + width <= (GLint) ctx->DrawBuffer->Width) {
309 quick_draw = GL_TRUE;
310 drawRb = ctx->DrawBuffer->_ColorDrawBuffers[0][0];
311 }
312 else {
313 quick_draw = GL_FALSE;
314 drawRb = NULL;
315 }
316
317 if (overlapping) {
318 GLint ssy = sy;
319 tmpImage = (GLchan *) MALLOC(width * height * sizeof(GLchan) * 4);
320 if (!tmpImage) {
321 _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
322 return;
323 }
324 /* read the source image */
325 p = tmpImage;
326 for (j = 0; j < height; j++, ssy += stepy) {
327 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
328 width, srcx, ssy, (GLchan (*)[4]) p );
329 p += width * 4;
330 }
331 p = tmpImage;
332 }
333 else {
334 tmpImage = NULL; /* silence compiler warnings */
335 p = NULL;
336 }
337
338 for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
339 /* Get source pixels */
340 if (overlapping) {
341 /* get from buffered image */
342 ASSERT(width < MAX_WIDTH);
343 MEMCPY(span.array->rgba, p, width * sizeof(GLchan) * 4);
344 p += width * 4;
345 }
346 else {
347 /* get from framebuffer */
348 ASSERT(width < MAX_WIDTH);
349 _swrast_read_rgba_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
350 width, srcx, sy, span.array->rgba );
351 }
352
353 if (transferOps) {
354 DEFMARRAY(GLfloat, rgbaFloat, MAX_WIDTH, 4); /* mac 32k limitation */
355 CHECKARRAY(rgbaFloat, return);
356
357 /* convert to float, transfer, convert back to chan */
358 chan_span_to_float(width, (CONST GLchan (*)[4]) span.array->rgba,
359 rgbaFloat);
360 _mesa_apply_rgba_transfer_ops(ctx, transferOps, width, rgbaFloat);
361 float_span_to_chan(width, (CONST GLfloat (*)[4]) rgbaFloat,
362 span.array->rgba);
363
364 UNDEFARRAY(rgbaFloat); /* mac 32k limitation */
365 }
366
367 if (ctx->Pixel.PixelTextureEnabled && ctx->Texture._EnabledUnits) {
368 span.end = width;
369 _swrast_pixel_texture(ctx, &span);
370 }
371
372 /* Write color span */
373 if (quick_draw && dy >= 0 && dy < (GLint) ctx->DrawBuffer->Height) {
374 drawRb->PutRow(ctx, drawRb, width, destx, dy, span.array->rgba, NULL);
375 }
376 else if (zoom) {
377 span.x = destx;
378 span.y = dy;
379 span.end = width;
380 _swrast_write_zoomed_rgba_span(ctx, &span,
381 (CONST GLchan (*)[4]) span.array->rgba,
382 desty, 0);
383 }
384 else {
385 span.x = destx;
386 span.y = dy;
387 span.end = width;
388 _swrast_write_rgba_span(ctx, &span);
389 }
390 }
391
392 if (overlapping)
393 FREE(tmpImage);
394 }
395
396
397 static void
398 copy_ci_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
399 GLint width, GLint height,
400 GLint destx, GLint desty )
401 {
402 GLuint *tmpImage,*p;
403 GLint sy, dy, stepy;
404 GLint j;
405 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
406 const GLboolean shift_or_offset = ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset;
407 GLint overlapping;
408 struct sw_span span;
409
410 if (!ctx->ReadBuffer->_ColorReadBuffer) {
411 /* no readbuffer - OK */
412 return;
413 }
414
415 INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_INDEX);
416
417 /* Determine if copy should be bottom-to-top or top-to-bottom */
418 if (srcy<desty) {
419 /* top-down max-to-min */
420 sy = srcy + height - 1;
421 dy = desty + height - 1;
422 stepy = -1;
423 }
424 else {
425 /* bottom-up min-to-max */
426 sy = srcy;
427 dy = desty;
428 stepy = 1;
429 }
430
431 if (ctx->DrawBuffer == ctx->ReadBuffer) {
432 overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
433 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
434 }
435 else {
436 overlapping = GL_FALSE;
437 }
438
439 if (ctx->Depth.Test)
440 _swrast_span_default_z(ctx, &span);
441 if (ctx->Fog.Enabled)
442 _swrast_span_default_fog(ctx, &span);
443
444 if (overlapping) {
445 GLint ssy = sy;
446 tmpImage = (GLuint *) MALLOC(width * height * sizeof(GLuint));
447 if (!tmpImage) {
448 _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
449 return;
450 }
451 /* read the image */
452 p = tmpImage;
453 for (j = 0; j < height; j++, ssy += stepy) {
454 _swrast_read_index_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
455 width, srcx, ssy, p );
456 p += width;
457 }
458 p = tmpImage;
459 }
460 else {
461 tmpImage = NULL; /* silence compiler warning */
462 p = NULL;
463 }
464
465 for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
466 /* Get color indexes */
467 if (overlapping) {
468 MEMCPY(span.array->index, p, width * sizeof(GLuint));
469 p += width;
470 }
471 else {
472 _swrast_read_index_span( ctx, ctx->ReadBuffer->_ColorReadBuffer,
473 width, srcx, sy, span.array->index );
474 }
475
476 /* Apply shift, offset, look-up table */
477 if (shift_or_offset) {
478 _mesa_shift_and_offset_ci( ctx, width, span.array->index );
479 }
480 if (ctx->Pixel.MapColorFlag) {
481 _mesa_map_ci( ctx, width, span.array->index );
482 }
483
484 /* write color indexes */
485 span.x = destx;
486 span.y = dy;
487 span.end = width;
488 if (zoom)
489 _swrast_write_zoomed_index_span(ctx, &span, desty, 0);
490 else
491 _swrast_write_index_span(ctx, &span);
492 }
493
494 if (overlapping)
495 FREE(tmpImage);
496 }
497
498
499
500 /*
501 * TODO: Optimize!!!!
502 */
503 static void
504 copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
505 GLint width, GLint height,
506 GLint destx, GLint desty )
507 {
508 const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
509 struct gl_renderbuffer *readRb
510 = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
511 GLfloat *p, *tmpImage;
512 GLint sy, dy, stepy;
513 GLint i, j;
514 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
515 GLint overlapping;
516 struct sw_span span;
517
518 if (!readRb) {
519 /* no readbuffer - OK */
520 return;
521 }
522
523 INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_Z);
524
525 if (!ctx->Visual.depthBits) {
526 _mesa_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" );
527 return;
528 }
529
530 /* Determine if copy should be bottom-to-top or top-to-bottom */
531 if (srcy<desty) {
532 /* top-down max-to-min */
533 sy = srcy + height - 1;
534 dy = desty + height - 1;
535 stepy = -1;
536 }
537 else {
538 /* bottom-up min-to-max */
539 sy = srcy;
540 dy = desty;
541 stepy = 1;
542 }
543
544 if (ctx->DrawBuffer == ctx->ReadBuffer) {
545 overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
546 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
547 }
548 else {
549 overlapping = GL_FALSE;
550 }
551
552 _swrast_span_default_color(ctx, &span);
553 if (ctx->Fog.Enabled)
554 _swrast_span_default_fog(ctx, &span);
555
556 if (overlapping) {
557 GLint ssy = sy;
558 tmpImage = (GLfloat *) MALLOC(width * height * sizeof(GLfloat));
559 if (!tmpImage) {
560 _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
561 return;
562 }
563 p = tmpImage;
564 for (j = 0; j < height; j++, ssy += stepy) {
565 _swrast_read_depth_span_float(ctx, readRb, width, srcx, ssy, p);
566 p += width;
567 }
568 p = tmpImage;
569 }
570 else {
571 tmpImage = NULL; /* silence compiler warning */
572 p = NULL;
573 }
574
575 for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
576 GLfloat depth[MAX_WIDTH];
577 float sum = 0;
578 /* get depth values */
579 if (overlapping) {
580 MEMCPY(depth, p, width * sizeof(GLfloat));
581 p += width;
582 }
583 else {
584 _swrast_read_depth_span_float(ctx, readRb, width, srcx, sy, depth);
585 }
586
587 /* apply scale and bias */
588 for (i = 0; i < width; i++) {
589 GLfloat d = depth[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias;
590 sum += d;
591 span.array->z[i] = (GLdepth) (CLAMP(d, 0.0F, 1.0F) * depthMax);
592 }
593
594 /* write depth values */
595 span.x = destx;
596 span.y = dy;
597 span.end = width;
598 if (ctx->Visual.rgbMode) {
599 if (zoom)
600 _swrast_write_zoomed_rgba_span( ctx, &span,
601 (const GLchan (*)[4])span.array->rgba, desty, 0 );
602 else
603 _swrast_write_rgba_span(ctx, &span);
604 }
605 else {
606 if (zoom)
607 _swrast_write_zoomed_index_span( ctx, &span, desty, 0 );
608 else
609 _swrast_write_index_span(ctx, &span);
610 }
611 }
612
613 if (overlapping)
614 FREE(tmpImage);
615 }
616
617
618
619 static void
620 copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
621 GLint width, GLint height,
622 GLint destx, GLint desty )
623 {
624 struct gl_renderbuffer *rb
625 = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
626 GLint sy, dy, stepy;
627 GLint j;
628 GLstencil *p, *tmpImage;
629 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F;
630 const GLboolean shift_or_offset = ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset;
631 GLint overlapping;
632
633 if (!ctx->Visual.stencilBits) {
634 _mesa_error( ctx, GL_INVALID_OPERATION, "glCopyPixels" );
635 return;
636 }
637
638 if (!rb) {
639 /* no readbuffer - OK */
640 return;
641 }
642
643 /* Determine if copy should be bottom-to-top or top-to-bottom */
644 if (srcy < desty) {
645 /* top-down max-to-min */
646 sy = srcy + height - 1;
647 dy = desty + height - 1;
648 stepy = -1;
649 }
650 else {
651 /* bottom-up min-to-max */
652 sy = srcy;
653 dy = desty;
654 stepy = 1;
655 }
656
657 if (ctx->DrawBuffer == ctx->ReadBuffer) {
658 overlapping = regions_overlap(srcx, srcy, destx, desty, width, height,
659 ctx->Pixel.ZoomX, ctx->Pixel.ZoomY);
660 }
661 else {
662 overlapping = GL_FALSE;
663 }
664
665 if (overlapping) {
666 GLint ssy = sy;
667 tmpImage = (GLstencil *) MALLOC(width * height * sizeof(GLstencil));
668 if (!tmpImage) {
669 _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
670 return;
671 }
672 p = tmpImage;
673 for (j = 0; j < height; j++, ssy += stepy) {
674 _swrast_read_stencil_span( ctx, rb, width, srcx, ssy, p );
675 p += width;
676 }
677 p = tmpImage;
678 }
679 else {
680 tmpImage = NULL; /* silence compiler warning */
681 p = NULL;
682 }
683
684 for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
685 GLstencil stencil[MAX_WIDTH];
686
687 /* Get stencil values */
688 if (overlapping) {
689 MEMCPY(stencil, p, width * sizeof(GLstencil));
690 p += width;
691 }
692 else {
693 _swrast_read_stencil_span( ctx, rb, width, srcx, sy, stencil );
694 }
695
696 /* Apply shift, offset, look-up table */
697 if (shift_or_offset) {
698 _mesa_shift_and_offset_stencil( ctx, width, stencil );
699 }
700 if (ctx->Pixel.MapStencilFlag) {
701 _mesa_map_stencil( ctx, width, stencil );
702 }
703
704 /* Write stencil values */
705 if (zoom) {
706 _swrast_write_zoomed_stencil_span( ctx, width, destx, dy,
707 stencil, desty, 0 );
708 }
709 else {
710 _swrast_write_stencil_span( ctx, width, destx, dy, stencil );
711 }
712 }
713
714 if (overlapping)
715 FREE(tmpImage);
716 }
717
718
719
720 void
721 _swrast_CopyPixels( GLcontext *ctx,
722 GLint srcx, GLint srcy, GLsizei width, GLsizei height,
723 GLint destx, GLint desty,
724 GLenum type )
725 {
726 SWcontext *swrast = SWRAST_CONTEXT(ctx);
727 RENDER_START(swrast,ctx);
728
729 if (swrast->NewState)
730 _swrast_validate_derived( ctx );
731
732 if (type == GL_COLOR && ctx->Visual.rgbMode) {
733 copy_rgba_pixels( ctx, srcx, srcy, width, height, destx, desty );
734 }
735 else if (type == GL_COLOR && !ctx->Visual.rgbMode) {
736 copy_ci_pixels( ctx, srcx, srcy, width, height, destx, desty );
737 }
738 else if (type == GL_DEPTH) {
739 copy_depth_pixels( ctx, srcx, srcy, width, height, destx, desty );
740 }
741 else if (type == GL_STENCIL) {
742 copy_stencil_pixels( ctx, srcx, srcy, width, height, destx, desty );
743 }
744 else {
745 _mesa_error( ctx, GL_INVALID_ENUM, "glCopyPixels" );
746 }
747
748 RENDER_FINISH(swrast,ctx);
749 }