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/context.h"
29 #include "main/convolve.h"
30 #include "main/image.h"
31 #include "main/macros.h"
32 #include "main/imports.h"
33 #include "main/state.h"
35 #include "s_context.h"
37 #include "s_stencil.h"
43 * Try to do a fast and simple RGB(a) glDrawPixels.
44 * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
47 fast_draw_rgba_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
48 GLsizei width
, GLsizei height
,
49 GLenum format
, GLenum type
,
50 const struct gl_pixelstore_attrib
*userUnpack
,
53 const GLint imgX
= x
, imgY
= y
;
54 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
56 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
59 GLint yStep
; /* +1 or -1 */
60 struct gl_pixelstore_attrib unpack
;
61 GLint destX
, destY
, drawWidth
, drawHeight
; /* post clipping */
64 return GL_TRUE
; /* no-op */
66 rbType
= rb
->DataType
;
68 if ((swrast
->_RasterMask
& ~CLIP_BIT
) ||
69 ctx
->Texture
._EnabledCoordUnits
||
70 userUnpack
->SwapBytes
||
71 ctx
->_ImageTransferState
) {
72 /* can't handle any of those conditions */
76 INIT_SPAN(span
, GL_BITMAP
);
77 span
.arrayMask
= SPAN_RGBA
;
78 span
.arrayAttribs
= FRAG_BIT_COL0
;
79 _swrast_span_default_attribs(ctx
, &span
);
81 /* copy input params since clipping may change them */
88 /* check for simple zooming and clipping */
89 if (ctx
->Pixel
.ZoomX
== 1.0F
&&
90 (ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
)) {
91 if (!_mesa_clip_drawpixels(ctx
, &destX
, &destY
,
92 &drawWidth
, &drawHeight
, &unpack
)) {
93 /* image was completely clipped: no-op, all done */
97 yStep
= (GLint
) ctx
->Pixel
.ZoomY
;
98 ASSERT(yStep
== 1 || yStep
== -1);
101 /* non-simple zooming */
102 simpleZoom
= GL_FALSE
;
104 if (unpack
.RowLength
== 0)
105 unpack
.RowLength
= width
;
112 if (format
== GL_RGBA
&& type
== rbType
) {
114 = (const GLubyte
*) _mesa_image_address2d(&unpack
, pixels
, width
,
115 height
, format
, type
, 0, 0);
116 const GLint srcStride
= _mesa_image_row_stride(&unpack
, width
,
120 for (row
= 0; row
< drawHeight
; row
++) {
121 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
, src
, NULL
);
129 for (row
= 0; row
< drawHeight
; row
++) {
131 span
.y
= destY
+ row
;
132 span
.end
= drawWidth
;
133 span
.array
->ChanType
= rbType
;
134 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, src
);
137 span
.array
->ChanType
= CHAN_TYPE
;
142 if (format
== GL_RGB
&& type
== rbType
) {
144 = (const GLubyte
*) _mesa_image_address2d(&unpack
, pixels
, width
,
145 height
, format
, type
, 0, 0);
146 const GLint srcStride
= _mesa_image_row_stride(&unpack
, width
,
150 for (row
= 0; row
< drawHeight
; row
++) {
151 rb
->PutRowRGB(ctx
, rb
, drawWidth
, destX
, destY
, src
, NULL
);
159 for (row
= 0; row
< drawHeight
; row
++) {
162 span
.end
= drawWidth
;
163 span
.array
->ChanType
= rbType
;
164 _swrast_write_zoomed_rgb_span(ctx
, imgX
, imgY
, &span
, src
);
168 span
.array
->ChanType
= CHAN_TYPE
;
173 /* Remaining cases haven't been tested with alignment != 1 */
174 if (userUnpack
->Alignment
!= 1)
177 if (format
== GL_LUMINANCE
&& type
== CHAN_TYPE
&& rbType
== CHAN_TYPE
) {
178 const GLchan
*src
= (const GLchan
*) pixels
179 + (unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
);
183 ASSERT(drawWidth
<= MAX_WIDTH
);
184 for (row
= 0; row
< drawHeight
; row
++) {
185 GLchan rgb
[MAX_WIDTH
][3];
187 for (i
= 0;i
<drawWidth
;i
++) {
192 rb
->PutRowRGB(ctx
, rb
, drawWidth
, destX
, destY
, rgb
, NULL
);
193 src
+= unpack
.RowLength
;
200 ASSERT(drawWidth
<= MAX_WIDTH
);
201 for (row
= 0; row
< drawHeight
; row
++) {
202 GLchan rgb
[MAX_WIDTH
][3];
204 for (i
= 0;i
<drawWidth
;i
++) {
211 span
.end
= drawWidth
;
212 _swrast_write_zoomed_rgb_span(ctx
, imgX
, imgY
, &span
, rgb
);
213 src
+= unpack
.RowLength
;
220 if (format
== GL_LUMINANCE_ALPHA
&& type
== CHAN_TYPE
&& rbType
== CHAN_TYPE
) {
221 const GLchan
*src
= (const GLchan
*) pixels
222 + (unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
)*2;
225 ASSERT(drawWidth
<= MAX_WIDTH
);
226 for (row
= 0; row
< drawHeight
; row
++) {
228 const GLchan
*ptr
= src
;
229 for (i
= 0;i
<drawWidth
;i
++) {
230 span
.array
->rgba
[i
][0] = *ptr
;
231 span
.array
->rgba
[i
][1] = *ptr
;
232 span
.array
->rgba
[i
][2] = *ptr
++;
233 span
.array
->rgba
[i
][3] = *ptr
++;
235 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
236 span
.array
->rgba
, NULL
);
237 src
+= unpack
.RowLength
*2;
244 ASSERT(drawWidth
<= MAX_WIDTH
);
245 for (row
= 0; row
< drawHeight
; row
++) {
246 const GLchan
*ptr
= src
;
248 for (i
= 0;i
<drawWidth
;i
++) {
249 span
.array
->rgba
[i
][0] = *ptr
;
250 span
.array
->rgba
[i
][1] = *ptr
;
251 span
.array
->rgba
[i
][2] = *ptr
++;
252 span
.array
->rgba
[i
][3] = *ptr
++;
256 span
.end
= drawWidth
;
257 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
259 src
+= unpack
.RowLength
*2;
266 if (format
== GL_COLOR_INDEX
&& type
== GL_UNSIGNED_BYTE
) {
267 const GLubyte
*src
= (const GLubyte
*) pixels
268 + unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
;
269 if (ctx
->Visual
.rgbMode
&& rbType
== GL_UNSIGNED_BYTE
) {
270 /* convert ubyte/CI data to ubyte/RGBA */
273 for (row
= 0; row
< drawHeight
; row
++) {
274 ASSERT(drawWidth
<= MAX_WIDTH
);
275 _mesa_map_ci8_to_rgba8(ctx
, drawWidth
, src
,
277 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
278 span
.array
->rgba8
, NULL
);
279 src
+= unpack
.RowLength
;
284 /* ubyte/CI to ubyte/RGBA with zooming */
286 for (row
= 0; row
< drawHeight
; row
++) {
287 ASSERT(drawWidth
<= MAX_WIDTH
);
288 _mesa_map_ci8_to_rgba8(ctx
, drawWidth
, src
,
292 span
.end
= drawWidth
;
293 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
295 src
+= unpack
.RowLength
;
301 else if (!ctx
->Visual
.rgbMode
&& rbType
== GL_UNSIGNED_INT
) {
302 /* write CI data to CI frame buffer */
305 for (row
= 0; row
< drawHeight
; row
++) {
306 GLuint index32
[MAX_WIDTH
];
308 for (col
= 0; col
< drawWidth
; col
++)
309 index32
[col
] = src
[col
];
310 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
, index32
, NULL
);
311 src
+= unpack
.RowLength
;
319 /* can't handle this pixel format and/or data type */
326 * Draw color index image.
329 draw_index_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
330 GLsizei width
, GLsizei height
,
332 const struct gl_pixelstore_attrib
*unpack
,
333 const GLvoid
*pixels
)
335 const GLint imgX
= x
, imgY
= y
;
336 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
337 GLint row
, skipPixels
;
340 INIT_SPAN(span
, GL_BITMAP
);
341 span
.arrayMask
= SPAN_INDEX
;
342 _swrast_span_default_attribs(ctx
, &span
);
348 while (skipPixels
< width
) {
349 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
350 ASSERT(spanWidth
<= MAX_WIDTH
);
351 for (row
= 0; row
< height
; row
++) {
352 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
354 GL_COLOR_INDEX
, type
,
356 _mesa_unpack_index_span(ctx
, spanWidth
, GL_UNSIGNED_INT
,
357 span
.array
->index
, type
, source
, unpack
,
358 ctx
->_ImageTransferState
);
360 /* These may get changed during writing/clipping */
361 span
.x
= x
+ skipPixels
;
363 span
.end
= spanWidth
;
366 _swrast_write_zoomed_index_span(ctx
, imgX
, imgY
, &span
);
368 _swrast_write_index_span(ctx
, &span
);
370 skipPixels
+= spanWidth
;
377 * Draw stencil image.
380 draw_stencil_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
381 GLsizei width
, GLsizei height
,
383 const struct gl_pixelstore_attrib
*unpack
,
384 const GLvoid
*pixels
)
386 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
389 /* if width > MAX_WIDTH, have to process image in chunks */
391 while (skipPixels
< width
) {
392 const GLint spanX
= x
+ skipPixels
;
393 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
395 for (row
= 0; row
< height
; row
++) {
396 const GLint spanY
= y
+ row
;
397 GLstencil values
[MAX_WIDTH
];
398 GLenum destType
= (sizeof(GLstencil
) == sizeof(GLubyte
))
399 ? GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
400 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
402 GL_COLOR_INDEX
, type
,
404 _mesa_unpack_stencil_span(ctx
, spanWidth
, destType
, values
,
405 type
, source
, unpack
,
406 ctx
->_ImageTransferState
);
408 _swrast_write_zoomed_stencil_span(ctx
, x
, y
, spanWidth
,
409 spanX
, spanY
, values
);
412 _swrast_write_stencil_span(ctx
, spanWidth
, spanX
, spanY
, values
);
415 skipPixels
+= spanWidth
;
424 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
425 GLsizei width
, GLsizei height
,
427 const struct gl_pixelstore_attrib
*unpack
,
428 const GLvoid
*pixels
)
430 const GLboolean scaleOrBias
431 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
432 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
435 INIT_SPAN(span
, GL_BITMAP
);
436 span
.arrayMask
= SPAN_Z
;
437 _swrast_span_default_attribs(ctx
, &span
);
439 if (type
== GL_UNSIGNED_SHORT
440 && ctx
->DrawBuffer
->Visual
.depthBits
== 16
443 && ctx
->Visual
.rgbMode
444 && width
<= MAX_WIDTH
445 && !unpack
->SwapBytes
) {
446 /* Special case: directly write 16-bit depth values */
448 for (row
= 0; row
< height
; row
++) {
449 const GLushort
*zSrc
= (const GLushort
*)
450 _mesa_image_address2d(unpack
, pixels
, width
, height
,
451 GL_DEPTH_COMPONENT
, type
, row
, 0);
453 for (i
= 0; i
< width
; i
++)
454 span
.array
->z
[i
] = zSrc
[i
];
458 _swrast_write_rgba_span(ctx
, &span
);
461 else if (type
== GL_UNSIGNED_INT
464 && ctx
->Visual
.rgbMode
465 && width
<= MAX_WIDTH
466 && !unpack
->SwapBytes
) {
467 /* Special case: shift 32-bit values down to Visual.depthBits */
468 const GLint shift
= 32 - ctx
->DrawBuffer
->Visual
.depthBits
;
470 for (row
= 0; row
< height
; row
++) {
471 const GLuint
*zSrc
= (const GLuint
*)
472 _mesa_image_address2d(unpack
, pixels
, width
, height
,
473 GL_DEPTH_COMPONENT
, type
, row
, 0);
475 _mesa_memcpy(span
.array
->z
, zSrc
, width
* sizeof(GLuint
));
479 for (col
= 0; col
< width
; col
++)
480 span
.array
->z
[col
] = zSrc
[col
] >> shift
;
485 _swrast_write_rgba_span(ctx
, &span
);
490 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
491 GLint skipPixels
= 0;
493 /* in case width > MAX_WIDTH do the copy in chunks */
494 while (skipPixels
< width
) {
495 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
497 ASSERT(span
.end
<= MAX_WIDTH
);
498 for (row
= 0; row
< height
; row
++) {
499 const GLvoid
*zSrc
= _mesa_image_address2d(unpack
,
500 pixels
, width
, height
,
501 GL_DEPTH_COMPONENT
, type
,
504 /* Set these for each row since the _swrast_write_* function may
505 * change them while clipping.
507 span
.x
= x
+ skipPixels
;
509 span
.end
= spanWidth
;
511 _mesa_unpack_depth_span(ctx
, spanWidth
,
512 GL_UNSIGNED_INT
, span
.array
->z
, depthMax
,
515 _swrast_write_zoomed_depth_span(ctx
, x
, y
, &span
);
517 else if (ctx
->Visual
.rgbMode
) {
518 _swrast_write_rgba_span(ctx
, &span
);
521 _swrast_write_index_span(ctx
, &span
);
524 skipPixels
+= spanWidth
;
535 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
536 GLsizei width
, GLsizei height
,
537 GLenum format
, GLenum type
,
538 const struct gl_pixelstore_attrib
*unpack
,
539 const GLvoid
*pixels
)
541 const GLint imgX
= x
, imgY
= y
;
542 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
543 GLfloat
*convImage
= NULL
;
544 GLbitfield transferOps
= ctx
->_ImageTransferState
;
547 /* Try an optimized glDrawPixels first */
548 if (fast_draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
,
553 INIT_SPAN(span
, GL_BITMAP
);
554 _swrast_span_default_attribs(ctx
, &span
);
555 span
.arrayMask
= SPAN_RGBA
;
556 span
.arrayAttribs
= FRAG_BIT_COL0
; /* we're fill in COL0 attrib values */
558 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
559 /* Convolution has to be handled specially. We'll create an
560 * intermediate image, applying all pixel transfer operations
561 * up to convolution. Then we'll convolve the image. Then
562 * we'll proceed with the rest of the transfer operations and
563 * rasterize the image.
566 GLfloat
*dest
, *tmpImage
;
568 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
570 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
573 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
575 _mesa_free(tmpImage
);
576 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
580 /* Unpack the image and apply transfer ops up to convolution */
582 for (row
= 0; row
< height
; row
++) {
583 const GLvoid
*source
= _mesa_image_address2d(unpack
,
584 pixels
, width
, height
, format
, type
, row
, 0);
585 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
, (GLfloat
*) dest
,
586 format
, type
, source
, unpack
,
587 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
);
592 if (ctx
->Pixel
.Convolution2DEnabled
) {
593 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
596 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
597 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
599 _mesa_free(tmpImage
);
601 /* continue transfer ops and draw the convolved image */
602 unpack
= &ctx
->DefaultPacking
;
606 transferOps
&= IMAGE_POST_CONVOLUTION_BITS
;
608 else if (ctx
->Pixel
.Convolution1DEnabled
) {
609 /* we only want to apply 1D convolution to glTexImage1D */
610 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
611 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
614 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
> 0 &&
615 ctx
->DrawBuffer
->_ColorDrawBuffers
[0]->DataType
!= GL_FLOAT
&&
616 ctx
->Color
.ClampFragmentColor
!= GL_FALSE
) {
617 /* need to clamp colors before applying fragment ops */
618 transferOps
|= IMAGE_CLAMP_BIT
;
625 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
626 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
627 const GLbitfield interpMask
= span
.interpMask
;
628 const GLbitfield arrayMask
= span
.arrayMask
;
629 const GLint srcStride
630 = _mesa_image_row_stride(unpack
, width
, format
, type
);
631 GLint skipPixels
= 0;
632 /* use span array for temp color storage */
633 GLfloat
*rgba
= (GLfloat
*) span
.array
->attribs
[FRAG_ATTRIB_COL0
];
635 /* if the span is wider than MAX_WIDTH we have to do it in chunks */
636 while (skipPixels
< width
) {
637 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
638 const GLubyte
*source
639 = (const GLubyte
*) _mesa_image_address2d(unpack
, pixels
,
640 width
, height
, format
,
641 type
, 0, skipPixels
);
644 for (row
= 0; row
< height
; row
++) {
645 /* get image row as float/RGBA */
646 _mesa_unpack_color_span_float(ctx
, spanWidth
, GL_RGBA
, rgba
,
647 format
, type
, source
, unpack
,
651 /* Set these for each row since the _swrast_write_* functions
652 * may change them while clipping/rendering.
654 span
.array
->ChanType
= GL_FLOAT
;
655 span
.x
= x
+ skipPixels
;
657 span
.end
= spanWidth
;
658 span
.arrayMask
= arrayMask
;
659 span
.interpMask
= interpMask
;
661 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, rgba
);
664 _swrast_write_rgba_span(ctx
, &span
);
671 skipPixels
+= spanWidth
;
672 } /* while skipPixels < width */
674 /* XXX this is ugly/temporary, to undo above change */
675 span
.array
->ChanType
= CHAN_TYPE
;
679 _mesa_free(convImage
);
685 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
686 * The only per-pixel operations that apply are depth scale/bias,
687 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
689 * Also, only the depth buffer and stencil buffers are touched, not the
693 draw_depth_stencil_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
694 GLsizei width
, GLsizei height
, GLenum type
,
695 const struct gl_pixelstore_attrib
*unpack
,
696 const GLvoid
*pixels
)
698 const GLint imgX
= x
, imgY
= y
;
699 const GLboolean scaleOrBias
700 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
701 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
702 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
703 const GLuint stencilType
= (STENCIL_BITS
== 8) ?
704 GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
705 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
706 struct gl_renderbuffer
*depthRb
, *stencilRb
;
707 struct gl_pixelstore_attrib clippedUnpack
= *unpack
;
710 if (!_mesa_clip_drawpixels(ctx
, &x
, &y
, &width
, &height
,
712 /* totally clipped */
717 depthRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
718 stencilRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
722 if (depthRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
723 stencilRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
724 depthRb
== stencilRb
&&
728 (stencilMask
& 0xff) == 0xff) {
729 /* This is the ideal case.
730 * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
731 * Plus, no pixel transfer ops, zooming, or masking needed.
734 for (i
= 0; i
< height
; i
++) {
735 const GLuint
*src
= (const GLuint
*)
736 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
737 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
738 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, src
, NULL
);
742 /* sub-optimal cases:
743 * Separate depth/stencil buffers, or pixel transfer ops required.
745 /* XXX need to handle very wide images (skippixels) */
748 depthRb
= ctx
->DrawBuffer
->_DepthBuffer
;
749 stencilRb
= ctx
->DrawBuffer
->_StencilBuffer
;
751 for (i
= 0; i
< height
; i
++) {
752 const GLuint
*depthStencilSrc
= (const GLuint
*)
753 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
754 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
756 if (ctx
->Depth
.Mask
) {
757 if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 24) {
758 /* fast path 24-bit zbuffer */
759 GLuint zValues
[MAX_WIDTH
];
761 ASSERT(depthRb
->DataType
== GL_UNSIGNED_INT
);
762 for (j
= 0; j
< width
; j
++) {
763 zValues
[j
] = depthStencilSrc
[j
] >> 8;
766 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
769 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
771 else if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 16) {
772 /* fast path 16-bit zbuffer */
773 GLushort zValues
[MAX_WIDTH
];
775 ASSERT(depthRb
->DataType
== GL_UNSIGNED_SHORT
);
776 for (j
= 0; j
< width
; j
++) {
777 zValues
[j
] = depthStencilSrc
[j
] >> 16;
780 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
783 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
787 GLuint zValues
[MAX_WIDTH
]; /* 16 or 32-bit Z value storage */
788 _mesa_unpack_depth_span(ctx
, width
,
789 depthRb
->DataType
, zValues
, depthMax
,
790 type
, depthStencilSrc
, &clippedUnpack
);
792 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
, x
,
796 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
801 if (stencilMask
!= 0x0) {
802 GLstencil stencilValues
[MAX_WIDTH
];
803 /* get stencil values, with shift/offset/mapping */
804 _mesa_unpack_stencil_span(ctx
, width
, stencilType
, stencilValues
,
805 type
, depthStencilSrc
, &clippedUnpack
,
806 ctx
->_ImageTransferState
);
808 _swrast_write_zoomed_stencil_span(ctx
, imgX
, imgY
, width
,
809 x
, y
+ i
, stencilValues
);
811 _swrast_write_stencil_span(ctx
, width
, x
, y
+ i
, stencilValues
);
819 * Execute software-based glDrawPixels.
820 * By time we get here, all error checking will have been done.
823 _swrast_DrawPixels( GLcontext
*ctx
,
825 GLsizei width
, GLsizei height
,
826 GLenum format
, GLenum type
,
827 const struct gl_pixelstore_attrib
*unpack
,
828 const GLvoid
*pixels
)
830 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
831 GLboolean save_vp_override
= ctx
->VertexProgram
._Overriden
;
833 /* We are creating fragments directly, without going through vertex
836 * This override flag tells the fragment processing code that its input
837 * comes from a non-standard source, and it may therefore not rely on
838 * optimizations that assume e.g. constant color if there is no color
841 _mesa_set_vp_override(ctx
, GL_TRUE
);
843 swrast_render_start(ctx
);
846 _mesa_update_state(ctx
);
848 if (swrast
->NewState
)
849 _swrast_validate_derived( ctx
);
851 pixels
= _mesa_map_pbo_source(ctx
, unpack
, pixels
);
853 swrast_render_finish(ctx
);
854 _mesa_set_vp_override(ctx
, save_vp_override
);
859 case GL_STENCIL_INDEX
:
860 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
862 case GL_DEPTH_COMPONENT
:
863 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
866 if (ctx
->Visual
.rgbMode
)
867 draw_rgba_pixels(ctx
, x
,y
, width
, height
, format
, type
, unpack
, pixels
);
869 draw_index_pixels(ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
876 case GL_LUMINANCE_ALPHA
:
882 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
884 case GL_DEPTH_STENCIL_EXT
:
885 draw_depth_stencil_pixels(ctx
, x
, y
, width
, height
,
886 type
, unpack
, pixels
);
889 _mesa_problem(ctx
, "unexpected format in _swrast_DrawPixels");
890 /* don't return yet, clean-up */
893 swrast_render_finish(ctx
);
894 _mesa_set_vp_override(ctx
, save_vp_override
);
896 _mesa_unmap_pbo_source(ctx
, unpack
);