2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 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_index_span(ctx
, spanWidth
, destType
, values
,
402 type
, source
, unpack
,
403 ctx
->_ImageTransferState
);
404 _mesa_apply_stencil_transfer_ops(ctx
, spanWidth
, values
);
406 _swrast_write_zoomed_stencil_span(ctx
, x
, y
, spanWidth
,
407 spanX
, spanY
, values
);
410 _swrast_write_stencil_span(ctx
, spanWidth
, spanX
, spanY
, values
);
413 skipPixels
+= spanWidth
;
422 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
423 GLsizei width
, GLsizei height
,
425 const struct gl_pixelstore_attrib
*unpack
,
426 const GLvoid
*pixels
)
428 const GLboolean scaleOrBias
429 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
430 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
433 INIT_SPAN(span
, GL_BITMAP
);
434 span
.arrayMask
= SPAN_Z
;
435 _swrast_span_default_attribs(ctx
, &span
);
437 if (type
== GL_UNSIGNED_SHORT
438 && ctx
->DrawBuffer
->Visual
.depthBits
== 16
441 && ctx
->Visual
.rgbMode
442 && width
<= MAX_WIDTH
443 && !unpack
->SwapBytes
) {
444 /* Special case: directly write 16-bit depth values */
446 for (row
= 0; row
< height
; row
++) {
447 const GLushort
*zSrc
= (const GLushort
*)
448 _mesa_image_address2d(unpack
, pixels
, width
, height
,
449 GL_DEPTH_COMPONENT
, type
, row
, 0);
451 for (i
= 0; i
< width
; i
++)
452 span
.array
->z
[i
] = zSrc
[i
];
456 _swrast_write_rgba_span(ctx
, &span
);
459 else if (type
== GL_UNSIGNED_INT
462 && ctx
->Visual
.rgbMode
463 && width
<= MAX_WIDTH
464 && !unpack
->SwapBytes
) {
465 /* Special case: shift 32-bit values down to Visual.depthBits */
466 const GLint shift
= 32 - ctx
->DrawBuffer
->Visual
.depthBits
;
468 for (row
= 0; row
< height
; row
++) {
469 const GLuint
*zSrc
= (const GLuint
*)
470 _mesa_image_address2d(unpack
, pixels
, width
, height
,
471 GL_DEPTH_COMPONENT
, type
, row
, 0);
473 _mesa_memcpy(span
.array
->z
, zSrc
, width
* sizeof(GLuint
));
477 for (col
= 0; col
< width
; col
++)
478 span
.array
->z
[col
] = zSrc
[col
] >> shift
;
483 _swrast_write_rgba_span(ctx
, &span
);
488 const GLfloat depthMax
= ctx
->DrawBuffer
->_DepthMaxF
;
489 GLint skipPixels
= 0;
491 /* in case width > MAX_WIDTH do the copy in chunks */
492 while (skipPixels
< width
) {
493 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
495 ASSERT(span
.end
<= MAX_WIDTH
);
496 for (row
= 0; row
< height
; row
++) {
497 const GLvoid
*zSrc
= _mesa_image_address2d(unpack
,
498 pixels
, width
, height
,
499 GL_DEPTH_COMPONENT
, type
,
502 /* Set these for each row since the _swrast_write_* function may
503 * change them while clipping.
505 span
.x
= x
+ skipPixels
;
507 span
.end
= spanWidth
;
509 _mesa_unpack_depth_span(ctx
, spanWidth
,
510 GL_UNSIGNED_INT
, span
.array
->z
, depthMax
,
513 _swrast_write_zoomed_depth_span(ctx
, x
, y
, &span
);
515 else if (ctx
->Visual
.rgbMode
) {
516 _swrast_write_rgba_span(ctx
, &span
);
519 _swrast_write_index_span(ctx
, &span
);
522 skipPixels
+= spanWidth
;
533 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
534 GLsizei width
, GLsizei height
,
535 GLenum format
, GLenum type
,
536 const struct gl_pixelstore_attrib
*unpack
,
537 const GLvoid
*pixels
)
539 const GLint imgX
= x
, imgY
= y
;
540 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
541 GLfloat
*convImage
= NULL
;
542 GLbitfield transferOps
= ctx
->_ImageTransferState
;
545 /* Try an optimized glDrawPixels first */
546 if (fast_draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
,
551 INIT_SPAN(span
, GL_BITMAP
);
552 _swrast_span_default_attribs(ctx
, &span
);
553 span
.arrayMask
= SPAN_RGBA
;
554 span
.arrayAttribs
= FRAG_BIT_COL0
; /* we're fill in COL0 attrib values */
556 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
557 /* Convolution has to be handled specially. We'll create an
558 * intermediate image, applying all pixel transfer operations
559 * up to convolution. Then we'll convolve the image. Then
560 * we'll proceed with the rest of the transfer operations and
561 * rasterize the image.
564 GLfloat
*dest
, *tmpImage
;
566 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
568 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
571 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
573 _mesa_free(tmpImage
);
574 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
578 /* Unpack the image and apply transfer ops up to convolution */
580 for (row
= 0; row
< height
; row
++) {
581 const GLvoid
*source
= _mesa_image_address2d(unpack
,
582 pixels
, width
, height
, format
, type
, row
, 0);
583 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
, (GLfloat
*) dest
,
584 format
, type
, source
, unpack
,
585 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
);
590 if (ctx
->Pixel
.Convolution2DEnabled
) {
591 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
594 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
595 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
597 _mesa_free(tmpImage
);
599 /* continue transfer ops and draw the convolved image */
600 unpack
= &ctx
->DefaultPacking
;
604 transferOps
&= IMAGE_POST_CONVOLUTION_BITS
;
606 else if (ctx
->Pixel
.Convolution1DEnabled
) {
607 /* we only want to apply 1D convolution to glTexImage1D */
608 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
609 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
612 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
[0] > 0 &&
613 ctx
->DrawBuffer
->_ColorDrawBuffers
[0][0]->DataType
!= GL_FLOAT
&&
614 ctx
->Color
.ClampFragmentColor
!= GL_FALSE
) {
615 /* need to clamp colors before applying fragment ops */
616 transferOps
|= IMAGE_CLAMP_BIT
;
623 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
624 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
625 const GLbitfield interpMask
= span
.interpMask
;
626 const GLbitfield arrayMask
= span
.arrayMask
;
627 const GLint srcStride
628 = _mesa_image_row_stride(unpack
, width
, format
, type
);
629 GLint skipPixels
= 0;
630 /* use span array for temp color storage */
631 GLfloat
*rgba
= (GLfloat
*) span
.array
->attribs
[FRAG_ATTRIB_COL0
];
633 /* if the span is wider than MAX_WIDTH we have to do it in chunks */
634 while (skipPixels
< width
) {
635 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
636 const GLubyte
*source
637 = (const GLubyte
*) _mesa_image_address2d(unpack
, pixels
,
638 width
, height
, format
,
639 type
, 0, skipPixels
);
642 for (row
= 0; row
< height
; row
++) {
643 /* get image row as float/RGBA */
644 _mesa_unpack_color_span_float(ctx
, spanWidth
, GL_RGBA
, rgba
,
645 format
, type
, source
, unpack
,
649 /* Set these for each row since the _swrast_write_* functions
650 * may change them while clipping/rendering.
652 span
.array
->ChanType
= GL_FLOAT
;
653 span
.x
= x
+ skipPixels
;
655 span
.end
= spanWidth
;
656 span
.arrayMask
= arrayMask
;
657 span
.interpMask
= interpMask
;
659 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, rgba
);
662 _swrast_write_rgba_span(ctx
, &span
);
669 skipPixels
+= spanWidth
;
670 } /* while skipPixels < width */
672 /* XXX this is ugly/temporary, to undo above change */
673 span
.array
->ChanType
= CHAN_TYPE
;
677 _mesa_free(convImage
);
683 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
684 * The only per-pixel operations that apply are depth scale/bias,
685 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
687 * Also, only the depth buffer and stencil buffers are touched, not the
691 draw_depth_stencil_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
692 GLsizei width
, GLsizei height
, GLenum type
,
693 const struct gl_pixelstore_attrib
*unpack
,
694 const GLvoid
*pixels
)
696 const GLint imgX
= x
, imgY
= y
;
697 const GLboolean scaleOrBias
698 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
699 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
700 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
701 const GLuint stencilType
= (STENCIL_BITS
== 8) ?
702 GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
703 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
704 struct gl_renderbuffer
*depthRb
, *stencilRb
;
705 struct gl_pixelstore_attrib clippedUnpack
= *unpack
;
708 if (!_mesa_clip_drawpixels(ctx
, &x
, &y
, &width
, &height
,
710 /* totally clipped */
715 depthRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
716 stencilRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
720 if (depthRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
721 stencilRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
722 depthRb
== stencilRb
&&
726 (stencilMask
& 0xff) == 0xff) {
727 /* This is the ideal case.
728 * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
729 * Plus, no pixel transfer ops, zooming, or masking needed.
732 for (i
= 0; i
< height
; i
++) {
733 const GLuint
*src
= (const GLuint
*)
734 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
735 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
736 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, src
, NULL
);
740 /* sub-optimal cases:
741 * Separate depth/stencil buffers, or pixel transfer ops required.
743 /* XXX need to handle very wide images (skippixels) */
746 depthRb
= ctx
->DrawBuffer
->_DepthBuffer
;
747 stencilRb
= ctx
->DrawBuffer
->_StencilBuffer
;
749 for (i
= 0; i
< height
; i
++) {
750 const GLuint
*depthStencilSrc
= (const GLuint
*)
751 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
752 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
754 if (ctx
->Depth
.Mask
) {
755 if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 24) {
756 /* fast path 24-bit zbuffer */
757 GLuint zValues
[MAX_WIDTH
];
759 ASSERT(depthRb
->DataType
== GL_UNSIGNED_INT
);
760 for (j
= 0; j
< width
; j
++) {
761 zValues
[j
] = depthStencilSrc
[j
] >> 8;
764 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
767 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
769 else if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 16) {
770 /* fast path 16-bit zbuffer */
771 GLushort zValues
[MAX_WIDTH
];
773 ASSERT(depthRb
->DataType
== GL_UNSIGNED_SHORT
);
774 for (j
= 0; j
< width
; j
++) {
775 zValues
[j
] = depthStencilSrc
[j
] >> 16;
778 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
781 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
785 GLuint zValues
[MAX_WIDTH
]; /* 16 or 32-bit Z value storage */
786 _mesa_unpack_depth_span(ctx
, width
,
787 depthRb
->DataType
, zValues
, depthScale
,
788 type
, depthStencilSrc
, &clippedUnpack
);
790 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
, x
,
794 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
799 if (stencilMask
!= 0x0) {
800 GLstencil stencilValues
[MAX_WIDTH
];
801 /* get stencil values, with shift/offset/mapping */
802 _mesa_unpack_stencil_span(ctx
, width
, stencilType
, stencilValues
,
803 type
, depthStencilSrc
, &clippedUnpack
,
804 ctx
->_ImageTransferState
);
806 _swrast_write_zoomed_stencil_span(ctx
, imgX
, imgY
, width
,
807 x
, y
+ i
, stencilValues
);
809 _swrast_write_stencil_span(ctx
, width
, x
, y
+ i
, stencilValues
);
818 * Execute software-based glDrawPixels.
819 * By time we get here, all error checking will have been done.
822 _swrast_DrawPixels( GLcontext
*ctx
,
824 GLsizei width
, GLsizei height
,
825 GLenum format
, GLenum type
,
826 const struct gl_pixelstore_attrib
*unpack
,
827 const GLvoid
*pixels
)
829 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
831 RENDER_START(swrast
,ctx
);
834 _mesa_update_state(ctx
);
836 if (swrast
->NewState
)
837 _swrast_validate_derived( ctx
);
839 if (unpack
->BufferObj
->Name
) {
840 /* unpack from PBO */
842 if (!_mesa_validate_pbo_access(2, unpack
, width
, height
, 1,
843 format
, type
, pixels
)) {
844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
845 "glDrawPixels(invalid PBO access)");
848 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
852 /* buffer is already mapped - that's an error */
853 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glDrawPixels(PBO is mapped)");
856 pixels
= ADD_POINTERS(buf
, pixels
);
860 case GL_STENCIL_INDEX
:
861 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
863 case GL_DEPTH_COMPONENT
:
864 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
867 if (ctx
->Visual
.rgbMode
)
868 draw_rgba_pixels(ctx
, x
,y
, width
, height
, format
, type
, unpack
, pixels
);
870 draw_index_pixels(ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
877 case GL_LUMINANCE_ALPHA
:
883 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
885 case GL_DEPTH_STENCIL_EXT
:
886 draw_depth_stencil_pixels(ctx
, x
, y
, width
, height
,
887 type
, unpack
, pixels
);
890 _mesa_problem(ctx
, "unexpected format in _swrast_DrawPixels");
891 /* don't return yet, clean-up */
896 RENDER_FINISH(swrast
,ctx
);
898 if (unpack
->BufferObj
->Name
) {
899 /* done with PBO so unmap it now */
900 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
907 #if 0 /* experimental */
909 * Execute glDrawDepthPixelsMESA().
912 _swrast_DrawDepthPixelsMESA( GLcontext
*ctx
,
914 GLsizei width
, GLsizei height
,
915 GLenum colorFormat
, GLenum colorType
,
916 const GLvoid
*colors
,
917 GLenum depthType
, const GLvoid
*depths
,
918 const struct gl_pixelstore_attrib
*unpack
)
920 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
922 if (swrast
->NewState
)
923 _swrast_validate_derived( ctx
);
925 RENDER_START(swrast
,ctx
);
927 switch (colorFormat
) {
929 if (ctx
->Visual
.rgbMode
)
930 draw_rgba_pixels(ctx
, x
,y
, width
, height
, colorFormat
, colorType
,
933 draw_index_pixels(ctx
, x
, y
, width
, height
, colorType
,
941 case GL_LUMINANCE_ALPHA
:
947 draw_rgba_pixels(ctx
, x
, y
, width
, height
, colorFormat
, colorType
,
951 _mesa_problem(ctx
, "unexpected format in glDrawDepthPixelsMESA");
954 RENDER_FINISH(swrast
,ctx
);