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
);
74 _swrast_span_default_attribs(ctx
, &span
);
76 /* copy input params since clipping may change them */
83 /* check for simple zooming and clipping */
84 if (ctx
->Pixel
.ZoomX
== 1.0F
&&
85 (ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
)) {
86 if (!_mesa_clip_drawpixels(ctx
, &destX
, &destY
,
87 &drawWidth
, &drawHeight
, &unpack
)) {
88 /* image was completely clipped: no-op, all done */
92 yStep
= (GLint
) ctx
->Pixel
.ZoomY
;
93 ASSERT(yStep
== 1 || yStep
== -1);
96 /* non-simple zooming */
97 simpleZoom
= GL_FALSE
;
99 if (unpack
.RowLength
== 0)
100 unpack
.RowLength
= width
;
107 if (format
== GL_RGBA
&& type
== rbType
) {
109 = (const GLubyte
*) _mesa_image_address2d(&unpack
, pixels
, width
,
110 height
, format
, type
, 0, 0);
111 const GLint srcStride
= _mesa_image_row_stride(&unpack
, width
,
115 for (row
= 0; row
< drawHeight
; row
++) {
116 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
, src
, NULL
);
124 for (row
= 0; row
< drawHeight
; row
++) {
126 span
.y
= destY
+ row
;
127 span
.end
= drawWidth
;
128 span
.array
->ChanType
= rbType
;
129 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
, src
);
132 span
.array
->ChanType
= CHAN_TYPE
;
137 if (format
== GL_RGB
&& type
== rbType
) {
139 = (const GLubyte
*) _mesa_image_address2d(&unpack
, pixels
, width
,
140 height
, format
, type
, 0, 0);
141 const GLint srcStride
= _mesa_image_row_stride(&unpack
, width
,
145 for (row
= 0; row
< drawHeight
; row
++) {
146 rb
->PutRowRGB(ctx
, rb
, drawWidth
, destX
, destY
, src
, NULL
);
154 for (row
= 0; row
< drawHeight
; row
++) {
157 span
.end
= drawWidth
;
158 span
.array
->ChanType
= rbType
;
159 _swrast_write_zoomed_rgb_span(ctx
, imgX
, imgY
, &span
, src
);
163 span
.array
->ChanType
= CHAN_TYPE
;
168 /* Remaining cases haven't been tested with alignment != 1 */
169 if (userUnpack
->Alignment
!= 1)
172 if (format
== GL_LUMINANCE
&& type
== CHAN_TYPE
&& rbType
== CHAN_TYPE
) {
173 const GLchan
*src
= (const GLchan
*) pixels
174 + (unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
);
178 ASSERT(drawWidth
<= MAX_WIDTH
);
179 for (row
= 0; row
< drawHeight
; row
++) {
180 GLchan rgb
[MAX_WIDTH
][3];
182 for (i
= 0;i
<drawWidth
;i
++) {
187 rb
->PutRowRGB(ctx
, rb
, drawWidth
, destX
, destY
, rgb
, NULL
);
188 src
+= unpack
.RowLength
;
195 ASSERT(drawWidth
<= MAX_WIDTH
);
196 for (row
= 0; row
< drawHeight
; row
++) {
197 GLchan rgb
[MAX_WIDTH
][3];
199 for (i
= 0;i
<drawWidth
;i
++) {
206 span
.end
= drawWidth
;
207 _swrast_write_zoomed_rgb_span(ctx
, imgX
, imgY
, &span
, rgb
);
208 src
+= unpack
.RowLength
;
215 if (format
== GL_LUMINANCE_ALPHA
&& type
== CHAN_TYPE
&& rbType
== CHAN_TYPE
) {
216 const GLchan
*src
= (const GLchan
*) pixels
217 + (unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
)*2;
220 ASSERT(drawWidth
<= MAX_WIDTH
);
221 for (row
= 0; row
< drawHeight
; row
++) {
223 const GLchan
*ptr
= src
;
224 for (i
= 0;i
<drawWidth
;i
++) {
225 span
.array
->rgba
[i
][0] = *ptr
;
226 span
.array
->rgba
[i
][1] = *ptr
;
227 span
.array
->rgba
[i
][2] = *ptr
++;
228 span
.array
->rgba
[i
][3] = *ptr
++;
230 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
231 span
.array
->rgba
, NULL
);
232 src
+= unpack
.RowLength
*2;
239 ASSERT(drawWidth
<= MAX_WIDTH
);
240 for (row
= 0; row
< drawHeight
; row
++) {
241 const GLchan
*ptr
= src
;
243 for (i
= 0;i
<drawWidth
;i
++) {
244 span
.array
->rgba
[i
][0] = *ptr
;
245 span
.array
->rgba
[i
][1] = *ptr
;
246 span
.array
->rgba
[i
][2] = *ptr
++;
247 span
.array
->rgba
[i
][3] = *ptr
++;
251 span
.end
= drawWidth
;
252 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
254 src
+= unpack
.RowLength
*2;
261 if (format
== GL_COLOR_INDEX
&& type
== GL_UNSIGNED_BYTE
) {
262 const GLubyte
*src
= (const GLubyte
*) pixels
263 + unpack
.SkipRows
* unpack
.RowLength
+ unpack
.SkipPixels
;
264 if (ctx
->Visual
.rgbMode
&& rbType
== GL_UNSIGNED_BYTE
) {
265 /* convert ubyte/CI data to ubyte/RGBA */
268 for (row
= 0; row
< drawHeight
; row
++) {
269 ASSERT(drawWidth
<= MAX_WIDTH
);
270 _mesa_map_ci8_to_rgba8(ctx
, drawWidth
, src
,
272 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
,
273 span
.array
->rgba8
, NULL
);
274 src
+= unpack
.RowLength
;
279 /* ubyte/CI to ubyte/RGBA with zooming */
281 for (row
= 0; row
< drawHeight
; row
++) {
282 ASSERT(drawWidth
<= MAX_WIDTH
);
283 _mesa_map_ci8_to_rgba8(ctx
, drawWidth
, src
,
287 span
.end
= drawWidth
;
288 _swrast_write_zoomed_rgba_span(ctx
, imgX
, imgY
, &span
,
290 src
+= unpack
.RowLength
;
296 else if (!ctx
->Visual
.rgbMode
&& rbType
== GL_UNSIGNED_INT
) {
297 /* write CI data to CI frame buffer */
300 for (row
= 0; row
< drawHeight
; row
++) {
301 GLuint index32
[MAX_WIDTH
];
303 for (col
= 0; col
< drawWidth
; col
++)
304 index32
[col
] = src
[col
];
305 rb
->PutRow(ctx
, rb
, drawWidth
, destX
, destY
, index32
, NULL
);
306 src
+= unpack
.RowLength
;
314 /* can't handle this pixel format and/or data type */
321 * Draw color index image.
324 draw_index_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
325 GLsizei width
, GLsizei height
,
327 const struct gl_pixelstore_attrib
*unpack
,
328 const GLvoid
*pixels
)
330 const GLint imgX
= x
, imgY
= y
;
331 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
332 GLint row
, skipPixels
;
335 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_INDEX
);
336 _swrast_span_default_attribs(ctx
, &span
);
342 while (skipPixels
< width
) {
343 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
344 ASSERT(spanWidth
<= MAX_WIDTH
);
345 for (row
= 0; row
< height
; row
++) {
346 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
348 GL_COLOR_INDEX
, type
,
350 _mesa_unpack_index_span(ctx
, spanWidth
, GL_UNSIGNED_INT
,
351 span
.array
->index
, type
, source
, unpack
,
352 ctx
->_ImageTransferState
);
354 /* These may get changed during writing/clipping */
355 span
.x
= x
+ skipPixels
;
357 span
.end
= spanWidth
;
360 _swrast_write_zoomed_index_span(ctx
, imgX
, imgY
, &span
);
362 _swrast_write_index_span(ctx
, &span
);
364 skipPixels
+= spanWidth
;
371 * Draw stencil image.
374 draw_stencil_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
375 GLsizei width
, GLsizei height
,
377 const struct gl_pixelstore_attrib
*unpack
,
378 const GLvoid
*pixels
)
380 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
383 /* if width > MAX_WIDTH, have to process image in chunks */
385 while (skipPixels
< width
) {
386 const GLint spanX
= x
+ skipPixels
;
387 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
389 for (row
= 0; row
< height
; row
++) {
390 const GLint spanY
= y
+ row
;
391 GLstencil values
[MAX_WIDTH
];
392 GLenum destType
= (sizeof(GLstencil
) == sizeof(GLubyte
))
393 ? GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
394 const GLvoid
*source
= _mesa_image_address2d(unpack
, pixels
,
396 GL_COLOR_INDEX
, type
,
398 _mesa_unpack_index_span(ctx
, spanWidth
, destType
, values
,
399 type
, source
, unpack
,
400 ctx
->_ImageTransferState
);
401 _mesa_apply_stencil_transfer_ops(ctx
, spanWidth
, values
);
403 _swrast_write_zoomed_stencil_span(ctx
, x
, y
, spanWidth
,
404 spanX
, spanY
, values
);
407 _swrast_write_stencil_span(ctx
, spanWidth
, spanX
, spanY
, values
);
410 skipPixels
+= spanWidth
;
419 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
420 GLsizei width
, GLsizei height
,
422 const struct gl_pixelstore_attrib
*unpack
,
423 const GLvoid
*pixels
)
425 const GLboolean scaleOrBias
426 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
427 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
430 INIT_SPAN(span
, GL_BITMAP
, 0, 0, SPAN_Z
);
431 _swrast_span_default_attribs(ctx
, &span
);
433 if (type
== GL_UNSIGNED_SHORT
434 && ctx
->DrawBuffer
->Visual
.depthBits
== 16
437 && ctx
->Visual
.rgbMode
438 && width
<= MAX_WIDTH
439 && !unpack
->SwapBytes
) {
440 /* Special case: directly write 16-bit depth values */
442 for (row
= 0; row
< height
; row
++) {
443 const GLushort
*zSrc
= (const GLushort
*)
444 _mesa_image_address2d(unpack
, pixels
, width
, height
,
445 GL_DEPTH_COMPONENT
, type
, row
, 0);
447 for (i
= 0; i
< width
; i
++)
448 span
.array
->z
[i
] = zSrc
[i
];
452 _swrast_write_rgba_span(ctx
, &span
);
455 else if (type
== GL_UNSIGNED_INT
458 && ctx
->Visual
.rgbMode
459 && width
<= MAX_WIDTH
460 && !unpack
->SwapBytes
) {
461 /* Special case: shift 32-bit values down to Visual.depthBits */
462 const GLint shift
= 32 - ctx
->DrawBuffer
->Visual
.depthBits
;
464 for (row
= 0; row
< height
; row
++) {
465 const GLuint
*zSrc
= (const GLuint
*)
466 _mesa_image_address2d(unpack
, pixels
, width
, height
,
467 GL_DEPTH_COMPONENT
, type
, row
, 0);
469 _mesa_memcpy(span
.array
->z
, zSrc
, width
* sizeof(GLuint
));
473 for (col
= 0; col
< width
; col
++)
474 span
.array
->z
[col
] = zSrc
[col
] >> shift
;
479 _swrast_write_rgba_span(ctx
, &span
);
484 const GLfloat depthMax
= ctx
->DrawBuffer
->_DepthMaxF
;
485 GLint skipPixels
= 0;
487 /* in case width > MAX_WIDTH do the copy in chunks */
488 while (skipPixels
< width
) {
489 const GLint spanWidth
= MIN2(width
- skipPixels
, MAX_WIDTH
);
491 ASSERT(span
.end
<= MAX_WIDTH
);
492 for (row
= 0; row
< height
; row
++) {
493 const GLvoid
*zSrc
= _mesa_image_address2d(unpack
,
494 pixels
, width
, height
,
495 GL_DEPTH_COMPONENT
, type
,
498 /* Set these for each row since the _swrast_write_* function may
499 * change them while clipping.
501 span
.x
= x
+ skipPixels
;
503 span
.end
= spanWidth
;
505 _mesa_unpack_depth_span(ctx
, spanWidth
,
506 GL_UNSIGNED_INT
, span
.array
->z
, depthMax
,
509 _swrast_write_zoomed_depth_span(ctx
, x
, y
, &span
);
511 else if (ctx
->Visual
.rgbMode
) {
512 _swrast_write_rgba_span(ctx
, &span
);
515 _swrast_write_index_span(ctx
, &span
);
518 skipPixels
+= spanWidth
;
529 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
530 GLsizei width
, GLsizei height
,
531 GLenum format
, GLenum type
,
532 const struct gl_pixelstore_attrib
*unpack
,
533 const GLvoid
*pixels
)
535 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
536 const GLbitfield prevActiveAttribs
= swrast
->_ActiveAttribMask
;
537 const GLint imgX
= x
, imgY
= y
;
538 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
539 GLfloat
*convImage
= NULL
;
540 GLbitfield transferOps
= ctx
->_ImageTransferState
;
543 /* don't interpolate COL0 and overwrite the glDrawPixel colors! */
544 swrast
->_ActiveAttribMask
&= ~FRAG_BIT_COL0
;
546 /* Try an optimized glDrawPixels first */
547 if (fast_draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
,
552 INIT_SPAN(span
, GL_BITMAP
, 0, 0x0, SPAN_RGBA
);
553 _swrast_span_default_attribs(ctx
, &span
);
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
);
680 swrast
->_ActiveAttribMask
= prevActiveAttribs
;
685 * This is a bit different from drawing GL_DEPTH_COMPONENT pixels.
686 * The only per-pixel operations that apply are depth scale/bias,
687 * stencil offset/shift, GL_DEPTH_WRITEMASK and GL_STENCIL_WRITEMASK,
689 * Also, only the depth buffer and stencil buffers are touched, not the
693 draw_depth_stencil_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
694 GLsizei width
, GLsizei height
, GLenum type
,
695 const struct gl_pixelstore_attrib
*unpack
,
696 const GLvoid
*pixels
)
698 const GLint imgX
= x
, imgY
= y
;
699 const GLboolean scaleOrBias
700 = ctx
->Pixel
.DepthScale
!= 1.0 || ctx
->Pixel
.DepthBias
!= 0.0;
701 const GLfloat depthScale
= ctx
->DrawBuffer
->_DepthMaxF
;
702 const GLuint stencilMask
= ctx
->Stencil
.WriteMask
[0];
703 const GLuint stencilType
= (STENCIL_BITS
== 8) ?
704 GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
705 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!= 1.0 || ctx
->Pixel
.ZoomY
!= 1.0;
706 struct gl_renderbuffer
*depthRb
, *stencilRb
;
707 struct gl_pixelstore_attrib clippedUnpack
= *unpack
;
710 if (!_mesa_clip_drawpixels(ctx
, &x
, &y
, &width
, &height
,
712 /* totally clipped */
717 depthRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
718 stencilRb
= ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
722 if (depthRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
723 stencilRb
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
&&
724 depthRb
== stencilRb
&&
728 (stencilMask
& 0xff) == 0xff) {
729 /* This is the ideal case.
730 * Drawing GL_DEPTH_STENCIL pixels into a combined depth/stencil buffer.
731 * Plus, no pixel transfer ops, zooming, or masking needed.
734 for (i
= 0; i
< height
; i
++) {
735 const GLuint
*src
= (const GLuint
*)
736 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
737 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
738 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, src
, NULL
);
742 /* sub-optimal cases:
743 * Separate depth/stencil buffers, or pixel transfer ops required.
745 /* XXX need to handle very wide images (skippixels) */
748 depthRb
= ctx
->DrawBuffer
->_DepthBuffer
;
749 stencilRb
= ctx
->DrawBuffer
->_StencilBuffer
;
751 for (i
= 0; i
< height
; i
++) {
752 const GLuint
*depthStencilSrc
= (const GLuint
*)
753 _mesa_image_address2d(&clippedUnpack
, pixels
, width
, height
,
754 GL_DEPTH_STENCIL_EXT
, type
, i
, 0);
756 if (ctx
->Depth
.Mask
) {
757 if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 24) {
758 /* fast path 24-bit zbuffer */
759 GLuint zValues
[MAX_WIDTH
];
761 ASSERT(depthRb
->DataType
== GL_UNSIGNED_INT
);
762 for (j
= 0; j
< width
; j
++) {
763 zValues
[j
] = depthStencilSrc
[j
] >> 8;
766 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
769 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
771 else if (!scaleOrBias
&& ctx
->DrawBuffer
->Visual
.depthBits
== 16) {
772 /* fast path 16-bit zbuffer */
773 GLushort zValues
[MAX_WIDTH
];
775 ASSERT(depthRb
->DataType
== GL_UNSIGNED_SHORT
);
776 for (j
= 0; j
< width
; j
++) {
777 zValues
[j
] = depthStencilSrc
[j
] >> 16;
780 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
,
783 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
787 GLuint zValues
[MAX_WIDTH
]; /* 16 or 32-bit Z value storage */
788 _mesa_unpack_depth_span(ctx
, width
,
789 depthRb
->DataType
, zValues
, depthScale
,
790 type
, depthStencilSrc
, &clippedUnpack
);
792 _swrast_write_zoomed_z_span(ctx
, imgX
, imgY
, width
, x
,
796 depthRb
->PutRow(ctx
, depthRb
, width
, x
, y
+ i
, zValues
,NULL
);
801 if (stencilMask
!= 0x0) {
802 GLstencil stencilValues
[MAX_WIDTH
];
803 /* get stencil values, with shift/offset/mapping */
804 _mesa_unpack_stencil_span(ctx
, width
, stencilType
, stencilValues
,
805 type
, depthStencilSrc
, &clippedUnpack
,
806 ctx
->_ImageTransferState
);
808 _swrast_write_zoomed_stencil_span(ctx
, imgX
, imgY
, width
,
809 x
, y
+ i
, stencilValues
);
811 _swrast_write_stencil_span(ctx
, width
, x
, y
+ i
, stencilValues
);
820 * Execute software-based glDrawPixels.
821 * By time we get here, all error checking will have been done.
824 _swrast_DrawPixels( GLcontext
*ctx
,
826 GLsizei width
, GLsizei height
,
827 GLenum format
, GLenum type
,
828 const struct gl_pixelstore_attrib
*unpack
,
829 const GLvoid
*pixels
)
831 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
833 RENDER_START(swrast
,ctx
);
836 _mesa_update_state(ctx
);
838 if (swrast
->NewState
)
839 _swrast_validate_derived( ctx
);
841 if (unpack
->BufferObj
->Name
) {
842 /* unpack from PBO */
844 if (!_mesa_validate_pbo_access(2, unpack
, width
, height
, 1,
845 format
, type
, pixels
)) {
846 _mesa_error(ctx
, GL_INVALID_OPERATION
,
847 "glDrawPixels(invalid PBO access)");
850 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
854 /* buffer is already mapped - that's an error */
855 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glDrawPixels(PBO is mapped)");
858 pixels
= ADD_POINTERS(buf
, pixels
);
862 case GL_STENCIL_INDEX
:
863 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
865 case GL_DEPTH_COMPONENT
:
866 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
869 if (ctx
->Visual
.rgbMode
)
870 draw_rgba_pixels(ctx
, x
,y
, width
, height
, format
, type
, unpack
, pixels
);
872 draw_index_pixels(ctx
, x
, y
, width
, height
, type
, unpack
, pixels
);
879 case GL_LUMINANCE_ALPHA
:
885 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, unpack
, pixels
);
887 case GL_DEPTH_STENCIL_EXT
:
888 draw_depth_stencil_pixels(ctx
, x
, y
, width
, height
,
889 type
, unpack
, pixels
);
892 _mesa_problem(ctx
, "unexpected format in _swrast_DrawPixels");
893 /* don't return yet, clean-up */
898 RENDER_FINISH(swrast
,ctx
);
900 if (unpack
->BufferObj
->Name
) {
901 /* done with PBO so unmap it now */
902 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
909 #if 0 /* experimental */
911 * Execute glDrawDepthPixelsMESA().
914 _swrast_DrawDepthPixelsMESA( GLcontext
*ctx
,
916 GLsizei width
, GLsizei height
,
917 GLenum colorFormat
, GLenum colorType
,
918 const GLvoid
*colors
,
919 GLenum depthType
, const GLvoid
*depths
,
920 const struct gl_pixelstore_attrib
*unpack
)
922 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
924 if (swrast
->NewState
)
925 _swrast_validate_derived( ctx
);
927 RENDER_START(swrast
,ctx
);
929 switch (colorFormat
) {
931 if (ctx
->Visual
.rgbMode
)
932 draw_rgba_pixels(ctx
, x
,y
, width
, height
, colorFormat
, colorType
,
935 draw_index_pixels(ctx
, x
, y
, width
, height
, colorType
,
943 case GL_LUMINANCE_ALPHA
:
949 draw_rgba_pixels(ctx
, x
, y
, width
, height
, colorFormat
, colorType
,
953 _mesa_problem(ctx
, "unexpected format in glDrawDepthPixelsMESA");
956 RENDER_FINISH(swrast
,ctx
);