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 (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
;
304 /* can't handle this pixel format and/or data type */
311 * Draw stencil image.
314 draw_stencil_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
315 GLsizei width
, GLsizei height
,
317 const struct gl_pixelstore_attrib
*unpack
,
318 const GLvoid
*pixels
)
320 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
323 /* if width > MAX_WIDTH, have to process image in chunks */
325 while (skipPixels
< width
) {
326 const GLint spanX
= x
+ skipPixels
;
327 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
329 for (row
= 0; row
< height
; row
++) {
330 const GLint spanY
= y
+ row
;
331 GLstencil values
[MAX_WIDTH
];
332 GLenum destType
= (sizeof(GLstencil
) == sizeof(GLubyte
))
333 ? GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
334 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
336 GL_COLOR_INDEX
, type
,
338 _mesa_unpack_stencil_span(ctx
, spanWidth
, destType
, values
,
339 type
, source
, unpack
,
340 ctx
->_ImageTransferState
);
342 _swrast_write_zoomed_stencil_span(ctx
, x
, y
, spanWidth
,
343 spanX
, spanY
, values
);
346 _swrast_write_stencil_span(ctx
, spanWidth
, spanX
, spanY
, values
);
349 skipPixels
+= spanWidth
;
358 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
359 GLsizei width
, GLsizei height
,
361 const struct gl_pixelstore_attrib
*unpack
,
362 const GLvoid
*pixels
)
364 const GLboolean scaleOrBias
365 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
366 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
369 INIT_SPAN(span
, GL_BITMAP
);
370 span
.arrayMask
= SPAN_Z
;
371 _swrast_span_default_attribs(ctx
, &span
);
373 if (type
== GL_UNSIGNED_SHORT
374 && ctx
->DrawBuffer
->Visual
.depthBits
== 16
377 && width
<= MAX_WIDTH
378 && !unpack
->SwapBytes
) {
379 /* Special case: directly write 16-bit depth values */
381 for (row
= 0; row
< height
; row
++) {
382 const GLushort
*zSrc
= (const GLushort
*)
383 _mesa_image_address2d(unpack
, pixels
, width
, height
,
384 GL_DEPTH_COMPONENT
, type
, row
, 0);
386 for (i
= 0; i
< width
; i
++)
387 span
.array
->z
[i
] = zSrc
[i
];
391 _swrast_write_rgba_span(ctx
, &span
);
394 else if (type
== GL_UNSIGNED_INT
397 && width
<= MAX_WIDTH
398 && !unpack
->SwapBytes
) {
399 /* Special case: shift 32-bit values down to Visual.depthBits */
400 const GLint shift
= 32 - ctx
->DrawBuffer
->Visual
.depthBits
;
402 for (row
= 0; row
< height
; row
++) {
403 const GLuint
*zSrc
= (const GLuint
*)
404 _mesa_image_address2d(unpack
, pixels
, width
, height
,
405 GL_DEPTH_COMPONENT
, type
, row
, 0);
407 memcpy(span
.array
->z
, zSrc
, width
* sizeof(GLuint
));
411 for (col
= 0; col
< width
; col
++)
412 span
.array
->z
[col
] = zSrc
[col
] >> shift
;
417 _swrast_write_rgba_span(ctx
, &span
);
422 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
423 GLint skipPixels
= 0;
425 /* in case width > MAX_WIDTH do the copy in chunks */
426 while (skipPixels
< width
) {
427 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
429 ASSERT(span
.end
<= MAX_WIDTH
);
430 for (row
= 0; row
< height
; row
++) {
431 const GLvoid
*zSrc
= _mesa_image_address2d(unpack
,
432 pixels
, width
, height
,
433 GL_DEPTH_COMPONENT
, type
,
436 /* Set these for each row since the _swrast_write_* function may
437 * change them while clipping.
439 span
.x
= x
+ skipPixels
;
441 span
.end
= spanWidth
;
443 _mesa_unpack_depth_span(ctx
, spanWidth
,
444 GL_UNSIGNED_INT
, span
.array
->z
, depthMax
,
447 _swrast_write_zoomed_depth_span(ctx
, x
, y
, &span
);
450 _swrast_write_rgba_span(ctx
, &span
);
453 skipPixels
+= spanWidth
;
464 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
465 GLsizei width
, GLsizei height
,
466 GLenum format
, GLenum type
,
467 const struct gl_pixelstore_attrib
*unpack
,
468 const GLvoid
*pixels
)
470 const GLint imgX
= x
, imgY
= y
;
471 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
472 GLfloat
*convImage
= NULL
;
473 GLbitfield transferOps
= ctx
->_ImageTransferState
;
476 /* Try an optimized glDrawPixels first */
477 if (fast_draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
,
482 INIT_SPAN(span
, GL_BITMAP
);
483 _swrast_span_default_attribs(ctx
, &span
);
484 span
.arrayMask
= SPAN_RGBA
;
485 span
.arrayAttribs
= FRAG_BIT_COL0
; /* we're fill in COL0 attrib values */
487 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
488 /* Convolution has to be handled specially. We'll create an
489 * intermediate image, applying all pixel transfer operations
490 * up to convolution. Then we'll convolve the image. Then
491 * we'll proceed with the rest of the transfer operations and
492 * rasterize the image.
495 GLfloat
*dest
, *tmpImage
;
497 tmpImage
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
499 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
502 convImage
= (GLfloat
*) malloc(width
* height
* 4 * sizeof(GLfloat
));
505 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
509 /* Unpack the image and apply transfer ops up to convolution */
511 for (row
= 0; row
< height
; row
++) {
512 const GLvoid
*source
= _mesa_image_address2d(unpack
,
513 pixels
, width
, height
, format
, type
, row
, 0);
514 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
, (GLfloat
*) dest
,
515 format
, type
, source
, unpack
,
516 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
);
521 if (ctx
->Pixel
.Convolution2DEnabled
) {
522 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
525 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
526 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
530 /* continue transfer ops and draw the convolved image */
531 unpack
= &ctx
->DefaultPacking
;
535 transferOps
&= IMAGE_POST_CONVOLUTION_BITS
;
537 else if (ctx
->Pixel
.Convolution1DEnabled
) {
538 /* we only want to apply 1D convolution to glTexImage1D */
539 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
540 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
543 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
> 0 &&
544 ctx
->DrawBuffer
->_ColorDrawBuffers
[0]->DataType
!= GL_FLOAT
&&
545 ctx
->Color
.ClampFragmentColor
!= GL_FALSE
) {
546 /* need to clamp colors before applying fragment ops */
547 transferOps
|= IMAGE_CLAMP_BIT
;
554 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
555 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
556 const GLbitfield interpMask
= span
.interpMask
;
557 const GLbitfield arrayMask
= span
.arrayMask
;
558 const GLint srcStride
559 = _mesa_image_row_stride(unpack
, width
, format
, type
);
560 GLint skipPixels
= 0;
561 /* use span array for temp color storage */
562 GLfloat
*rgba
= (GLfloat
*) span
.array
->attribs
[FRAG_ATTRIB_COL0
];
564 /* if the span is wider than MAX_WIDTH we have to do it in chunks */
565 while (skipPixels
< width
) {
566 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
567 const GLubyte
*source
568 = (const GLubyte
*) _mesa_image_address2d(unpack
, pixels
,
569 width
, height
, format
,
570 type
, 0, skipPixels
);
573 for (row
= 0; row
< height
; row
++) {
574 /* get image row as float/RGBA */
575 _mesa_unpack_color_span_float(ctx
, spanWidth
, GL_RGBA
, rgba
,
576 format
, type
, source
, unpack
,
580 /* Set these for each row since the _swrast_write_* functions
581 * may change them while clipping/rendering.
583 span
.array
->ChanType
= GL_FLOAT
;
584 span
.x
= x
+ skipPixels
;
586 span
.end
= spanWidth
;
587 span
.arrayMask
= arrayMask
;
588 span
.interpMask
= interpMask
;
590 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, rgba
);
593 _swrast_write_rgba_span(ctx
, &span
);
600 skipPixels
+= spanWidth
;
601 } /* while skipPixels < width */
603 /* XXX this is ugly/temporary, to undo above change */
604 span
.array
->ChanType
= CHAN_TYPE
;
614 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
615 * The only per-pixel operations that apply are depth scale/bias,
616 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
618 * Also, only the depth buffer and stencil buffers are touched, not the
622 draw_depth_stencil_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
623 GLsizei width
, GLsizei height
, GLenum type
,
624 const struct gl_pixelstore_attrib
*unpack
,
625 const GLvoid
*pixels
)
627 const GLint imgX
= x
, imgY
= y
;
628 const GLboolean scaleOrBias
629 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
630 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
631 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
632 const GLuint stencilType
= (STENCIL_BITS
== 8) ?
633 GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
634 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
635 struct gl_renderbuffer
*depthRb
, *stencilRb
;
636 struct gl_pixelstore_attrib clippedUnpack
= *unpack
;
639 if (!_mesa_clip_drawpixels(ctx
, &x
, &y
, &width
, &height
,
641 /* totally clipped */
646 depthRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
647 stencilRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
651 if (depthRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
652 stencilRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
653 depthRb
== stencilRb
&&
657 (stencilMask
& 0xff) == 0xff) {
658 /* This is the ideal case.
659 * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
660 * Plus, no pixel transfer ops, zooming, or masking needed.
663 for (i
= 0; i
< height
; i
++) {
664 const GLuint
*src
= (const GLuint
*)
665 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
666 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
667 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, src
, NULL
);
671 /* sub-optimal cases:
672 * Separate depth/stencil buffers, or pixel transfer ops required.
674 /* XXX need to handle very wide images (skippixels) */
677 depthRb
= ctx
->DrawBuffer
->_DepthBuffer
;
678 stencilRb
= ctx
->DrawBuffer
->_StencilBuffer
;
680 for (i
= 0; i
< height
; i
++) {
681 const GLuint
*depthStencilSrc
= (const GLuint
*)
682 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
683 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
685 if (ctx
->Depth
.Mask
) {
686 if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 24) {
687 /* fast path 24-bit zbuffer */
688 GLuint zValues
[MAX_WIDTH
];
690 ASSERT(depthRb
->DataType
== GL_UNSIGNED_INT
);
691 for (j
= 0; j
< width
; j
++) {
692 zValues
[j
] = depthStencilSrc
[j
] >> 8;
695 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
698 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
700 else if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 16) {
701 /* fast path 16-bit zbuffer */
702 GLushort zValues
[MAX_WIDTH
];
704 ASSERT(depthRb
->DataType
== GL_UNSIGNED_SHORT
);
705 for (j
= 0; j
< width
; j
++) {
706 zValues
[j
] = depthStencilSrc
[j
] >> 16;
709 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
712 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
716 GLuint zValues
[MAX_WIDTH
]; /* 16 or 32-bit Z value storage */
717 _mesa_unpack_depth_span(ctx
, width
,
718 depthRb
->DataType
, zValues
, depthMax
,
719 type
, depthStencilSrc
, &clippedUnpack
);
721 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
, x
,
725 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
730 if (stencilMask
!= 0x0) {
731 GLstencil stencilValues
[MAX_WIDTH
];
732 /* get stencil values, with shift/offset/mapping */
733 _mesa_unpack_stencil_span(ctx
, width
, stencilType
, stencilValues
,
734 type
, depthStencilSrc
, &clippedUnpack
,
735 ctx
->_ImageTransferState
);
737 _swrast_write_zoomed_stencil_span(ctx
, imgX
, imgY
, width
,
738 x
, y
+ i
, stencilValues
);
740 _swrast_write_stencil_span(ctx
, width
, x
, y
+ i
, stencilValues
);
748 * Execute software-based glDrawPixels.
749 * By time we get here, all error checking will have been done.
752 _swrast_DrawPixels( GLcontext
*ctx
,
754 GLsizei width
, GLsizei height
,
755 GLenum format
, GLenum type
,
756 const struct gl_pixelstore_attrib
*unpack
,
757 const GLvoid
*pixels
)
759 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
760 GLboolean save_vp_override
= ctx
->VertexProgram
._Overriden
;
762 if (!_mesa_check_conditional_render(ctx
))
763 return; /* don't draw */
765 /* We are creating fragments directly, without going through vertex
768 * This override flag tells the fragment processing code that its input
769 * comes from a non-standard source, and it may therefore not rely on
770 * optimizations that assume e.g. constant color if there is no color
773 _mesa_set_vp_override(ctx
, GL_TRUE
);
775 swrast_render_start(ctx
);
778 _mesa_update_state(ctx
);
780 if (swrast
->NewState
)
781 _swrast_validate_derived( ctx
);
783 pixels
= _mesa_map_pbo_source(ctx
, unpack
, pixels
);
785 swrast_render_finish(ctx
);
786 _mesa_set_vp_override(ctx
, save_vp_override
);
791 case GL_STENCIL_INDEX
:
792 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
794 case GL_DEPTH_COMPONENT
:
795 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
803 case GL_LUMINANCE_ALPHA
:
809 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
811 case GL_DEPTH_STENCIL_EXT
:
812 draw_depth_stencil_pixels(ctx
, x
, y
, width
, height
,
813 type
, unpack
, pixels
);
816 _mesa_problem(ctx
, "unexpected format in _swrast_DrawPixels");
817 /* don't return yet, clean-up */
820 swrast_render_finish(ctx
);
821 _mesa_set_vp_override(ctx
, save_vp_override
);
823 _mesa_unmap_pbo_source(ctx
, unpack
);