swrast: Remove unused variable.
[mesa.git] / src / mesa / swrast / s_drawpix.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "main/glheader.h"
27 #include "main/bufferobj.h"
28 #include "main/colormac.h"
29 #include "main/condrender.h"
30 #include "main/context.h"
31 #include "main/format_pack.h"
32 #include "main/image.h"
33 #include "main/imports.h"
34 #include "main/macros.h"
35 #include "main/pack.h"
36 #include "main/pbo.h"
37 #include "main/pixeltransfer.h"
38 #include "main/state.h"
39
40 #include "s_context.h"
41 #include "s_span.h"
42 #include "s_stencil.h"
43 #include "s_zoom.h"
44
45
46 /**
47 * Handle a common case of drawing GL_RGB/GL_UNSIGNED_BYTE into a
48 * MESA_FORMAT_XRGB888 or MESA_FORMAT_ARGB888 renderbuffer.
49 */
50 static void
51 fast_draw_rgb_ubyte_pixels(struct gl_context *ctx,
52 struct gl_renderbuffer *rb,
53 GLint x, GLint y,
54 GLsizei width, GLsizei height,
55 const struct gl_pixelstore_attrib *unpack,
56 const GLvoid *pixels)
57 {
58 const GLubyte *src = (const GLubyte *)
59 _mesa_image_address2d(unpack, pixels, width,
60 height, GL_RGB, GL_UNSIGNED_BYTE, 0, 0);
61 const GLint srcRowStride = _mesa_image_row_stride(unpack, width,
62 GL_RGB, GL_UNSIGNED_BYTE);
63 GLint i, j;
64 GLubyte *dst;
65 GLint dstRowStride;
66
67 ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
68 GL_MAP_WRITE_BIT, &dst, &dstRowStride);
69
70 if (!dst) {
71 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
72 return;
73 }
74
75 if (ctx->Pixel.ZoomY == -1.0f) {
76 dst = dst + (height - 1) * dstRowStride;
77 dstRowStride = -dstRowStride;
78 }
79
80 for (i = 0; i < height; i++) {
81 GLuint *dst4 = (GLuint *) dst;
82 for (j = 0; j < width; j++) {
83 dst4[j] = PACK_COLOR_8888(0xff, src[j*3+0], src[j*3+1], src[j*3+2]);
84 }
85 dst += dstRowStride;
86 src += srcRowStride;
87 }
88
89 ctx->Driver.UnmapRenderbuffer(ctx, rb);
90 }
91
92
93 /**
94 * Handle a common case of drawing GL_RGBA/GL_UNSIGNED_BYTE into a
95 * MESA_FORMAT_ARGB888 or MESA_FORMAT_xRGB888 renderbuffer.
96 */
97 static void
98 fast_draw_rgba_ubyte_pixels(struct gl_context *ctx,
99 struct gl_renderbuffer *rb,
100 GLint x, GLint y,
101 GLsizei width, GLsizei height,
102 const struct gl_pixelstore_attrib *unpack,
103 const GLvoid *pixels)
104 {
105 const GLubyte *src = (const GLubyte *)
106 _mesa_image_address2d(unpack, pixels, width,
107 height, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
108 const GLint srcRowStride =
109 _mesa_image_row_stride(unpack, width, GL_RGBA, GL_UNSIGNED_BYTE);
110 GLint i, j;
111 GLubyte *dst;
112 GLint dstRowStride;
113
114 ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
115 GL_MAP_WRITE_BIT, &dst, &dstRowStride);
116
117 if (!dst) {
118 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
119 return;
120 }
121
122 if (ctx->Pixel.ZoomY == -1.0f) {
123 dst = dst + (height - 1) * dstRowStride;
124 dstRowStride = -dstRowStride;
125 }
126
127 for (i = 0; i < height; i++) {
128 GLuint *dst4 = (GLuint *) dst;
129 for (j = 0; j < width; j++) {
130 dst4[j] = PACK_COLOR_8888(src[j*4+3], src[j*4+0],
131 src[j*4+1], src[j*4+2]);
132 }
133 dst += dstRowStride;
134 src += srcRowStride;
135 }
136
137 ctx->Driver.UnmapRenderbuffer(ctx, rb);
138 }
139
140
141 /**
142 * Handle a common case of drawing a format/type combination that
143 * exactly matches the renderbuffer format.
144 */
145 static void
146 fast_draw_generic_pixels(struct gl_context *ctx,
147 struct gl_renderbuffer *rb,
148 GLint x, GLint y,
149 GLsizei width, GLsizei height,
150 GLenum format, GLenum type,
151 const struct gl_pixelstore_attrib *unpack,
152 const GLvoid *pixels)
153 {
154 const GLubyte *src = (const GLubyte *)
155 _mesa_image_address2d(unpack, pixels, width,
156 height, format, type, 0, 0);
157 const GLint srcRowStride =
158 _mesa_image_row_stride(unpack, width, format, type);
159 const GLint rowLength = width * _mesa_get_format_bytes(rb->Format);
160 GLint i;
161 GLubyte *dst;
162 GLint dstRowStride;
163
164 ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height,
165 GL_MAP_WRITE_BIT, &dst, &dstRowStride);
166
167 if (!dst) {
168 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
169 return;
170 }
171
172 if (ctx->Pixel.ZoomY == -1.0f) {
173 dst = dst + (height - 1) * dstRowStride;
174 dstRowStride = -dstRowStride;
175 }
176
177 for (i = 0; i < height; i++) {
178 memcpy(dst, src, rowLength);
179 dst += dstRowStride;
180 src += srcRowStride;
181 }
182
183 ctx->Driver.UnmapRenderbuffer(ctx, rb);
184 }
185
186
187 /**
188 * Try to do a fast and simple RGB(a) glDrawPixels.
189 * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
190 */
191 static GLboolean
192 fast_draw_rgba_pixels(struct gl_context *ctx, GLint x, GLint y,
193 GLsizei width, GLsizei height,
194 GLenum format, GLenum type,
195 const struct gl_pixelstore_attrib *userUnpack,
196 const GLvoid *pixels)
197 {
198 struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
199 SWcontext *swrast = SWRAST_CONTEXT(ctx);
200 struct gl_pixelstore_attrib unpack;
201
202 if (!rb)
203 return GL_TRUE; /* no-op */
204
205 if (ctx->DrawBuffer->_NumColorDrawBuffers > 1 ||
206 (swrast->_RasterMask & ~CLIP_BIT) ||
207 ctx->Texture._EnabledCoordUnits ||
208 userUnpack->SwapBytes ||
209 ctx->Pixel.ZoomX != 1.0f ||
210 fabsf(ctx->Pixel.ZoomY) != 1.0f ||
211 ctx->_ImageTransferState) {
212 /* can't handle any of those conditions */
213 return GL_FALSE;
214 }
215
216 unpack = *userUnpack;
217
218 /* clipping */
219 if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height, &unpack)) {
220 /* image was completely clipped: no-op, all done */
221 return GL_TRUE;
222 }
223
224 if (format == GL_RGB &&
225 type == GL_UNSIGNED_BYTE &&
226 (rb->Format == MESA_FORMAT_B8G8R8X8_UNORM ||
227 rb->Format == MESA_FORMAT_B8G8R8A8_UNORM)) {
228 fast_draw_rgb_ubyte_pixels(ctx, rb, x, y, width, height,
229 &unpack, pixels);
230 return GL_TRUE;
231 }
232
233 if (format == GL_RGBA &&
234 type == GL_UNSIGNED_BYTE &&
235 (rb->Format == MESA_FORMAT_B8G8R8X8_UNORM ||
236 rb->Format == MESA_FORMAT_B8G8R8A8_UNORM)) {
237 fast_draw_rgba_ubyte_pixels(ctx, rb, x, y, width, height,
238 &unpack, pixels);
239 return GL_TRUE;
240 }
241
242 if (_mesa_format_matches_format_and_type(rb->Format, format, type,
243 ctx->Unpack.SwapBytes)) {
244 fast_draw_generic_pixels(ctx, rb, x, y, width, height,
245 format, type, &unpack, pixels);
246 return GL_TRUE;
247 }
248
249 /* can't handle this pixel format and/or data type */
250 return GL_FALSE;
251 }
252
253
254
255 /*
256 * Draw stencil image.
257 */
258 static void
259 draw_stencil_pixels( struct gl_context *ctx, GLint x, GLint y,
260 GLsizei width, GLsizei height,
261 GLenum type,
262 const struct gl_pixelstore_attrib *unpack,
263 const GLvoid *pixels )
264 {
265 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
266 const GLenum destType = GL_UNSIGNED_BYTE;
267 GLint row;
268 GLubyte *values;
269
270 values = malloc(width * sizeof(GLubyte));
271 if (!values) {
272 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
273 return;
274 }
275
276 for (row = 0; row < height; row++) {
277 const GLvoid *source = _mesa_image_address2d(unpack, pixels,
278 width, height,
279 GL_STENCIL_INDEX, type,
280 row, 0);
281 _mesa_unpack_stencil_span(ctx, width, destType, values,
282 type, source, unpack,
283 ctx->_ImageTransferState);
284 if (zoom) {
285 _swrast_write_zoomed_stencil_span(ctx, x, y, width,
286 x, y, values);
287 }
288 else {
289 _swrast_write_stencil_span(ctx, width, x, y, values);
290 }
291
292 y++;
293 }
294
295 free(values);
296 }
297
298
299 /*
300 * Draw depth image.
301 */
302 static void
303 draw_depth_pixels( struct gl_context *ctx, GLint x, GLint y,
304 GLsizei width, GLsizei height,
305 GLenum type,
306 const struct gl_pixelstore_attrib *unpack,
307 const GLvoid *pixels )
308 {
309 const GLboolean scaleOrBias
310 = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
311 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
312 SWspan span;
313
314 INIT_SPAN(span, GL_BITMAP);
315 span.arrayMask = SPAN_Z;
316 _swrast_span_default_attribs(ctx, &span);
317
318 if (type == GL_UNSIGNED_SHORT
319 && ctx->DrawBuffer->Visual.depthBits == 16
320 && !scaleOrBias
321 && !zoom
322 && width <= SWRAST_MAX_WIDTH
323 && !unpack->SwapBytes) {
324 /* Special case: directly write 16-bit depth values */
325 GLint row;
326 for (row = 0; row < height; row++) {
327 const GLushort *zSrc = (const GLushort *)
328 _mesa_image_address2d(unpack, pixels, width, height,
329 GL_DEPTH_COMPONENT, type, row, 0);
330 GLint i;
331 for (i = 0; i < width; i++)
332 span.array->z[i] = zSrc[i];
333 span.x = x;
334 span.y = y + row;
335 span.end = width;
336 _swrast_write_rgba_span(ctx, &span);
337 }
338 }
339 else if (type == GL_UNSIGNED_INT
340 && !scaleOrBias
341 && !zoom
342 && width <= SWRAST_MAX_WIDTH
343 && !unpack->SwapBytes) {
344 /* Special case: shift 32-bit values down to Visual.depthBits */
345 const GLint shift = 32 - ctx->DrawBuffer->Visual.depthBits;
346 GLint row;
347 for (row = 0; row < height; row++) {
348 const GLuint *zSrc = (const GLuint *)
349 _mesa_image_address2d(unpack, pixels, width, height,
350 GL_DEPTH_COMPONENT, type, row, 0);
351 if (shift == 0) {
352 memcpy(span.array->z, zSrc, width * sizeof(GLuint));
353 }
354 else {
355 GLint col;
356 for (col = 0; col < width; col++)
357 span.array->z[col] = zSrc[col] >> shift;
358 }
359 span.x = x;
360 span.y = y + row;
361 span.end = width;
362 _swrast_write_rgba_span(ctx, &span);
363 }
364 }
365 else {
366 /* General case */
367 const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
368 GLint skipPixels = 0;
369
370 /* in case width > SWRAST_MAX_WIDTH do the copy in chunks */
371 while (skipPixels < width) {
372 const GLint spanWidth = MIN2(width - skipPixels, SWRAST_MAX_WIDTH);
373 GLint row;
374 ASSERT(span.end <= SWRAST_MAX_WIDTH);
375 for (row = 0; row < height; row++) {
376 const GLvoid *zSrc = _mesa_image_address2d(unpack,
377 pixels, width, height,
378 GL_DEPTH_COMPONENT, type,
379 row, skipPixels);
380
381 /* Set these for each row since the _swrast_write_* function may
382 * change them while clipping.
383 */
384 span.x = x + skipPixels;
385 span.y = y + row;
386 span.end = spanWidth;
387
388 _mesa_unpack_depth_span(ctx, spanWidth,
389 GL_UNSIGNED_INT, span.array->z, depthMax,
390 type, zSrc, unpack);
391 if (zoom) {
392 _swrast_write_zoomed_depth_span(ctx, x, y, &span);
393 }
394 else {
395 _swrast_write_rgba_span(ctx, &span);
396 }
397 }
398 skipPixels += spanWidth;
399 }
400 }
401 }
402
403
404
405 /**
406 * Draw RGBA image.
407 */
408 static void
409 draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y,
410 GLsizei width, GLsizei height,
411 GLenum format, GLenum type,
412 const struct gl_pixelstore_attrib *unpack,
413 const GLvoid *pixels )
414 {
415 const GLint imgX = x, imgY = y;
416 const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
417 GLbitfield transferOps = ctx->_ImageTransferState;
418 SWspan span;
419
420 /* Try an optimized glDrawPixels first */
421 if (fast_draw_rgba_pixels(ctx, x, y, width, height, format, type,
422 unpack, pixels)) {
423 return;
424 }
425
426 swrast_render_start(ctx);
427
428 INIT_SPAN(span, GL_BITMAP);
429 _swrast_span_default_attribs(ctx, &span);
430 span.arrayMask = SPAN_RGBA;
431 span.arrayAttribs = VARYING_BIT_COL0; /* we're fill in COL0 attrib values */
432
433 if (ctx->DrawBuffer->_NumColorDrawBuffers > 0) {
434 GLenum datatype = _mesa_get_format_datatype(
435 ctx->DrawBuffer->_ColorDrawBuffers[0]->Format);
436 if (datatype != GL_FLOAT &&
437 ctx->Color.ClampFragmentColor != GL_FALSE) {
438 /* need to clamp colors before applying fragment ops */
439 transferOps |= IMAGE_CLAMP_BIT;
440 }
441 }
442
443 /*
444 * General solution
445 */
446 {
447 const GLbitfield interpMask = span.interpMask;
448 const GLbitfield arrayMask = span.arrayMask;
449 const GLint srcStride
450 = _mesa_image_row_stride(unpack, width, format, type);
451 GLint skipPixels = 0;
452 /* use span array for temp color storage */
453 GLfloat *rgba = (GLfloat *) span.array->attribs[VARYING_SLOT_COL0];
454
455 /* if the span is wider than SWRAST_MAX_WIDTH we have to do it in chunks */
456 while (skipPixels < width) {
457 const GLint spanWidth = MIN2(width - skipPixels, SWRAST_MAX_WIDTH);
458 const GLubyte *source
459 = (const GLubyte *) _mesa_image_address2d(unpack, pixels,
460 width, height, format,
461 type, 0, skipPixels);
462 GLint row;
463
464 for (row = 0; row < height; row++) {
465 /* get image row as float/RGBA */
466 _mesa_unpack_color_span_float(ctx, spanWidth, GL_RGBA, rgba,
467 format, type, source, unpack,
468 transferOps);
469 /* Set these for each row since the _swrast_write_* functions
470 * may change them while clipping/rendering.
471 */
472 span.array->ChanType = GL_FLOAT;
473 span.x = x + skipPixels;
474 span.y = y + row;
475 span.end = spanWidth;
476 span.arrayMask = arrayMask;
477 span.interpMask = interpMask;
478 if (zoom) {
479 _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, rgba);
480 }
481 else {
482 _swrast_write_rgba_span(ctx, &span);
483 }
484
485 source += srcStride;
486 } /* for row */
487
488 skipPixels += spanWidth;
489 } /* while skipPixels < width */
490
491 /* XXX this is ugly/temporary, to undo above change */
492 span.array->ChanType = CHAN_TYPE;
493 }
494
495 swrast_render_finish(ctx);
496 }
497
498
499 /**
500 * Draw depth+stencil values into a MESA_FORAMT_Z24_S8 or MESA_FORMAT_Z24_UNORM_S8_UINT
501 * renderbuffer. No masking, zooming, scaling, etc.
502 */
503 static void
504 fast_draw_depth_stencil(struct gl_context *ctx, GLint x, GLint y,
505 GLsizei width, GLsizei height,
506 const struct gl_pixelstore_attrib *unpack,
507 const GLvoid *pixels)
508 {
509 const GLenum format = GL_DEPTH_STENCIL_EXT;
510 const GLenum type = GL_UNSIGNED_INT_24_8;
511 struct gl_renderbuffer *rb =
512 ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
513 struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
514 GLubyte *src, *dst;
515 GLint srcRowStride, dstRowStride;
516 GLint i;
517
518 src = _mesa_image_address2d(unpack, pixels, width, height,
519 format, type, 0, 0);
520 srcRowStride = _mesa_image_row_stride(unpack, width, format, type);
521
522 dst = _swrast_pixel_address(rb, x, y);
523 dstRowStride = srb->RowStride;
524
525 for (i = 0; i < height; i++) {
526 _mesa_pack_uint_24_8_depth_stencil_row(rb->Format, width,
527 (const GLuint *) src, dst);
528 dst += dstRowStride;
529 src += srcRowStride;
530 }
531 }
532
533
534
535 /**
536 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
537 * The only per-pixel operations that apply are depth scale/bias,
538 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
539 * and pixel zoom.
540 * Also, only the depth buffer and stencil buffers are touched, not the
541 * color buffer(s).
542 */
543 static void
544 draw_depth_stencil_pixels(struct gl_context *ctx, GLint x, GLint y,
545 GLsizei width, GLsizei height, GLenum type,
546 const struct gl_pixelstore_attrib *unpack,
547 const GLvoid *pixels)
548 {
549 const GLint imgX = x, imgY = y;
550 const GLboolean scaleOrBias
551 = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
552 const GLuint stencilMask = ctx->Stencil.WriteMask[0];
553 const GLenum stencilType = GL_UNSIGNED_BYTE;
554 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
555 struct gl_renderbuffer *depthRb, *stencilRb;
556 struct gl_pixelstore_attrib clippedUnpack = *unpack;
557
558 if (!zoom) {
559 if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height,
560 &clippedUnpack)) {
561 /* totally clipped */
562 return;
563 }
564 }
565
566 depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
567 stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
568 ASSERT(depthRb);
569 ASSERT(stencilRb);
570
571 if (depthRb == stencilRb &&
572 (depthRb->Format == MESA_FORMAT_S8_UINT_Z24_UNORM ||
573 depthRb->Format == MESA_FORMAT_Z24_UNORM_S8_UINT) &&
574 type == GL_UNSIGNED_INT_24_8 &&
575 !scaleOrBias &&
576 !zoom &&
577 ctx->Depth.Mask &&
578 (stencilMask & 0xff) == 0xff) {
579 fast_draw_depth_stencil(ctx, x, y, width, height,
580 &clippedUnpack, pixels);
581 }
582 else {
583 /* sub-optimal cases:
584 * Separate depth/stencil buffers, or pixel transfer ops required.
585 */
586 /* XXX need to handle very wide images (skippixels) */
587 GLuint *zValues; /* 32-bit Z values */
588 GLint i;
589
590 zValues = malloc(width * sizeof(GLuint));
591 if (!zValues) {
592 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
593 return;
594 }
595
596 for (i = 0; i < height; i++) {
597 const GLuint *depthStencilSrc = (const GLuint *)
598 _mesa_image_address2d(&clippedUnpack, pixels, width, height,
599 GL_DEPTH_STENCIL_EXT, type, i, 0);
600
601 if (ctx->Depth.Mask) {
602 _mesa_unpack_depth_span(ctx, width,
603 GL_UNSIGNED_INT, /* dest type */
604 zValues, /* dest addr */
605 0xffffffff, /* depth max */
606 type, /* src type */
607 depthStencilSrc, /* src addr */
608 &clippedUnpack);
609 if (zoom) {
610 _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,
611 y + i, zValues);
612 }
613 else {
614 GLubyte *dst = _swrast_pixel_address(depthRb, x, y + i);
615 _mesa_pack_uint_z_row(depthRb->Format, width, zValues, dst);
616 }
617 }
618
619 if (stencilMask != 0x0) {
620 GLubyte *stencilValues = (GLubyte *) zValues; /* re-use buffer */
621 /* get stencil values, with shift/offset/mapping */
622 _mesa_unpack_stencil_span(ctx, width, stencilType, stencilValues,
623 type, depthStencilSrc, &clippedUnpack,
624 ctx->_ImageTransferState);
625 if (zoom)
626 _swrast_write_zoomed_stencil_span(ctx, imgX, imgY, width,
627 x, y + i, stencilValues);
628 else
629 _swrast_write_stencil_span(ctx, width, x, y + i, stencilValues);
630 }
631 }
632
633 free(zValues);
634 }
635 }
636
637
638 /**
639 * Execute software-based glDrawPixels.
640 * By time we get here, all error checking will have been done.
641 */
642 void
643 _swrast_DrawPixels( struct gl_context *ctx,
644 GLint x, GLint y,
645 GLsizei width, GLsizei height,
646 GLenum format, GLenum type,
647 const struct gl_pixelstore_attrib *unpack,
648 const GLvoid *pixels )
649 {
650 SWcontext *swrast = SWRAST_CONTEXT(ctx);
651 GLboolean save_vp_override = ctx->VertexProgram._Overriden;
652
653 if (!_mesa_check_conditional_render(ctx))
654 return; /* don't draw */
655
656 /* We are creating fragments directly, without going through vertex
657 * programs.
658 *
659 * This override flag tells the fragment processing code that its input
660 * comes from a non-standard source, and it may therefore not rely on
661 * optimizations that assume e.g. constant color if there is no color
662 * vertex array.
663 */
664 _mesa_set_vp_override(ctx, GL_TRUE);
665
666 if (ctx->NewState)
667 _mesa_update_state(ctx);
668
669 if (swrast->NewState)
670 _swrast_validate_derived( ctx );
671
672 pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
673 if (!pixels) {
674 _mesa_set_vp_override(ctx, save_vp_override);
675 return;
676 }
677
678 /*
679 * By time we get here, all error checking should have been done.
680 */
681 switch (format) {
682 case GL_STENCIL_INDEX:
683 swrast_render_start(ctx);
684 draw_stencil_pixels( ctx, x, y, width, height, type, unpack, pixels );
685 swrast_render_finish(ctx);
686 break;
687 case GL_DEPTH_COMPONENT:
688 swrast_render_start(ctx);
689 draw_depth_pixels( ctx, x, y, width, height, type, unpack, pixels );
690 swrast_render_finish(ctx);
691 break;
692 case GL_DEPTH_STENCIL_EXT:
693 swrast_render_start(ctx);
694 draw_depth_stencil_pixels(ctx, x, y, width, height, type, unpack, pixels);
695 swrast_render_finish(ctx);
696 break;
697 default:
698 /* all other formats should be color formats */
699 draw_rgba_pixels(ctx, x, y, width, height, format, type, unpack, pixels);
700 }
701
702 _mesa_set_vp_override(ctx, save_vp_override);
703
704 _mesa_unmap_pbo_source(ctx, unpack);
705 }