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 "bufferobj.h"
28 #include "main/context.h"
31 #include "main/macros.h"
32 #include "main/imports.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];
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 */
66 return GL_TRUE
; /* no-op */
68 rbType
= rb
->DataType
;
70 if ((swrast
->_RasterMask
& ~CLIP_BIT
) ||
71 ctx
->Texture
._EnabledCoordUnits
||
72 userUnpack
->SwapBytes
||
73 ctx
->_ImageTransferState
) {
74 /* can't handle any of those conditions */
78 INIT_SPAN(span
, GL_BITMAP
);
79 span
.arrayMask
= SPAN_RGBA
;
80 span
.arrayAttribs
= FRAG_BIT_COL0
;
81 _swrast_span_default_attribs(ctx
, &span
);
83 /* copy input params since clipping may change them */
90 /* check for simple zooming and clipping */
91 if (ctx
->Pixel
.ZoomX
== 1.0F
&&
92 (ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
)) {
93 if (!_mesa_clip_drawpixels(ctx
, &destX
, &destY
,
94 &drawWidth
, &drawHeight
, &unpack
)) {
95 /* image was completely clipped: no-op, all done */
99 yStep
= (GLint
) ctx
->Pixel
.ZoomY
;
100 ASSERT(yStep
== 1 || yStep
== -1);
103 /* non-simple zooming */
104 simpleZoom
= GL_FALSE
;
106 if (unpack
.RowLength
== 0)
107 unpack
.RowLength
= width
;
114 if (format
== GL_RGBA
&& type
== rbType
) {
116 = (const GLubyte
*) _mesa_image_address2d(&unpack
, pixels
, width
,
117 height
, format
, type
, 0, 0);
118 const GLint srcStride
= _mesa_image_row_stride(&unpack
, width
,
122 for (row
= 0; row
< drawHeight
; row
++) {
123 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
, src
, NULL
);
131 for (row
= 0; row
< drawHeight
; row
++) {
133 span
.y
= destY
+ row
;
134 span
.end
= drawWidth
;
135 span
.array
->ChanType
= rbType
;
136 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, src
);
139 span
.array
->ChanType
= CHAN_TYPE
;
144 if (format
== GL_RGB
&& type
== rbType
) {
146 = (const GLubyte
*) _mesa_image_address2d(&unpack
, pixels
, width
,
147 height
, format
, type
, 0, 0);
148 const GLint srcStride
= _mesa_image_row_stride(&unpack
, width
,
152 for (row
= 0; row
< drawHeight
; row
++) {
153 rb
->PutRowRGB(ctx
, rb
, drawWidth
, destX
, destY
, src
, NULL
);
161 for (row
= 0; row
< drawHeight
; row
++) {
164 span
.end
= drawWidth
;
165 span
.array
->ChanType
= rbType
;
166 _swrast_write_zoomed_rgb_span(ctx
, imgX
, imgY
, &span
, src
);
170 span
.array
->ChanType
= CHAN_TYPE
;
175 /* Remaining cases haven't been tested with alignment != 1 */
176 if (userUnpack
->Alignment
!= 1)
179 if (format
== GL_LUMINANCE
&& type
== CHAN_TYPE
&& rbType
== CHAN_TYPE
) {
180 const GLchan
*src
= (const GLchan
*) pixels
181 + (unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
);
185 ASSERT(drawWidth
<= MAX_WIDTH
);
186 for (row
= 0; row
< drawHeight
; row
++) {
187 GLchan rgb
[MAX_WIDTH
][3];
189 for (i
= 0;i
<drawWidth
;i
++) {
194 rb
->PutRowRGB(ctx
, rb
, drawWidth
, destX
, destY
, rgb
, NULL
);
195 src
+= unpack
.RowLength
;
202 ASSERT(drawWidth
<= MAX_WIDTH
);
203 for (row
= 0; row
< drawHeight
; row
++) {
204 GLchan rgb
[MAX_WIDTH
][3];
206 for (i
= 0;i
<drawWidth
;i
++) {
213 span
.end
= drawWidth
;
214 _swrast_write_zoomed_rgb_span(ctx
, imgX
, imgY
, &span
, rgb
);
215 src
+= unpack
.RowLength
;
222 if (format
== GL_LUMINANCE_ALPHA
&& type
== CHAN_TYPE
&& rbType
== CHAN_TYPE
) {
223 const GLchan
*src
= (const GLchan
*) pixels
224 + (unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
)*2;
227 ASSERT(drawWidth
<= MAX_WIDTH
);
228 for (row
= 0; row
< drawHeight
; row
++) {
230 const GLchan
*ptr
= src
;
231 for (i
= 0;i
<drawWidth
;i
++) {
232 span
.array
->rgba
[i
][0] = *ptr
;
233 span
.array
->rgba
[i
][1] = *ptr
;
234 span
.array
->rgba
[i
][2] = *ptr
++;
235 span
.array
->rgba
[i
][3] = *ptr
++;
237 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
238 span
.array
->rgba
, NULL
);
239 src
+= unpack
.RowLength
*2;
246 ASSERT(drawWidth
<= MAX_WIDTH
);
247 for (row
= 0; row
< drawHeight
; row
++) {
248 const GLchan
*ptr
= src
;
250 for (i
= 0;i
<drawWidth
;i
++) {
251 span
.array
->rgba
[i
][0] = *ptr
;
252 span
.array
->rgba
[i
][1] = *ptr
;
253 span
.array
->rgba
[i
][2] = *ptr
++;
254 span
.array
->rgba
[i
][3] = *ptr
++;
258 span
.end
= drawWidth
;
259 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
261 src
+= unpack
.RowLength
*2;
268 if (format
== GL_COLOR_INDEX
&& type
== GL_UNSIGNED_BYTE
) {
269 const GLubyte
*src
= (const GLubyte
*) pixels
270 + unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
;
271 if (ctx
->Visual
.rgbMode
&& rbType
== GL_UNSIGNED_BYTE
) {
272 /* convert ubyte/CI data to ubyte/RGBA */
275 for (row
= 0; row
< drawHeight
; row
++) {
276 ASSERT(drawWidth
<= MAX_WIDTH
);
277 _mesa_map_ci8_to_rgba8(ctx
, drawWidth
, src
,
279 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
280 span
.array
->rgba8
, NULL
);
281 src
+= unpack
.RowLength
;
286 /* ubyte/CI to ubyte/RGBA with zooming */
288 for (row
= 0; row
< drawHeight
; row
++) {
289 ASSERT(drawWidth
<= MAX_WIDTH
);
290 _mesa_map_ci8_to_rgba8(ctx
, drawWidth
, src
,
294 span
.end
= drawWidth
;
295 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
297 src
+= unpack
.RowLength
;
303 else if (!ctx
->Visual
.rgbMode
&& rbType
== GL_UNSIGNED_INT
) {
304 /* write CI data to CI frame buffer */
307 for (row
= 0; row
< drawHeight
; row
++) {
308 GLuint index32
[MAX_WIDTH
];
310 for (col
= 0; col
< drawWidth
; col
++)
311 index32
[col
] = src
[col
];
312 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
, index32
, NULL
);
313 src
+= unpack
.RowLength
;
321 /* can't handle this pixel format and/or data type */
328 * Draw color index image.
331 draw_index_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
332 GLsizei width
, GLsizei height
,
334 const struct gl_pixelstore_attrib
*unpack
,
335 const GLvoid
*pixels
)
337 const GLint imgX
= x
, imgY
= y
;
338 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
339 GLint row
, skipPixels
;
342 INIT_SPAN(span
, GL_BITMAP
);
343 span
.arrayMask
= SPAN_INDEX
;
344 _swrast_span_default_attribs(ctx
, &span
);
350 while (skipPixels
< width
) {
351 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
352 ASSERT(spanWidth
<= MAX_WIDTH
);
353 for (row
= 0; row
< height
; row
++) {
354 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
356 GL_COLOR_INDEX
, type
,
358 _mesa_unpack_index_span(ctx
, spanWidth
, GL_UNSIGNED_INT
,
359 span
.array
->index
, type
, source
, unpack
,
360 ctx
->_ImageTransferState
);
362 /* These may get changed during writing/clipping */
363 span
.x
= x
+ skipPixels
;
365 span
.end
= spanWidth
;
368 _swrast_write_zoomed_index_span(ctx
, imgX
, imgY
, &span
);
370 _swrast_write_index_span(ctx
, &span
);
372 skipPixels
+= spanWidth
;
379 * Draw stencil image.
382 draw_stencil_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
383 GLsizei width
, GLsizei height
,
385 const struct gl_pixelstore_attrib
*unpack
,
386 const GLvoid
*pixels
)
388 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
391 /* if width > MAX_WIDTH, have to process image in chunks */
393 while (skipPixels
< width
) {
394 const GLint spanX
= x
+ skipPixels
;
395 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
397 for (row
= 0; row
< height
; row
++) {
398 const GLint spanY
= y
+ row
;
399 GLstencil values
[MAX_WIDTH
];
400 GLenum destType
= (sizeof(GLstencil
) == sizeof(GLubyte
))
401 ? GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
402 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
404 GL_COLOR_INDEX
, type
,
406 _mesa_unpack_stencil_span(ctx
, spanWidth
, destType
, values
,
407 type
, source
, unpack
,
408 ctx
->_ImageTransferState
);
410 _swrast_write_zoomed_stencil_span(ctx
, x
, y
, spanWidth
,
411 spanX
, spanY
, values
);
414 _swrast_write_stencil_span(ctx
, spanWidth
, spanX
, spanY
, values
);
417 skipPixels
+= spanWidth
;
426 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
427 GLsizei width
, GLsizei height
,
429 const struct gl_pixelstore_attrib
*unpack
,
430 const GLvoid
*pixels
)
432 const GLboolean scaleOrBias
433 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
434 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
437 INIT_SPAN(span
, GL_BITMAP
);
438 span
.arrayMask
= SPAN_Z
;
439 _swrast_span_default_attribs(ctx
, &span
);
441 if (type
== GL_UNSIGNED_SHORT
442 && ctx
->DrawBuffer
->Visual
.depthBits
== 16
445 && ctx
->Visual
.rgbMode
446 && width
<= MAX_WIDTH
447 && !unpack
->SwapBytes
) {
448 /* Special case: directly write 16-bit depth values */
450 for (row
= 0; row
< height
; row
++) {
451 const GLushort
*zSrc
= (const GLushort
*)
452 _mesa_image_address2d(unpack
, pixels
, width
, height
,
453 GL_DEPTH_COMPONENT
, type
, row
, 0);
455 for (i
= 0; i
< width
; i
++)
456 span
.array
->z
[i
] = zSrc
[i
];
460 _swrast_write_rgba_span(ctx
, &span
);
463 else if (type
== GL_UNSIGNED_INT
466 && ctx
->Visual
.rgbMode
467 && width
<= MAX_WIDTH
468 && !unpack
->SwapBytes
) {
469 /* Special case: shift 32-bit values down to Visual.depthBits */
470 const GLint shift
= 32 - ctx
->DrawBuffer
->Visual
.depthBits
;
472 for (row
= 0; row
< height
; row
++) {
473 const GLuint
*zSrc
= (const GLuint
*)
474 _mesa_image_address2d(unpack
, pixels
, width
, height
,
475 GL_DEPTH_COMPONENT
, type
, row
, 0);
477 _mesa_memcpy(span
.array
->z
, zSrc
, width
* sizeof(GLuint
));
481 for (col
= 0; col
< width
; col
++)
482 span
.array
->z
[col
] = zSrc
[col
] >> shift
;
487 _swrast_write_rgba_span(ctx
, &span
);
492 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
493 GLint skipPixels
= 0;
495 /* in case width > MAX_WIDTH do the copy in chunks */
496 while (skipPixels
< width
) {
497 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
499 ASSERT(span
.end
<= MAX_WIDTH
);
500 for (row
= 0; row
< height
; row
++) {
501 const GLvoid
*zSrc
= _mesa_image_address2d(unpack
,
502 pixels
, width
, height
,
503 GL_DEPTH_COMPONENT
, type
,
506 /* Set these for each row since the _swrast_write_* function may
507 * change them while clipping.
509 span
.x
= x
+ skipPixels
;
511 span
.end
= spanWidth
;
513 _mesa_unpack_depth_span(ctx
, spanWidth
,
514 GL_UNSIGNED_INT
, span
.array
->z
, depthMax
,
517 _swrast_write_zoomed_depth_span(ctx
, x
, y
, &span
);
519 else if (ctx
->Visual
.rgbMode
) {
520 _swrast_write_rgba_span(ctx
, &span
);
523 _swrast_write_index_span(ctx
, &span
);
526 skipPixels
+= spanWidth
;
537 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
538 GLsizei width
, GLsizei height
,
539 GLenum format
, GLenum type
,
540 const struct gl_pixelstore_attrib
*unpack
,
541 const GLvoid
*pixels
)
543 const GLint imgX
= x
, imgY
= y
;
544 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
545 GLfloat
*convImage
= NULL
;
546 GLbitfield transferOps
= ctx
->_ImageTransferState
;
549 /* Try an optimized glDrawPixels first */
550 if (fast_draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
,
555 INIT_SPAN(span
, GL_BITMAP
);
556 _swrast_span_default_attribs(ctx
, &span
);
557 span
.arrayMask
= SPAN_RGBA
;
558 span
.arrayAttribs
= FRAG_BIT_COL0
; /* we're fill in COL0 attrib values */
560 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
561 /* Convolution has to be handled specially. We'll create an
562 * intermediate image, applying all pixel transfer operations
563 * up to convolution. Then we'll convolve the image. Then
564 * we'll proceed with the rest of the transfer operations and
565 * rasterize the image.
568 GLfloat
*dest
, *tmpImage
;
570 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
572 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
575 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
577 _mesa_free(tmpImage
);
578 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
582 /* Unpack the image and apply transfer ops up to convolution */
584 for (row
= 0; row
< height
; row
++) {
585 const GLvoid
*source
= _mesa_image_address2d(unpack
,
586 pixels
, width
, height
, format
, type
, row
, 0);
587 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
, (GLfloat
*) dest
,
588 format
, type
, source
, unpack
,
589 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
);
594 if (ctx
->Pixel
.Convolution2DEnabled
) {
595 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
598 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
599 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
601 _mesa_free(tmpImage
);
603 /* continue transfer ops and draw the convolved image */
604 unpack
= &ctx
->DefaultPacking
;
608 transferOps
&= IMAGE_POST_CONVOLUTION_BITS
;
610 else if (ctx
->Pixel
.Convolution1DEnabled
) {
611 /* we only want to apply 1D convolution to glTexImage1D */
612 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
613 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
616 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
> 0 &&
617 ctx
->DrawBuffer
->_ColorDrawBuffers
[0]->DataType
!= GL_FLOAT
&&
618 ctx
->Color
.ClampFragmentColor
!= GL_FALSE
) {
619 /* need to clamp colors before applying fragment ops */
620 transferOps
|= IMAGE_CLAMP_BIT
;
627 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
628 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
629 const GLbitfield interpMask
= span
.interpMask
;
630 const GLbitfield arrayMask
= span
.arrayMask
;
631 const GLint srcStride
632 = _mesa_image_row_stride(unpack
, width
, format
, type
);
633 GLint skipPixels
= 0;
634 /* use span array for temp color storage */
635 GLfloat
*rgba
= (GLfloat
*) span
.array
->attribs
[FRAG_ATTRIB_COL0
];
637 /* if the span is wider than MAX_WIDTH we have to do it in chunks */
638 while (skipPixels
< width
) {
639 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
640 const GLubyte
*source
641 = (const GLubyte
*) _mesa_image_address2d(unpack
, pixels
,
642 width
, height
, format
,
643 type
, 0, skipPixels
);
646 for (row
= 0; row
< height
; row
++) {
647 /* get image row as float/RGBA */
648 _mesa_unpack_color_span_float(ctx
, spanWidth
, GL_RGBA
, rgba
,
649 format
, type
, source
, unpack
,
653 /* Set these for each row since the _swrast_write_* functions
654 * may change them while clipping/rendering.
656 span
.array
->ChanType
= GL_FLOAT
;
657 span
.x
= x
+ skipPixels
;
659 span
.end
= spanWidth
;
660 span
.arrayMask
= arrayMask
;
661 span
.interpMask
= interpMask
;
663 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, rgba
);
666 _swrast_write_rgba_span(ctx
, &span
);
673 skipPixels
+= spanWidth
;
674 } /* while skipPixels < width */
676 /* XXX this is ugly/temporary, to undo above change */
677 span
.array
->ChanType
= CHAN_TYPE
;
681 _mesa_free(convImage
);
687 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
688 * The only per-pixel operations that apply are depth scale/bias,
689 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
691 * Also, only the depth buffer and stencil buffers are touched, not the
695 draw_depth_stencil_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
696 GLsizei width
, GLsizei height
, GLenum type
,
697 const struct gl_pixelstore_attrib
*unpack
,
698 const GLvoid
*pixels
)
700 const GLint imgX
= x
, imgY
= y
;
701 const GLboolean scaleOrBias
702 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
703 const GLuint depthMax
= ctx
->DrawBuffer
->_DepthMax
;
704 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
705 const GLuint stencilType
= (STENCIL_BITS
== 8) ?
706 GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
707 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
708 struct gl_renderbuffer
*depthRb
, *stencilRb
;
709 struct gl_pixelstore_attrib clippedUnpack
= *unpack
;
712 if (!_mesa_clip_drawpixels(ctx
, &x
, &y
, &width
, &height
,
714 /* totally clipped */
719 depthRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
720 stencilRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
724 if (depthRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
725 stencilRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
726 depthRb
== stencilRb
&&
730 (stencilMask
& 0xff) == 0xff) {
731 /* This is the ideal case.
732 * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
733 * Plus, no pixel transfer ops, zooming, or masking needed.
736 for (i
= 0; i
< height
; i
++) {
737 const GLuint
*src
= (const GLuint
*)
738 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
739 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
740 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, src
, NULL
);
744 /* sub-optimal cases:
745 * Separate depth/stencil buffers, or pixel transfer ops required.
747 /* XXX need to handle very wide images (skippixels) */
750 depthRb
= ctx
->DrawBuffer
->_DepthBuffer
;
751 stencilRb
= ctx
->DrawBuffer
->_StencilBuffer
;
753 for (i
= 0; i
< height
; i
++) {
754 const GLuint
*depthStencilSrc
= (const GLuint
*)
755 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
756 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
758 if (ctx
->Depth
.Mask
) {
759 if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 24) {
760 /* fast path 24-bit zbuffer */
761 GLuint zValues
[MAX_WIDTH
];
763 ASSERT(depthRb
->DataType
== GL_UNSIGNED_INT
);
764 for (j
= 0; j
< width
; j
++) {
765 zValues
[j
] = depthStencilSrc
[j
] >> 8;
768 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
771 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
773 else if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 16) {
774 /* fast path 16-bit zbuffer */
775 GLushort zValues
[MAX_WIDTH
];
777 ASSERT(depthRb
->DataType
== GL_UNSIGNED_SHORT
);
778 for (j
= 0; j
< width
; j
++) {
779 zValues
[j
] = depthStencilSrc
[j
] >> 16;
782 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
785 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
789 GLuint zValues
[MAX_WIDTH
]; /* 16 or 32-bit Z value storage */
790 _mesa_unpack_depth_span(ctx
, width
,
791 depthRb
->DataType
, zValues
, depthMax
,
792 type
, depthStencilSrc
, &clippedUnpack
);
794 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
, x
,
798 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
803 if (stencilMask
!= 0x0) {
804 GLstencil stencilValues
[MAX_WIDTH
];
805 /* get stencil values, with shift/offset/mapping */
806 _mesa_unpack_stencil_span(ctx
, width
, stencilType
, stencilValues
,
807 type
, depthStencilSrc
, &clippedUnpack
,
808 ctx
->_ImageTransferState
);
810 _swrast_write_zoomed_stencil_span(ctx
, imgX
, imgY
, width
,
811 x
, y
+ i
, stencilValues
);
813 _swrast_write_stencil_span(ctx
, width
, x
, y
+ i
, stencilValues
);
821 * Execute software-based glDrawPixels.
822 * By time we get here, all error checking will have been done.
825 _swrast_DrawPixels( GLcontext
*ctx
,
827 GLsizei width
, GLsizei height
,
828 GLenum format
, GLenum type
,
829 const struct gl_pixelstore_attrib
*unpack
,
830 const GLvoid
*pixels
)
832 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
834 RENDER_START(swrast
,ctx
);
837 _mesa_update_state(ctx
);
839 if (swrast
->NewState
)
840 _swrast_validate_derived( ctx
);
842 pixels
= _mesa_map_drawpix_pbo(ctx
, unpack
, pixels
);
844 RENDER_FINISH(swrast
,ctx
);
849 case GL_STENCIL_INDEX
:
850 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
852 case GL_DEPTH_COMPONENT
:
853 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
856 if (ctx
->Visual
.rgbMode
)
857 draw_rgba_pixels(ctx
, x
,y
, width
, height
, format
, type
, unpack
, pixels
);
859 draw_index_pixels(ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
866 case GL_LUMINANCE_ALPHA
:
872 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
874 case GL_DEPTH_STENCIL_EXT
:
875 draw_depth_stencil_pixels(ctx
, x
, y
, width
, height
,
876 type
, unpack
, pixels
);
879 _mesa_problem(ctx
, "unexpected format in _swrast_DrawPixels");
880 /* don't return yet, clean-up */
883 RENDER_FINISH(swrast
,ctx
);
885 _mesa_unmap_drapix_pbo(ctx
, unpack
);
890 #if 0 /* experimental */
892 * Execute glDrawDepthPixelsMESA().
895 _swrast_DrawDepthPixelsMESA( GLcontext
*ctx
,
897 GLsizei width
, GLsizei height
,
898 GLenum colorFormat
, GLenum colorType
,
899 const GLvoid
*colors
,
900 GLenum depthType
, const GLvoid
*depths
,
901 const struct gl_pixelstore_attrib
*unpack
)
903 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
905 if (swrast
->NewState
)
906 _swrast_validate_derived( ctx
);
908 RENDER_START(swrast
,ctx
);
910 switch (colorFormat
) {
912 if (ctx
->Visual
.rgbMode
)
913 draw_rgba_pixels(ctx
, x
,y
, width
, height
, colorFormat
, colorType
,
916 draw_index_pixels(ctx
, x
, y
, width
, height
, colorType
,
924 case GL_LUMINANCE_ALPHA
:
930 draw_rgba_pixels(ctx
, x
, y
, width
, height
, colorFormat
, colorType
,
934 _mesa_problem(ctx
, "unexpected format in glDrawDepthPixelsMESA");
937 RENDER_FINISH(swrast
,ctx
);