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
, 0, 0, SPAN_RGBA
);
75 _swrast_span_default_z(ctx
, &span
);
76 if (swrast
->_FogEnabled
)
77 _swrast_span_default_fog(ctx
, &span
);
78 if (ctx
->Texture
._EnabledCoordUnits
)
79 _swrast_span_default_texcoords(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
,
276 span
.array
->color
.sz1
.rgba
);
277 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
278 span
.array
->color
.sz1
.rgba
, 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
,
289 span
.array
->color
.sz1
.rgba
);
292 span
.end
= drawWidth
;
293 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
294 span
.array
->color
.sz1
.rgba
);
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 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
336 const GLint imgX
= x
, imgY
= y
;
337 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
338 GLint row
, skipPixels
;
341 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
344 _swrast_span_default_z(ctx
, &span
);
345 if (swrast
->_FogEnabled
)
346 _swrast_span_default_fog(ctx
, &span
);
352 while (skipPixels
< width
) {
353 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
354 ASSERT(spanWidth
<= MAX_WIDTH
);
355 for (row
= 0; row
< height
; row
++) {
356 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
358 GL_COLOR_INDEX
, type
,
360 _mesa_unpack_index_span(ctx
, spanWidth
, GL_UNSIGNED_INT
,
361 span
.array
->index
, type
, source
, unpack
,
362 ctx
->_ImageTransferState
);
364 /* These may get changed during writing/clipping */
365 span
.x
= x
+ skipPixels
;
367 span
.end
= spanWidth
;
370 _swrast_write_zoomed_index_span(ctx
, imgX
, imgY
, &span
);
372 _swrast_write_index_span(ctx
, &span
);
374 skipPixels
+= spanWidth
;
381 * Draw stencil image.
384 draw_stencil_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
385 GLsizei width
, GLsizei height
,
387 const struct gl_pixelstore_attrib
*unpack
,
388 const GLvoid
*pixels
)
390 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
393 /* if width > MAX_WIDTH, have to process image in chunks */
395 while (skipPixels
< width
) {
396 const GLint spanX
= x
+ skipPixels
;
397 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
399 for (row
= 0; row
< height
; row
++) {
400 const GLint spanY
= y
+ row
;
401 GLstencil values
[MAX_WIDTH
];
402 GLenum destType
= (sizeof(GLstencil
) == sizeof(GLubyte
))
403 ? GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
404 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
406 GL_COLOR_INDEX
, type
,
408 _mesa_unpack_index_span(ctx
, spanWidth
, destType
, values
,
409 type
, source
, unpack
,
410 ctx
->_ImageTransferState
);
411 _mesa_apply_stencil_transfer_ops(ctx
, spanWidth
, values
);
413 _swrast_write_zoomed_stencil_span(ctx
, x
, y
, spanWidth
,
414 spanX
, spanY
, values
);
417 _swrast_write_stencil_span(ctx
, spanWidth
, spanX
, spanY
, values
);
420 skipPixels
+= spanWidth
;
429 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
430 GLsizei width
, GLsizei height
,
432 const struct gl_pixelstore_attrib
*unpack
,
433 const GLvoid
*pixels
)
435 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
436 const GLboolean scaleOrBias
437 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
438 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
441 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
443 _swrast_span_default_color(ctx
, &span
);
445 if (swrast
->_FogEnabled
)
446 _swrast_span_default_fog(ctx
, &span
);
447 if (ctx
->Texture
._EnabledCoordUnits
)
448 _swrast_span_default_texcoords(ctx
, &span
);
450 if (type
== GL_UNSIGNED_SHORT
451 && ctx
->DrawBuffer
->Visual
.depthBits
== 16
454 && ctx
->Visual
.rgbMode
455 && width
<= MAX_WIDTH
456 && !unpack
->SwapBytes
) {
457 /* Special case: directly write 16-bit depth values */
459 for (row
= 0; row
< height
; row
++) {
460 const GLushort
*zSrc
= (const GLushort
*)
461 _mesa_image_address2d(unpack
, pixels
, width
, height
,
462 GL_DEPTH_COMPONENT
, type
, row
, 0);
464 for (i
= 0; i
< width
; i
++)
465 span
.array
->z
[i
] = zSrc
[i
];
469 _swrast_write_rgba_span(ctx
, &span
);
472 else if (type
== GL_UNSIGNED_INT
475 && ctx
->Visual
.rgbMode
476 && width
<= MAX_WIDTH
477 && !unpack
->SwapBytes
) {
478 /* Special case: shift 32-bit values down to Visual.depthBits */
479 const GLint shift
= 32 - ctx
->DrawBuffer
->Visual
.depthBits
;
481 for (row
= 0; row
< height
; row
++) {
482 const GLuint
*zSrc
= (const GLuint
*)
483 _mesa_image_address2d(unpack
, pixels
, width
, height
,
484 GL_DEPTH_COMPONENT
, type
, row
, 0);
486 _mesa_memcpy(span
.array
->z
, zSrc
, width
* sizeof(GLuint
));
490 for (col
= 0; col
< width
; col
++)
491 span
.array
->z
[col
] = zSrc
[col
] >> shift
;
496 _swrast_write_rgba_span(ctx
, &span
);
501 const GLfloat depthMax
= ctx
->DrawBuffer
->_DepthMaxF
;
502 GLint skipPixels
= 0;
504 /* in case width > MAX_WIDTH do the copy in chunks */
505 while (skipPixels
< width
) {
506 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
508 ASSERT(span
.end
<= MAX_WIDTH
);
509 for (row
= 0; row
< height
; row
++) {
510 const GLvoid
*zSrc
= _mesa_image_address2d(unpack
,
511 pixels
, width
, height
,
512 GL_DEPTH_COMPONENT
, type
,
515 /* Set these for each row since the _swrast_write_* function may
516 * change them while clipping.
518 span
.x
= x
+ skipPixels
;
520 span
.end
= spanWidth
;
522 _mesa_unpack_depth_span(ctx
, spanWidth
,
523 GL_UNSIGNED_INT
, span
.array
->z
, depthMax
,
526 _swrast_write_zoomed_depth_span(ctx
, x
, y
, &span
);
528 else if (ctx
->Visual
.rgbMode
) {
529 _swrast_write_rgba_span(ctx
, &span
);
532 _swrast_write_index_span(ctx
, &span
);
535 skipPixels
+= spanWidth
;
546 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
547 GLsizei width
, GLsizei height
,
548 GLenum format
, GLenum type
,
549 const struct gl_pixelstore_attrib
*unpack
,
550 const GLvoid
*pixels
)
552 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
553 const GLint imgX
= x
, imgY
= y
;
554 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
555 GLfloat
*convImage
= NULL
;
556 GLbitfield transferOps
= ctx
->_ImageTransferState
;
559 /* Try an optimized glDrawPixels first */
560 if (fast_draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
,
564 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_RGBA
);
566 _swrast_span_default_z(ctx
, &span
);
567 if (swrast
->_FogEnabled
)
568 _swrast_span_default_fog(ctx
, &span
);
569 if (ctx
->Texture
._EnabledCoordUnits
)
570 _swrast_span_default_texcoords(ctx
, &span
);
572 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
573 /* Convolution has to be handled specially. We'll create an
574 * intermediate image, applying all pixel transfer operations
575 * up to convolution. Then we'll convolve the image. Then
576 * we'll proceed with the rest of the transfer operations and
577 * rasterize the image.
580 GLfloat
*dest
, *tmpImage
;
582 tmpImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
584 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
587 convImage
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
589 _mesa_free(tmpImage
);
590 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
594 /* Unpack the image and apply transfer ops up to convolution */
596 for (row
= 0; row
< height
; row
++) {
597 const GLvoid
*source
= _mesa_image_address2d(unpack
,
598 pixels
, width
, height
, format
, type
, row
, 0);
599 _mesa_unpack_color_span_float(ctx
, width
, GL_RGBA
, (GLfloat
*) dest
,
600 format
, type
, source
, unpack
,
601 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
);
606 if (ctx
->Pixel
.Convolution2DEnabled
) {
607 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
610 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
611 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
613 _mesa_free(tmpImage
);
615 /* continue transfer ops and draw the convolved image */
616 unpack
= &ctx
->DefaultPacking
;
620 transferOps
&= IMAGE_POST_CONVOLUTION_BITS
;
622 else if (ctx
->Pixel
.Convolution1DEnabled
) {
623 /* we only want to apply 1D convolution to glTexImage1D */
624 transferOps
&= ~(IMAGE_CONVOLUTION_BIT
|
625 IMAGE_POST_CONVOLUTION_SCALE_BIAS
);
628 if (ctx
->DrawBuffer
->_NumColorDrawBuffers
[0] > 0 &&
629 ctx
->DrawBuffer
->_ColorDrawBuffers
[0][0]->DataType
!= GL_FLOAT
&&
630 ctx
->Color
.ClampFragmentColor
!= GL_FALSE
) {
631 /* need to clamp colors before applying fragment ops */
632 transferOps
|= IMAGE_CLAMP_BIT
;
639 const GLboolean sink
= (ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
)
640 || (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
);
641 const GLbitfield interpMask
= span
.interpMask
;
642 const GLbitfield arrayMask
= span
.arrayMask
;
643 const GLint srcStride
644 = _mesa_image_row_stride(unpack
, width
, format
, type
);
645 GLint skipPixels
= 0;
646 /* use span array for temp color storage */
647 GLfloat
*rgba
= (GLfloat
*) span
.array
->attribs
[FRAG_ATTRIB_COL0
];
649 /* if the span is wider than MAX_WIDTH we have to do it in chunks */
650 while (skipPixels
< width
) {
651 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
652 const GLubyte
*source
653 = (const GLubyte
*) _mesa_image_address2d(unpack
, pixels
,
654 width
, height
, format
,
655 type
, 0, skipPixels
);
658 for (row
= 0; row
< height
; row
++) {
659 /* get image row as float/RGBA */
660 _mesa_unpack_color_span_float(ctx
, spanWidth
, GL_RGBA
, rgba
,
661 format
, type
, source
, unpack
,
665 /* Set these for each row since the _swrast_write_* functions
666 * may change them while clipping/rendering.
668 span
.array
->ChanType
= GL_FLOAT
;
669 span
.x
= x
+ skipPixels
;
671 span
.end
= spanWidth
;
672 span
.arrayMask
= arrayMask
;
673 span
.interpMask
= interpMask
;
675 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, rgba
);
678 _swrast_write_rgba_span(ctx
, &span
);
685 skipPixels
+= spanWidth
;
686 } /* while skipPixels < width */
688 /* XXX this is ugly/temporary, to undo above change */
689 span
.array
->ChanType
= CHAN_TYPE
;
693 _mesa_free(convImage
);
699 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
700 * The only per-pixel operations that apply are depth scale/bias,
701 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
703 * Also, only the depth buffer and stencil buffers are touched, not the
707 draw_depth_stencil_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
708 GLsizei width
, GLsizei height
, GLenum type
,
709 const struct gl_pixelstore_attrib
*unpack
,
710 const GLvoid
*pixels
)
712 const GLint imgX
= x
, imgY
= y
;
713 const GLboolean scaleOrBias
714 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
715 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
716 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
717 const GLuint stencilType
= (STENCIL_BITS
== 8) ?
718 GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
719 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
720 struct gl_renderbuffer
*depthRb
, *stencilRb
;
721 struct gl_pixelstore_attrib clippedUnpack
= *unpack
;
724 if (!_mesa_clip_drawpixels(ctx
, &x
, &y
, &width
, &height
,
726 /* totally clipped */
731 depthRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
732 stencilRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
736 if (depthRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
737 stencilRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
738 depthRb
== stencilRb
&&
742 (stencilMask
& 0xff) == 0xff) {
743 /* This is the ideal case.
744 * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
745 * Plus, no pixel transfer ops, zooming, or masking needed.
748 for (i
= 0; i
< height
; i
++) {
749 const GLuint
*src
= (const GLuint
*)
750 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
751 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
752 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, src
, NULL
);
756 /* sub-optimal cases:
757 * Separate depth/stencil buffers, or pixel transfer ops required.
759 /* XXX need to handle very wide images (skippixels) */
762 depthRb
= ctx
->DrawBuffer
->_DepthBuffer
;
763 stencilRb
= ctx
->DrawBuffer
->_StencilBuffer
;
765 for (i
= 0; i
< height
; i
++) {
766 const GLuint
*depthStencilSrc
= (const GLuint
*)
767 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
768 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
770 if (ctx
->Depth
.Mask
) {
771 if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 24) {
772 /* fast path 24-bit zbuffer */
773 GLuint zValues
[MAX_WIDTH
];
775 ASSERT(depthRb
->DataType
== GL_UNSIGNED_INT
);
776 for (j
= 0; j
< width
; j
++) {
777 zValues
[j
] = depthStencilSrc
[j
] >> 8;
780 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
783 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
785 else if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 16) {
786 /* fast path 16-bit zbuffer */
787 GLushort zValues
[MAX_WIDTH
];
789 ASSERT(depthRb
->DataType
== GL_UNSIGNED_SHORT
);
790 for (j
= 0; j
< width
; j
++) {
791 zValues
[j
] = depthStencilSrc
[j
] >> 16;
794 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
797 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
801 GLuint zValues
[MAX_WIDTH
]; /* 16 or 32-bit Z value storage */
802 _mesa_unpack_depth_span(ctx
, width
,
803 depthRb
->DataType
, zValues
, depthScale
,
804 type
, depthStencilSrc
, &clippedUnpack
);
806 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
, x
,
810 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
815 if (stencilMask
!= 0x0) {
816 GLstencil stencilValues
[MAX_WIDTH
];
817 /* get stencil values, with shift/offset/mapping */
818 _mesa_unpack_stencil_span(ctx
, width
, stencilType
, stencilValues
,
819 type
, depthStencilSrc
, &clippedUnpack
,
820 ctx
->_ImageTransferState
);
822 _swrast_write_zoomed_stencil_span(ctx
, imgX
, imgY
, width
,
823 x
, y
+ i
, stencilValues
);
825 _swrast_write_stencil_span(ctx
, width
, x
, y
+ i
, stencilValues
);
834 * Execute software-based glDrawPixels.
835 * By time we get here, all error checking will have been done.
838 _swrast_DrawPixels( GLcontext
*ctx
,
840 GLsizei width
, GLsizei height
,
841 GLenum format
, GLenum type
,
842 const struct gl_pixelstore_attrib
*unpack
,
843 const GLvoid
*pixels
)
845 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
847 RENDER_START(swrast
,ctx
);
850 _mesa_update_state(ctx
);
852 if (swrast
->NewState
)
853 _swrast_validate_derived( ctx
);
855 if (unpack
->BufferObj
->Name
) {
856 /* unpack from PBO */
858 if (!_mesa_validate_pbo_access(2, unpack
, width
, height
, 1,
859 format
, type
, pixels
)) {
860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
861 "glDrawPixels(invalid PBO access)");
864 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
868 /* buffer is already mapped - that's an error */
869 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glDrawPixels(PBO is mapped)");
872 pixels
= ADD_POINTERS(buf
, pixels
);
876 case GL_STENCIL_INDEX
:
877 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
879 case GL_DEPTH_COMPONENT
:
880 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
883 if (ctx
->Visual
.rgbMode
)
884 draw_rgba_pixels(ctx
, x
,y
, width
, height
, format
, type
, unpack
, pixels
);
886 draw_index_pixels(ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
893 case GL_LUMINANCE_ALPHA
:
899 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
901 case GL_DEPTH_STENCIL_EXT
:
902 draw_depth_stencil_pixels(ctx
, x
, y
, width
, height
,
903 type
, unpack
, pixels
);
906 _mesa_problem(ctx
, "unexpected format in _swrast_DrawPixels");
907 /* don't return yet, clean-up */
912 RENDER_FINISH(swrast
,ctx
);
914 if (unpack
->BufferObj
->Name
) {
915 /* done with PBO so unmap it now */
916 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
923 #if 0 /* experimental */
925 * Execute glDrawDepthPixelsMESA().
928 _swrast_DrawDepthPixelsMESA( GLcontext
*ctx
,
930 GLsizei width
, GLsizei height
,
931 GLenum colorFormat
, GLenum colorType
,
932 const GLvoid
*colors
,
933 GLenum depthType
, const GLvoid
*depths
,
934 const struct gl_pixelstore_attrib
*unpack
)
936 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
938 if (swrast
->NewState
)
939 _swrast_validate_derived( ctx
);
941 RENDER_START(swrast
,ctx
);
943 switch (colorFormat
) {
945 if (ctx
->Visual
.rgbMode
)
946 draw_rgba_pixels(ctx
, x
,y
, width
, height
, colorFormat
, colorType
,
949 draw_index_pixels(ctx
, x
, y
, width
, height
, colorType
,
957 case GL_LUMINANCE_ALPHA
:
963 draw_rgba_pixels(ctx
, x
, y
, width
, height
, colorFormat
, colorType
,
967 _mesa_problem(ctx
, "unexpected format in glDrawDepthPixelsMESA");
970 RENDER_FINISH(swrast
,ctx
);