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.
26 #include "main/glheader.h"
27 #include "main/bufferobj.h"
28 #include "main/condrender.h"
29 #include "main/context.h"
30 #include "main/convolve.h"
31 #include "main/image.h"
32 #include "main/macros.h"
33 #include "main/imports.h"
34 #include "main/state.h"
36 #include "s_context.h"
38 #include "s_stencil.h"
44 * Try to do a fast and simple RGB(a) glDrawPixels.
45 * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
48 fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y,
49 GLsizei width, GLsizei height,
50 GLenum format, GLenum type,
51 const struct gl_pixelstore_attrib *userUnpack,
54 const GLint imgX = x, imgY = y;
55 struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
57 SWcontext *swrast = SWRAST_CONTEXT(ctx);
60 GLint yStep; /* +1 or -1 */
61 struct gl_pixelstore_attrib unpack;
62 GLint destX, destY, drawWidth, drawHeight; /* post clipping */
65 return GL_TRUE; /* no-op */
67 rbType = rb->DataType;
69 if ((swrast->_RasterMask & ~CLIP_BIT) ||
70 ctx->Texture._EnabledCoordUnits ||
71 userUnpack->SwapBytes ||
72 ctx->_ImageTransferState) {
73 /* can't handle any of those conditions */
77 INIT_SPAN(span, GL_BITMAP);
78 span.arrayMask = SPAN_RGBA;
79 span.arrayAttribs = FRAG_BIT_COL0;
80 _swrast_span_default_attribs(ctx, &span);
82 /* copy input params since clipping may change them */
89 /* check for simple zooming and clipping */
90 if (ctx->Pixel.ZoomX == 1.0F &&
91 (ctx->Pixel.ZoomY == 1.0F || ctx->Pixel.ZoomY == -1.0F)) {
92 if (!_mesa_clip_drawpixels(ctx, &destX, &destY,
93 &drawWidth, &drawHeight, &unpack)) {
94 /* image was completely clipped: no-op, all done */
98 yStep = (GLint) ctx->Pixel.ZoomY;
99 ASSERT(yStep == 1 || yStep == -1);
102 /* non-simple zooming */
103 simpleZoom = GL_FALSE;
105 if (unpack.RowLength == 0)
106 unpack.RowLength = width;
113 if (format == GL_RGBA && type == rbType) {
115 = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width,
116 height, format, type, 0, 0);
117 const GLint srcStride = _mesa_image_row_stride(&unpack, width,
121 for (row = 0; row < drawHeight; row++) {
122 rb->PutRow(ctx, rb, drawWidth, destX, destY, src, NULL);
130 for (row = 0; row < drawHeight; row++) {
132 span.y = destY + row;
133 span.end = drawWidth;
134 span.array->ChanType = rbType;
135 _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, src);
138 span.array->ChanType = CHAN_TYPE;
143 if (format == GL_RGB && type == rbType) {
145 = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width,
146 height, format, type, 0, 0);
147 const GLint srcStride = _mesa_image_row_stride(&unpack, width,
151 for (row = 0; row < drawHeight; row++) {
152 rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, src, NULL);
160 for (row = 0; row < drawHeight; row++) {
163 span.end = drawWidth;
164 span.array->ChanType = rbType;
165 _swrast_write_zoomed_rgb_span(ctx, imgX, imgY, &span, src);
169 span.array->ChanType = CHAN_TYPE;
174 /* Remaining cases haven't been tested with alignment != 1 */
175 if (userUnpack->Alignment != 1)
178 if (format == GL_LUMINANCE && type == CHAN_TYPE && rbType == CHAN_TYPE) {
179 const GLchan *src = (const GLchan *) pixels
180 + (unpack.SkipRows * unpack.RowLength + unpack.SkipPixels);
184 ASSERT(drawWidth <= MAX_WIDTH);
185 for (row = 0; row < drawHeight; row++) {
186 GLchan rgb[MAX_WIDTH][3];
188 for (i = 0;i<drawWidth;i++) {
193 rb->PutRowRGB(ctx, rb, drawWidth, destX, destY, rgb, NULL);
194 src += unpack.RowLength;
201 ASSERT(drawWidth <= MAX_WIDTH);
202 for (row = 0; row < drawHeight; row++) {
203 GLchan rgb[MAX_WIDTH][3];
205 for (i = 0;i<drawWidth;i++) {
212 span.end = drawWidth;
213 _swrast_write_zoomed_rgb_span(ctx, imgX, imgY, &span, rgb);
214 src += unpack.RowLength;
221 if (format == GL_LUMINANCE_ALPHA && type == CHAN_TYPE && rbType == CHAN_TYPE) {
222 const GLchan *src = (const GLchan *) pixels
223 + (unpack.SkipRows * unpack.RowLength + unpack.SkipPixels)*2;
226 ASSERT(drawWidth <= MAX_WIDTH);
227 for (row = 0; row < drawHeight; row++) {
229 const GLchan *ptr = src;
230 for (i = 0;i<drawWidth;i++) {
231 span.array->rgba[i][0] = *ptr;
232 span.array->rgba[i][1] = *ptr;
233 span.array->rgba[i][2] = *ptr++;
234 span.array->rgba[i][3] = *ptr++;
236 rb->PutRow(ctx, rb, drawWidth, destX, destY,
237 span.array->rgba, NULL);
238 src += unpack.RowLength*2;
245 ASSERT(drawWidth <= MAX_WIDTH);
246 for (row = 0; row < drawHeight; row++) {
247 const GLchan *ptr = src;
249 for (i = 0;i<drawWidth;i++) {
250 span.array->rgba[i][0] = *ptr;
251 span.array->rgba[i][1] = *ptr;
252 span.array->rgba[i][2] = *ptr++;
253 span.array->rgba[i][3] = *ptr++;
257 span.end = drawWidth;
258 _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span,
260 src += unpack.RowLength*2;
267 if (format == GL_COLOR_INDEX && type == GL_UNSIGNED_BYTE) {
268 const GLubyte *src = (const GLubyte *) pixels
269 + unpack.SkipRows * unpack.RowLength + unpack.SkipPixels;
270 if (ctx->Visual.rgbMode && rbType == GL_UNSIGNED_BYTE) {
271 /* convert ubyte/CI data to ubyte/RGBA */
274 for (row = 0; row < drawHeight; row++) {
275 ASSERT(drawWidth <= MAX_WIDTH);
276 _mesa_map_ci8_to_rgba8(ctx, drawWidth, src,
278 rb->PutRow(ctx, rb, drawWidth, destX, destY,
279 span.array->rgba8, NULL);
280 src += unpack.RowLength;
285 /* ubyte/CI to ubyte/RGBA with zooming */
287 for (row = 0; row < drawHeight; row++) {
288 ASSERT(drawWidth <= MAX_WIDTH);
289 _mesa_map_ci8_to_rgba8(ctx, drawWidth, src,
293 span.end = drawWidth;
294 _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span,
296 src += unpack.RowLength;
302 else if (!ctx->Visual.rgbMode && rbType == GL_UNSIGNED_INT) {
303 /* write CI data to CI frame buffer */
306 for (row = 0; row < drawHeight; row++) {
307 GLuint index32[MAX_WIDTH];
309 for (col = 0; col < drawWidth; col++)
310 index32[col] = src[col];
311 rb->PutRow(ctx, rb, drawWidth, destX, destY, index32, NULL);
312 src += unpack.RowLength;
320 /* can't handle this pixel format and/or data type */
327 * Draw color index image.
330 draw_index_pixels( GLcontext *ctx, GLint x, GLint y,
331 GLsizei width, GLsizei height,
333 const struct gl_pixelstore_attrib *unpack,
334 const GLvoid *pixels )
336 const GLint imgX = x, imgY = y;
337 const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
338 GLint row, skipPixels;
341 INIT_SPAN(span, GL_BITMAP);
342 span.arrayMask = SPAN_INDEX;
343 _swrast_span_default_attribs(ctx, &span);
349 while (skipPixels < width) {
350 const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
351 ASSERT(spanWidth <= MAX_WIDTH);
352 for (row = 0; row < height; row++) {
353 const GLvoid *source = _mesa_image_address2d(unpack, pixels,
355 GL_COLOR_INDEX, type,
357 _mesa_unpack_index_span(ctx, spanWidth, GL_UNSIGNED_INT,
358 span.array->index, type, source, unpack,
359 ctx->_ImageTransferState);
361 /* These may get changed during writing/clipping */
362 span.x = x + skipPixels;
364 span.end = spanWidth;
367 _swrast_write_zoomed_index_span(ctx, imgX, imgY, &span);
369 _swrast_write_index_span(ctx, &span);
371 skipPixels += spanWidth;
378 * Draw stencil image.
381 draw_stencil_pixels( GLcontext *ctx, GLint x, GLint y,
382 GLsizei width, GLsizei height,
384 const struct gl_pixelstore_attrib *unpack,
385 const GLvoid *pixels )
387 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
390 /* if width > MAX_WIDTH, have to process image in chunks */
392 while (skipPixels < width) {
393 const GLint spanX = x + skipPixels;
394 const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
396 for (row = 0; row < height; row++) {
397 const GLint spanY = y + row;
398 GLstencil values[MAX_WIDTH];
399 GLenum destType = (sizeof(GLstencil) == sizeof(GLubyte))
400 ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
401 const GLvoid *source = _mesa_image_address2d(unpack, pixels,
403 GL_COLOR_INDEX, type,
405 _mesa_unpack_stencil_span(ctx, spanWidth, destType, values,
406 type, source, unpack,
407 ctx->_ImageTransferState);
409 _swrast_write_zoomed_stencil_span(ctx, x, y, spanWidth,
410 spanX, spanY, values);
413 _swrast_write_stencil_span(ctx, spanWidth, spanX, spanY, values);
416 skipPixels += spanWidth;
425 draw_depth_pixels( GLcontext *ctx, GLint x, GLint y,
426 GLsizei width, GLsizei height,
428 const struct gl_pixelstore_attrib *unpack,
429 const GLvoid *pixels )
431 const GLboolean scaleOrBias
432 = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
433 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
436 INIT_SPAN(span, GL_BITMAP);
437 span.arrayMask = SPAN_Z;
438 _swrast_span_default_attribs(ctx, &span);
440 if (type == GL_UNSIGNED_SHORT
441 && ctx->DrawBuffer->Visual.depthBits == 16
444 && ctx->Visual.rgbMode
445 && width <= MAX_WIDTH
446 && !unpack->SwapBytes) {
447 /* Special case: directly write 16-bit depth values */
449 for (row = 0; row < height; row++) {
450 const GLushort *zSrc = (const GLushort *)
451 _mesa_image_address2d(unpack, pixels, width, height,
452 GL_DEPTH_COMPONENT, type, row, 0);
454 for (i = 0; i < width; i++)
455 span.array->z[i] = zSrc[i];
459 _swrast_write_rgba_span(ctx, &span);
462 else if (type == GL_UNSIGNED_INT
465 && ctx->Visual.rgbMode
466 && width <= MAX_WIDTH
467 && !unpack->SwapBytes) {
468 /* Special case: shift 32-bit values down to Visual.depthBits */
469 const GLint shift = 32 - ctx->DrawBuffer->Visual.depthBits;
471 for (row = 0; row < height; row++) {
472 const GLuint *zSrc = (const GLuint *)
473 _mesa_image_address2d(unpack, pixels, width, height,
474 GL_DEPTH_COMPONENT, type, row, 0);
476 _mesa_memcpy(span.array->z, zSrc, width * sizeof(GLuint));
480 for (col = 0; col < width; col++)
481 span.array->z[col] = zSrc[col] >> shift;
486 _swrast_write_rgba_span(ctx, &span);
491 const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
492 GLint skipPixels = 0;
494 /* in case width > MAX_WIDTH do the copy in chunks */
495 while (skipPixels < width) {
496 const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
498 ASSERT(span.end <= MAX_WIDTH);
499 for (row = 0; row < height; row++) {
500 const GLvoid *zSrc = _mesa_image_address2d(unpack,
501 pixels, width, height,
502 GL_DEPTH_COMPONENT, type,
505 /* Set these for each row since the _swrast_write_* function may
506 * change them while clipping.
508 span.x = x + skipPixels;
510 span.end = spanWidth;
512 _mesa_unpack_depth_span(ctx, spanWidth,
513 GL_UNSIGNED_INT, span.array->z, depthMax,
516 _swrast_write_zoomed_depth_span(ctx, x, y, &span);
518 else if (ctx->Visual.rgbMode) {
519 _swrast_write_rgba_span(ctx, &span);
522 _swrast_write_index_span(ctx, &span);
525 skipPixels += spanWidth;
536 draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
537 GLsizei width, GLsizei height,
538 GLenum format, GLenum type,
539 const struct gl_pixelstore_attrib *unpack,
540 const GLvoid *pixels )
542 const GLint imgX = x, imgY = y;
543 const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
544 GLfloat *convImage = NULL;
545 GLbitfield transferOps = ctx->_ImageTransferState;
548 /* Try an optimized glDrawPixels first */
549 if (fast_draw_rgba_pixels(ctx, x, y, width, height, format, type,
554 INIT_SPAN(span, GL_BITMAP);
555 _swrast_span_default_attribs(ctx, &span);
556 span.arrayMask = SPAN_RGBA;
557 span.arrayAttribs = FRAG_BIT_COL0; /* we're fill in COL0 attrib values */
559 if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) {
560 /* Convolution has to be handled specially. We'll create an
561 * intermediate image, applying all pixel transfer operations
562 * up to convolution. Then we'll convolve the image. Then
563 * we'll proceed with the rest of the transfer operations and
564 * rasterize the image.
567 GLfloat *dest, *tmpImage;
569 tmpImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
571 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
574 convImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
576 _mesa_free(tmpImage);
577 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
581 /* Unpack the image and apply transfer ops up to convolution */
583 for (row = 0; row < height; row++) {
584 const GLvoid *source = _mesa_image_address2d(unpack,
585 pixels, width, height, format, type, row, 0);
586 _mesa_unpack_color_span_float(ctx, width, GL_RGBA, (GLfloat *) dest,
587 format, type, source, unpack,
588 transferOps & IMAGE_PRE_CONVOLUTION_BITS);
593 if (ctx->Pixel.Convolution2DEnabled) {
594 _mesa_convolve_2d_image(ctx, &width, &height, tmpImage, convImage);
597 ASSERT(ctx->Pixel.Separable2DEnabled);
598 _mesa_convolve_sep_image(ctx, &width, &height, tmpImage, convImage);
600 _mesa_free(tmpImage);
602 /* continue transfer ops and draw the convolved image */
603 unpack = &ctx->DefaultPacking;
607 transferOps &= IMAGE_POST_CONVOLUTION_BITS;
609 else if (ctx->Pixel.Convolution1DEnabled) {
610 /* we only want to apply 1D convolution to glTexImage1D */
611 transferOps &= ~(IMAGE_CONVOLUTION_BIT |
612 IMAGE_POST_CONVOLUTION_SCALE_BIAS);
615 if (ctx->DrawBuffer->_NumColorDrawBuffers > 0 &&
616 ctx->DrawBuffer->_ColorDrawBuffers[0]->DataType != GL_FLOAT &&
617 ctx->Color.ClampFragmentColor != GL_FALSE) {
618 /* need to clamp colors before applying fragment ops */
619 transferOps |= IMAGE_CLAMP_BIT;
626 const GLboolean sink = (ctx->Pixel.MinMaxEnabled && ctx->MinMax.Sink)
627 || (ctx->Pixel.HistogramEnabled && ctx->Histogram.Sink);
628 const GLbitfield interpMask = span.interpMask;
629 const GLbitfield arrayMask = span.arrayMask;
630 const GLint srcStride
631 = _mesa_image_row_stride(unpack, width, format, type);
632 GLint skipPixels = 0;
633 /* use span array for temp color storage */
634 GLfloat *rgba = (GLfloat *) span.array->attribs[FRAG_ATTRIB_COL0];
636 /* if the span is wider than MAX_WIDTH we have to do it in chunks */
637 while (skipPixels < width) {
638 const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
639 const GLubyte *source
640 = (const GLubyte *) _mesa_image_address2d(unpack, pixels,
641 width, height, format,
642 type, 0, skipPixels);
645 for (row = 0; row < height; row++) {
646 /* get image row as float/RGBA */
647 _mesa_unpack_color_span_float(ctx, spanWidth, GL_RGBA, rgba,
648 format, type, source, unpack,
652 /* Set these for each row since the _swrast_write_* functions
653 * may change them while clipping/rendering.
655 span.array->ChanType = GL_FLOAT;
656 span.x = x + skipPixels;
658 span.end = spanWidth;
659 span.arrayMask = arrayMask;
660 span.interpMask = interpMask;
662 _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span, rgba);
665 _swrast_write_rgba_span(ctx, &span);
672 skipPixels += spanWidth;
673 } /* while skipPixels < width */
675 /* XXX this is ugly/temporary, to undo above change */
676 span.array->ChanType = CHAN_TYPE;
680 _mesa_free(convImage);
686 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
687 * The only per-pixel operations that apply are depth scale/bias,
688 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
690 * Also, only the depth buffer and stencil buffers are touched, not the
694 draw_depth_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
695 GLsizei width, GLsizei height, GLenum type,
696 const struct gl_pixelstore_attrib *unpack,
697 const GLvoid *pixels)
699 const GLint imgX = x, imgY = y;
700 const GLboolean scaleOrBias
701 = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
702 const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
703 const GLuint stencilMask = ctx->Stencil.WriteMask[0];
704 const GLuint stencilType = (STENCIL_BITS == 8) ?
705 GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
706 const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
707 struct gl_renderbuffer *depthRb, *stencilRb;
708 struct gl_pixelstore_attrib clippedUnpack = *unpack;
711 if (!_mesa_clip_drawpixels(ctx, &x, &y, &width, &height,
713 /* totally clipped */
718 depthRb = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
719 stencilRb = ctx->ReadBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
723 if (depthRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
724 stencilRb->_BaseFormat == GL_DEPTH_STENCIL_EXT &&
725 depthRb == stencilRb &&
729 (stencilMask & 0xff) == 0xff) {
730 /* This is the ideal case.
731 * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
732 * Plus, no pixel transfer ops, zooming, or masking needed.
735 for (i = 0; i < height; i++) {
736 const GLuint *src = (const GLuint *)
737 _mesa_image_address2d(&clippedUnpack, pixels, width, height,
738 GL_DEPTH_STENCIL_EXT, type, i, 0);
739 depthRb->PutRow(ctx, depthRb, width, x, y + i, src, NULL);
743 /* sub-optimal cases:
744 * Separate depth/stencil buffers, or pixel transfer ops required.
746 /* XXX need to handle very wide images (skippixels) */
749 depthRb = ctx->DrawBuffer->_DepthBuffer;
750 stencilRb = ctx->DrawBuffer->_StencilBuffer;
752 for (i = 0; i < height; i++) {
753 const GLuint *depthStencilSrc = (const GLuint *)
754 _mesa_image_address2d(&clippedUnpack, pixels, width, height,
755 GL_DEPTH_STENCIL_EXT, type, i, 0);
757 if (ctx->Depth.Mask) {
758 if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 24) {
759 /* fast path 24-bit zbuffer */
760 GLuint zValues[MAX_WIDTH];
762 ASSERT(depthRb->DataType == GL_UNSIGNED_INT);
763 for (j = 0; j < width; j++) {
764 zValues[j] = depthStencilSrc[j] >> 8;
767 _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
770 depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
772 else if (!scaleOrBias && ctx->DrawBuffer->Visual.depthBits == 16) {
773 /* fast path 16-bit zbuffer */
774 GLushort zValues[MAX_WIDTH];
776 ASSERT(depthRb->DataType == GL_UNSIGNED_SHORT);
777 for (j = 0; j < width; j++) {
778 zValues[j] = depthStencilSrc[j] >> 16;
781 _swrast_write_zoomed_z_span(ctx, imgX, imgY, width,
784 depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
788 GLuint zValues[MAX_WIDTH]; /* 16 or 32-bit Z value storage */
789 _mesa_unpack_depth_span(ctx, width,
790 depthRb->DataType, zValues, depthMax,
791 type, depthStencilSrc, &clippedUnpack);
793 _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,
797 depthRb->PutRow(ctx, depthRb, width, x, y + i, zValues,NULL);
802 if (stencilMask != 0x0) {
803 GLstencil stencilValues[MAX_WIDTH];
804 /* get stencil values, with shift/offset/mapping */
805 _mesa_unpack_stencil_span(ctx, width, stencilType, stencilValues,
806 type, depthStencilSrc, &clippedUnpack,
807 ctx->_ImageTransferState);
809 _swrast_write_zoomed_stencil_span(ctx, imgX, imgY, width,
810 x, y + i, stencilValues);
812 _swrast_write_stencil_span(ctx, width, x, y + i, stencilValues);
820 * Execute software-based glDrawPixels.
821 * By time we get here, all error checking will have been done.
824 _swrast_DrawPixels( GLcontext *ctx,
826 GLsizei width, GLsizei height,
827 GLenum format, GLenum type,
828 const struct gl_pixelstore_attrib *unpack,
829 const GLvoid *pixels )
831 SWcontext *swrast = SWRAST_CONTEXT(ctx);
832 GLboolean save_vp_override = ctx->VertexProgram._Overriden;
834 if (!_mesa_check_conditional_render(ctx))
835 return; /* don't draw */
837 /* We are creating fragments directly, without going through vertex
840 * This override flag tells the fragment processing code that its input
841 * comes from a non-standard source, and it may therefore not rely on
842 * optimizations that assume e.g. constant color if there is no color
845 _mesa_set_vp_override(ctx, GL_TRUE);
847 swrast_render_start(ctx);
850 _mesa_update_state(ctx);
852 if (swrast->NewState)
853 _swrast_validate_derived( ctx );
855 pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
857 swrast_render_finish(ctx);
858 _mesa_set_vp_override(ctx, save_vp_override);
863 case GL_STENCIL_INDEX:
864 draw_stencil_pixels( ctx, x, y, width, height, type, unpack, pixels );
866 case GL_DEPTH_COMPONENT:
867 draw_depth_pixels( ctx, x, y, width, height, type, unpack, pixels );
870 if (ctx->Visual.rgbMode)
871 draw_rgba_pixels(ctx, x,y, width, height, format, type, unpack, pixels);
873 draw_index_pixels(ctx, x, y, width, height, type, unpack, pixels);
880 case GL_LUMINANCE_ALPHA:
886 draw_rgba_pixels(ctx, x, y, width, height, format, type, unpack, pixels);
888 case GL_DEPTH_STENCIL_EXT:
889 draw_depth_stencil_pixels(ctx, x, y, width, height,
890 type, unpack, pixels);
893 _mesa_problem(ctx, "unexpected format in _swrast_DrawPixels");
894 /* don't return yet, clean-up */
897 swrast_render_finish(ctx);
898 _mesa_set_vp_override(ctx, save_vp_override);
900 _mesa_unmap_pbo_source(ctx, unpack);