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.
27 #include "bufferobj.h"
36 #include "s_context.h"
37 #include "s_drawpix.h"
39 #include "s_stencil.h"
45 * Try to do a fast and simple RGB(a) glDrawPixels.
46 * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
49 fast_draw_rgba_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
50 GLsizei width
, GLsizei height
,
51 GLenum format
, GLenum type
,
52 const struct gl_pixelstore_attrib
*userUnpack
,
55 const GLint imgX
= x
, imgY
= y
;
56 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[0][0];
57 const GLenum rbType
= rb
->DataType
;
58 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
61 GLint yStep
; /* +1 or -1 */
62 struct gl_pixelstore_attrib unpack
;
63 GLint destX
, destY
, drawWidth
, drawHeight
; /* post clipping */
65 if ((swrast
->_RasterMask
& ~CLIP_BIT
) ||
66 ctx
->Texture
._EnabledCoordUnits
||
67 userUnpack
->SwapBytes
||
68 ctx
->_ImageTransferState
) {
69 /* can't handle any of those conditions */
73 INIT_SPAN(span
, GL_BITMAP
);
74 span
.arrayMask
= SPAN_RGBA
;
75 span
.arrayAttribs
= FRAG_BIT_COL0
;
76 _swrast_span_default_attribs(ctx
, &span
);
78 /* copy input params since clipping may change them */
85 /* check for simple zooming and clipping */
86 if (ctx
->Pixel
.ZoomX
== 1.0F
&&
87 (ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
)) {
88 if (!_mesa_clip_drawpixels(ctx
, &destX
, &destY
,
89 &drawWidth
, &drawHeight
, &unpack
)) {
90 /* image was completely clipped: no-op, all done */
94 yStep
= (GLint
) ctx
->Pixel
.ZoomY
;
95 ASSERT(yStep
== 1 || yStep
== -1);
98 /* non-simple zooming */
99 simpleZoom
= GL_FALSE
;
101 if (unpack
.RowLength
== 0)
102 unpack
.RowLength
= width
;
109 if (format
== GL_RGBA
&& type
== rbType
) {
111 = (const GLubyte
*) _mesa_image_address2d(&unpack
, pixels
, width
,
112 height
, format
, type
, 0, 0);
113 const GLint srcStride
= _mesa_image_row_stride(&unpack
, width
,
117 for (row
= 0; row
< drawHeight
; row
++) {
118 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
, src
, NULL
);
126 for (row
= 0; row
< drawHeight
; row
++) {
128 span
.y
= destY
+ row
;
129 span
.end
= drawWidth
;
130 span
.array
->ChanType
= rbType
;
131 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, src
);
134 span
.array
->ChanType
= CHAN_TYPE
;
139 if (format
== GL_RGB
&& type
== rbType
) {
141 = (const GLubyte
*) _mesa_image_address2d(&unpack
, pixels
, width
,
142 height
, format
, type
, 0, 0);
143 const GLint srcStride
= _mesa_image_row_stride(&unpack
, width
,
147 for (row
= 0; row
< drawHeight
; row
++) {
148 rb
->PutRowRGB(ctx
, rb
, drawWidth
, destX
, destY
, src
, NULL
);
156 for (row
= 0; row
< drawHeight
; row
++) {
159 span
.end
= drawWidth
;
160 span
.array
->ChanType
= rbType
;
161 _swrast_write_zoomed_rgb_span(ctx
, imgX
, imgY
, &span
, src
);
165 span
.array
->ChanType
= CHAN_TYPE
;
170 /* Remaining cases haven't been tested with alignment != 1 */
171 if (userUnpack
->Alignment
!= 1)
174 if (format
== GL_LUMINANCE
&& type
== CHAN_TYPE
&& rbType
== CHAN_TYPE
) {
175 const GLchan
*src
= (const GLchan
*) pixels
176 + (unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
);
180 ASSERT(drawWidth
<= MAX_WIDTH
);
181 for (row
= 0; row
< drawHeight
; row
++) {
182 GLchan rgb
[MAX_WIDTH
][3];
184 for (i
= 0;i
<drawWidth
;i
++) {
189 rb
->PutRowRGB(ctx
, rb
, drawWidth
, destX
, destY
, rgb
, NULL
);
190 src
+= unpack
.RowLength
;
197 ASSERT(drawWidth
<= MAX_WIDTH
);
198 for (row
= 0; row
< drawHeight
; row
++) {
199 GLchan rgb
[MAX_WIDTH
][3];
201 for (i
= 0;i
<drawWidth
;i
++) {
208 span
.end
= drawWidth
;
209 _swrast_write_zoomed_rgb_span(ctx
, imgX
, imgY
, &span
, rgb
);
210 src
+= unpack
.RowLength
;
217 if (format
== GL_LUMINANCE_ALPHA
&& type
== CHAN_TYPE
&& rbType
== CHAN_TYPE
) {
218 const GLchan
*src
= (const GLchan
*) pixels
219 + (unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
)*2;
222 ASSERT(drawWidth
<= MAX_WIDTH
);
223 for (row
= 0; row
< drawHeight
; row
++) {
225 const GLchan
*ptr
= src
;
226 for (i
= 0;i
<drawWidth
;i
++) {
227 span
.array
->rgba
[i
][0] = *ptr
;
228 span
.array
->rgba
[i
][1] = *ptr
;
229 span
.array
->rgba
[i
][2] = *ptr
++;
230 span
.array
->rgba
[i
][3] = *ptr
++;
232 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
233 span
.array
->rgba
, NULL
);
234 src
+= unpack
.RowLength
*2;
241 ASSERT(drawWidth
<= MAX_WIDTH
);
242 for (row
= 0; row
< drawHeight
; row
++) {
243 const GLchan
*ptr
= src
;
245 for (i
= 0;i
<drawWidth
;i
++) {
246 span
.array
->rgba
[i
][0] = *ptr
;
247 span
.array
->rgba
[i
][1] = *ptr
;
248 span
.array
->rgba
[i
][2] = *ptr
++;
249 span
.array
->rgba
[i
][3] = *ptr
++;
253 span
.end
= drawWidth
;
254 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
256 src
+= unpack
.RowLength
*2;
263 if (format
== GL_COLOR_INDEX
&& type
== GL_UNSIGNED_BYTE
) {
264 const GLubyte
*src
= (const GLubyte
*) pixels
265 + unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
;
266 if (ctx
->Visual
.rgbMode
&& rbType
== GL_UNSIGNED_BYTE
) {
267 /* convert ubyte/CI data to ubyte/RGBA */
270 for (row
= 0; row
< drawHeight
; row
++) {
271 ASSERT(drawWidth
<= MAX_WIDTH
);
272 _mesa_map_ci8_to_rgba8(ctx
, drawWidth
, src
,
274 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
275 span
.array
->rgba8
, NULL
);
276 src
+= unpack
.RowLength
;
281 /* ubyte/CI to ubyte/RGBA with zooming */
283 for (row
= 0; row
< drawHeight
; row
++) {
284 ASSERT(drawWidth
<= MAX_WIDTH
);
285 _mesa_map_ci8_to_rgba8(ctx
, drawWidth
, src
,
289 span
.end
= drawWidth
;
290 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
292 src
+= unpack
.RowLength
;
298 else if (!ctx
->Visual
.rgbMode
&& rbType
== GL_UNSIGNED_INT
) {
299 /* write CI data to CI frame buffer */
302 for (row
= 0; row
< drawHeight
; row
++) {
303 GLuint index32
[MAX_WIDTH
];
305 for (col
= 0; col
< drawWidth
; col
++)
306 index32
[col
] = src
[col
];
307 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
, index32
, NULL
);
308 src
+= unpack
.RowLength
;
316 /* can't handle this pixel format and/or data type */
323 * Draw color index image.
326 draw_index_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
327 GLsizei width
, GLsizei height
,
329 const struct gl_pixelstore_attrib
*unpack
,
330 const GLvoid
*pixels
)
332 const GLint imgX
= x
, imgY
= y
;
333 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
334 GLint row
, skipPixels
;
337 INIT_SPAN(span
, GL_BITMAP
);
338 span
.arrayMask
= SPAN_INDEX
;
339 _swrast_span_default_attribs(ctx
, &span
);
345 while (skipPixels
< width
) {
346 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
347 ASSERT(spanWidth
<= MAX_WIDTH
);
348 for (row
= 0; row
< height
; row
++) {
349 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
351 GL_COLOR_INDEX
, type
,
353 _mesa_unpack_index_span(ctx
, spanWidth
, GL_UNSIGNED_INT
,
354 span
.array
->index
, type
, source
, unpack
,
355 ctx
->_ImageTransferState
);
357 /* These may get changed during writing/clipping */
358 span
.x
= x
+ skipPixels
;
360 span
.end
= spanWidth
;
363 _swrast_write_zoomed_index_span(ctx
, imgX
, imgY
, &span
);
365 _swrast_write_index_span(ctx
, &span
);
367 skipPixels
+= spanWidth
;
374 * Draw stencil image.
377 draw_stencil_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
378 GLsizei width
, GLsizei height
,
380 const struct gl_pixelstore_attrib
*unpack
,
381 const GLvoid
*pixels
)
383 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
386 /* if width > MAX_WIDTH, have to process image in chunks */
388 while (skipPixels
< width
) {
389 const GLint spanX
= x
+ skipPixels
;
390 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
392 for (row
= 0; row
< height
; row
++) {
393 const GLint spanY
= y
+ row
;
394 GLstencil values
[MAX_WIDTH
];
395 GLenum destType
= (sizeof(GLstencil
) == sizeof(GLubyte
))
396 ? GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
397 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
399 GL_COLOR_INDEX
, type
,
401 _mesa_unpack_stencil_span(ctx
, spanWidth
, destType
, values
,
402 type
, source
, unpack
,
403 ctx
->_ImageTransferState
);
405 _swrast_write_zoomed_stencil_span(ctx
, x
, y
, spanWidth
,
406 spanX
, spanY
, values
);
409 _swrast_write_stencil_span(ctx
, spanWidth
, spanX
, spanY
, values
);
412 skipPixels
+= spanWidth
;
421 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
422 GLsizei width
, GLsizei height
,
424 const struct gl_pixelstore_attrib
*unpack
,
425 const GLvoid
*pixels
)
427 const GLboolean scaleOrBias
428 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
429 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
432 INIT_SPAN(span
, GL_BITMAP
);
433 span
.arrayMask
= SPAN_Z
;
434 _swrast_span_default_attribs(ctx
, &span
);
436 if (type
== GL_UNSIGNED_SHORT
437 && ctx
->DrawBuffer
->Visual
.depthBits
== 16
440 && ctx
->Visual
.rgbMode
441 && width
<= MAX_WIDTH
442 && !unpack
->SwapBytes
) {
443 /* Special case: directly write 16-bit depth values */
445 for (row
= 0; row
< height
; row
++) {
446 const GLushort
*zSrc
= (const GLushort
*)
447 _mesa_image_address2d(unpack
, pixels
, width
, height
,
448 GL_DEPTH_COMPONENT
, type
, row
, 0);
450 for (i
= 0; i
< width
; i
++)
451 span
.array
->z
[i
] = zSrc
[i
];
455 _swrast_write_rgba_span(ctx
, &span
);
458 else if (type
== GL_UNSIGNED_INT
461 && ctx
->Visual
.rgbMode
462 && width
<= MAX_WIDTH
463 && !unpack
->SwapBytes
) {
464 /* Special case: shift 32-bit values down to Visual.depthBits */
465 const GLint shift
= 32 - ctx
->DrawBuffer
->Visual
.depthBits
;
467 for (row
= 0; row
< height
; row
++) {
468 const GLuint
*zSrc
= (const GLuint
*)
469 _mesa_image_address2d(unpack
, pixels
, width
, height
,
470 GL_DEPTH_COMPONENT
, type
, row
, 0);
472 _mesa_memcpy(span
.array
->z
, zSrc
, width
* sizeof(GLuint
));
476 for (col
= 0; col
< width
; col
++)
477 span
.array
->z
[col
] = zSrc
[col
] >> shift
;
482 _swrast_write_rgba_span(ctx
, &span
);
487 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
488 GLint skipPixels
= 0;
490 /* in case width > MAX_WIDTH do the copy in chunks */
491 while (skipPixels
< width
) {
492 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
494 ASSERT(span
.end
<= MAX_WIDTH
);
495 for (row
= 0; row
< height
; row
++) {
496 const GLvoid
*zSrc
= _mesa_image_address2d(unpack
,
497 pixels
, width
, height
,
498 GL_DEPTH_COMPONENT
, type
,
501 /* Set these for each row since the _swrast_write_* function may
502 * change them while clipping.
504 span
.x
= x
+ skipPixels
;
506 span
.end
= spanWidth
;
508 _mesa_unpack_depth_span(ctx
, spanWidth
,
509 GL_UNSIGNED_INT
, span
.array
->z
, depthMax
,
512 _swrast_write_zoomed_depth_span(ctx
, x
, y
, &span
);
514 else if (ctx
->Visual
.rgbMode
) {
515 _swrast_write_rgba_span(ctx
, &span
);
518 _swrast_write_index_span(ctx
, &span
);
521 skipPixels
+= spanWidth
;
532 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
533 GLsizei width
, GLsizei height
,
534 GLenum format
, GLenum type
,
535 const struct gl_pixelstore_attrib
*unpack
,
536 const GLvoid
*pixels
)
538 const GLint imgX
= x
, imgY
= y
;
539 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
540 GLfloat
*convImage
= NULL
;
541 GLbitfield transferOps
= ctx
->_ImageTransferState
;
544 /* Try an optimized glDrawPixels first */
545 if (fast_draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
,
550 INIT_SPAN(span
, GL_BITMAP
);
551 _swrast_span_default_attribs(ctx
, &span
);
552 span
.arrayMask
= SPAN_RGBA
;
553 span
.arrayAttribs
= FRAG_BIT_COL0
; /* we're fill in COL0 attrib values */
555 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
556 /* Convolution has to be handled specially. We'll create an
557 * intermediate image, applying all pixel transfer operations
558 * up to convolution. Then we'll convolve the image. Then
559 * we'll proceed with the rest of the transfer operations and
560 * rasterize the image.
563 GLfloat
*dest
, *tmpImage
;
565 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
567 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
570 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
572 _mesa_free(tmpImage
);
573 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
577 /* Unpack the image and apply transfer ops up to convolution */
579 for (row
= 0; row
< height
; row
++) {
580 const GLvoid
*source
= _mesa_image_address2d(unpack
,
581 pixels
, width
, height
, format
, type
, row
, 0);
582 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
, (GLfloat
*) dest
,
583 format
, type
, source
, unpack
,
584 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
);
589 if (ctx
->Pixel
.Convolution2DEnabled
) {
590 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
593 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
594 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
596 _mesa_free(tmpImage
);
598 /* continue transfer ops and draw the convolved image */
599 unpack
= &ctx
->DefaultPacking
;
603 transferOps
&= IMAGE_POST_CONVOLUTION_BITS
;
605 else if (ctx
->Pixel
.Convolution1DEnabled
) {
606 /* we only want to apply 1D convolution to glTexImage1D */
607 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
608 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
611 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
[0] > 0 &&
612 ctx
->DrawBuffer
->_ColorDrawBuffers
[0][0]->DataType
!= GL_FLOAT
&&
613 ctx
->Color
.ClampFragmentColor
!= GL_FALSE
) {
614 /* need to clamp colors before applying fragment ops */
615 transferOps
|= IMAGE_CLAMP_BIT
;
622 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
623 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
624 const GLbitfield interpMask
= span
.interpMask
;
625 const GLbitfield arrayMask
= span
.arrayMask
;
626 const GLint srcStride
627 = _mesa_image_row_stride(unpack
, width
, format
, type
);
628 GLint skipPixels
= 0;
629 /* use span array for temp color storage */
630 GLfloat
*rgba
= (GLfloat
*) span
.array
->attribs
[FRAG_ATTRIB_COL0
];
632 /* if the span is wider than MAX_WIDTH we have to do it in chunks */
633 while (skipPixels
< width
) {
634 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
635 const GLubyte
*source
636 = (const GLubyte
*) _mesa_image_address2d(unpack
, pixels
,
637 width
, height
, format
,
638 type
, 0, skipPixels
);
641 for (row
= 0; row
< height
; row
++) {
642 /* get image row as float/RGBA */
643 _mesa_unpack_color_span_float(ctx
, spanWidth
, GL_RGBA
, rgba
,
644 format
, type
, source
, unpack
,
648 /* Set these for each row since the _swrast_write_* functions
649 * may change them while clipping/rendering.
651 span
.array
->ChanType
= GL_FLOAT
;
652 span
.x
= x
+ skipPixels
;
654 span
.end
= spanWidth
;
655 span
.arrayMask
= arrayMask
;
656 span
.interpMask
= interpMask
;
658 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, rgba
);
661 _swrast_write_rgba_span(ctx
, &span
);
668 skipPixels
+= spanWidth
;
669 } /* while skipPixels < width */
671 /* XXX this is ugly/temporary, to undo above change */
672 span
.array
->ChanType
= CHAN_TYPE
;
676 _mesa_free(convImage
);
682 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
683 * The only per-pixel operations that apply are depth scale/bias,
684 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
686 * Also, only the depth buffer and stencil buffers are touched, not the
690 draw_depth_stencil_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
691 GLsizei width
, GLsizei height
, GLenum type
,
692 const struct gl_pixelstore_attrib
*unpack
,
693 const GLvoid
*pixels
)
695 const GLint imgX
= x
, imgY
= y
;
696 const GLboolean scaleOrBias
697 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
698 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
699 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
700 const GLuint stencilType
= (STENCIL_BITS
== 8) ?
701 GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
702 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
703 struct gl_renderbuffer
*depthRb
, *stencilRb
;
704 struct gl_pixelstore_attrib clippedUnpack
= *unpack
;
707 if (!_mesa_clip_drawpixels(ctx
, &x
, &y
, &width
, &height
,
709 /* totally clipped */
714 depthRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
715 stencilRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
719 if (depthRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
720 stencilRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
721 depthRb
== stencilRb
&&
725 (stencilMask
& 0xff) == 0xff) {
726 /* This is the ideal case.
727 * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
728 * Plus, no pixel transfer ops, zooming, or masking needed.
731 for (i
= 0; i
< height
; i
++) {
732 const GLuint
*src
= (const GLuint
*)
733 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
734 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
735 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, src
, NULL
);
739 /* sub-optimal cases:
740 * Separate depth/stencil buffers, or pixel transfer ops required.
742 /* XXX need to handle very wide images (skippixels) */
745 depthRb
= ctx
->DrawBuffer
->_DepthBuffer
;
746 stencilRb
= ctx
->DrawBuffer
->_StencilBuffer
;
748 for (i
= 0; i
< height
; i
++) {
749 const GLuint
*depthStencilSrc
= (const GLuint
*)
750 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
751 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
753 if (ctx
->Depth
.Mask
) {
754 if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 24) {
755 /* fast path 24-bit zbuffer */
756 GLuint zValues
[MAX_WIDTH
];
758 ASSERT(depthRb
->DataType
== GL_UNSIGNED_INT
);
759 for (j
= 0; j
< width
; j
++) {
760 zValues
[j
] = depthStencilSrc
[j
] >> 8;
763 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
766 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
768 else if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 16) {
769 /* fast path 16-bit zbuffer */
770 GLushort zValues
[MAX_WIDTH
];
772 ASSERT(depthRb
->DataType
== GL_UNSIGNED_SHORT
);
773 for (j
= 0; j
< width
; j
++) {
774 zValues
[j
] = depthStencilSrc
[j
] >> 16;
777 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
780 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
784 GLuint zValues
[MAX_WIDTH
]; /* 16 or 32-bit Z value storage */
785 _mesa_unpack_depth_span(ctx
, width
,
786 depthRb
->DataType
, zValues
, depthMax
,
787 type
, depthStencilSrc
, &clippedUnpack
);
789 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
, x
,
793 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
798 if (stencilMask
!= 0x0) {
799 GLstencil stencilValues
[MAX_WIDTH
];
800 /* get stencil values, with shift/offset/mapping */
801 _mesa_unpack_stencil_span(ctx
, width
, stencilType
, stencilValues
,
802 type
, depthStencilSrc
, &clippedUnpack
,
803 ctx
->_ImageTransferState
);
805 _swrast_write_zoomed_stencil_span(ctx
, imgX
, imgY
, width
,
806 x
, y
+ i
, stencilValues
);
808 _swrast_write_stencil_span(ctx
, width
, x
, y
+ i
, stencilValues
);
816 * Execute software-based glDrawPixels.
817 * By time we get here, all error checking will have been done.
820 _swrast_DrawPixels( GLcontext
*ctx
,
822 GLsizei width
, GLsizei height
,
823 GLenum format
, GLenum type
,
824 const struct gl_pixelstore_attrib
*unpack
,
825 const GLvoid
*pixels
)
827 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
829 RENDER_START(swrast
,ctx
);
832 _mesa_update_state(ctx
);
834 if (swrast
->NewState
)
835 _swrast_validate_derived( ctx
);
837 pixels
= _mesa_map_drawpix_pbo(ctx
, unpack
, pixels
);
842 case GL_STENCIL_INDEX
:
843 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
845 case GL_DEPTH_COMPONENT
:
846 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
849 if (ctx
->Visual
.rgbMode
)
850 draw_rgba_pixels(ctx
, x
,y
, width
, height
, format
, type
, unpack
, pixels
);
852 draw_index_pixels(ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
859 case GL_LUMINANCE_ALPHA
:
865 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
867 case GL_DEPTH_STENCIL_EXT
:
868 draw_depth_stencil_pixels(ctx
, x
, y
, width
, height
,
869 type
, unpack
, pixels
);
872 _mesa_problem(ctx
, "unexpected format in _swrast_DrawPixels");
873 /* don't return yet, clean-up */
878 RENDER_FINISH(swrast
,ctx
);
880 _mesa_unmap_drawpix_pbo(ctx
, unpack
);
885 #if 0 /* experimental */
887 * Execute glDrawDepthPixelsMESA().
890 _swrast_DrawDepthPixelsMESA( GLcontext
*ctx
,
892 GLsizei width
, GLsizei height
,
893 GLenum colorFormat
, GLenum colorType
,
894 const GLvoid
*colors
,
895 GLenum depthType
, const GLvoid
*depths
,
896 const struct gl_pixelstore_attrib
*unpack
)
898 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
900 if (swrast
->NewState
)
901 _swrast_validate_derived( ctx
);
903 RENDER_START(swrast
,ctx
);
905 switch (colorFormat
) {
907 if (ctx
->Visual
.rgbMode
)
908 draw_rgba_pixels(ctx
, x
,y
, width
, height
, colorFormat
, colorType
,
911 draw_index_pixels(ctx
, x
, y
, width
, height
, colorType
,
919 case GL_LUMINANCE_ALPHA
:
925 draw_rgba_pixels(ctx
, x
, y
, width
, height
, colorFormat
, colorType
,
929 _mesa_problem(ctx
, "unexpected format in glDrawDepthPixelsMESA");
932 RENDER_FINISH(swrast
,ctx
);