1 /* $Id: s_drawpix.c,v 1.1 2000/10/31 18:00:04 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #include "s_pixeltex.h"
40 #include "s_stencil.h"
41 #include "s_texture.h"
47 * Given the dest position, size and skipPixels and skipRows values
48 * for a glDrawPixels command, perform clipping of the image bounds
49 * so the result lies withing the context's buffer bounds.
50 * Return: GL_TRUE if image is ready for drawing
51 * GL_FALSE if image was completely clipped away (draw nothing)
54 _mesa_clip_pixelrect(const GLcontext
*ctx
,
55 GLint
*destX
, GLint
*destY
,
56 GLsizei
*width
, GLsizei
*height
,
57 GLint
*skipPixels
, GLint
*skipRows
)
59 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
62 if (*destX
< buffer
->Xmin
) {
63 *skipPixels
+= (buffer
->Xmin
- *destX
);
64 *width
-= (buffer
->Xmin
- *destX
);
65 *destX
= buffer
->Xmin
;
68 if (*destX
+ *width
> buffer
->Xmax
)
69 *width
-= (*destX
+ *width
- buffer
->Xmax
);
75 if (*destY
< buffer
->Ymin
) {
76 *skipRows
+= (buffer
->Ymin
- *destY
);
77 *height
-= (buffer
->Ymin
- *destY
);
78 *destY
= buffer
->Ymin
;
81 if (*destY
+ *height
> buffer
->Ymax
)
82 *height
-= (*destY
+ *height
- buffer
->Ymax
);
93 * Try to do a fast and simple RGB(a) glDrawPixels.
94 * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
97 fast_draw_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
98 GLsizei width
, GLsizei height
,
99 GLenum format
, GLenum type
, const GLvoid
*pixels
)
101 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
102 GLchan rgb
[MAX_WIDTH
][3];
103 GLchan rgba
[MAX_WIDTH
][4];
105 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx
, "glDrawPixels",
109 if (!ctx
->Current
.RasterPosValid
) {
110 return GL_TRUE
; /* no-op */
113 if ((ctx
->RasterMask
&(~(SCISSOR_BIT
|WINCLIP_BIT
)))==0
114 && ctx
->Texture
.ReallyEnabled
== 0
115 && unpack
->Alignment
== 1
116 && !unpack
->SwapBytes
117 && !unpack
->LsbFirst
) {
121 GLint drawWidth
= width
; /* actual width drawn */
122 GLint drawHeight
= height
; /* actual height drawn */
123 GLint skipPixels
= unpack
->SkipPixels
;
124 GLint skipRows
= unpack
->SkipRows
;
126 GLdepth zSpan
[MAX_WIDTH
]; /* only used when zooming */
129 if (unpack
->RowLength
> 0)
130 rowLength
= unpack
->RowLength
;
134 /* If we're not using pixel zoom then do all clipping calculations
135 * now. Otherwise, we'll let the gl_write_zoomed_*_span() functions
136 * handle the clipping.
138 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
139 /* horizontal clipping */
140 if (destX
< ctx
->DrawBuffer
->Xmin
) {
141 skipPixels
+= (ctx
->DrawBuffer
->Xmin
- destX
);
142 drawWidth
-= (ctx
->DrawBuffer
->Xmin
- destX
);
143 destX
= ctx
->DrawBuffer
->Xmin
;
145 if (destX
+ drawWidth
> ctx
->DrawBuffer
->Xmax
)
146 drawWidth
-= (destX
+ drawWidth
- ctx
->DrawBuffer
->Xmax
);
150 /* vertical clipping */
151 if (destY
< ctx
->DrawBuffer
->Ymin
) {
152 skipRows
+= (ctx
->DrawBuffer
->Ymin
- destY
);
153 drawHeight
-= (ctx
->DrawBuffer
->Ymin
- destY
);
154 destY
= ctx
->DrawBuffer
->Ymin
;
156 if (destY
+ drawHeight
> ctx
->DrawBuffer
->Ymax
)
157 drawHeight
-= (destY
+ drawHeight
- ctx
->DrawBuffer
->Ymax
);
161 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
162 /* upside-down image */
163 /* horizontal clipping */
164 if (destX
< ctx
->DrawBuffer
->Xmin
) {
165 skipPixels
+= (ctx
->DrawBuffer
->Xmin
- destX
);
166 drawWidth
-= (ctx
->DrawBuffer
->Xmin
- destX
);
167 destX
= ctx
->DrawBuffer
->Xmin
;
169 if (destX
+ drawWidth
> ctx
->DrawBuffer
->Xmax
)
170 drawWidth
-= (destX
+ drawWidth
- ctx
->DrawBuffer
->Xmax
);
174 /* vertical clipping */
175 if (destY
> ctx
->DrawBuffer
->Ymax
) {
176 skipRows
+= (destY
- ctx
->DrawBuffer
->Ymax
);
177 drawHeight
-= (destY
- ctx
->DrawBuffer
->Ymax
);
178 destY
= ctx
->DrawBuffer
->Ymax
;
180 if (destY
- drawHeight
< ctx
->DrawBuffer
->Ymin
)
181 drawHeight
-= (ctx
->DrawBuffer
->Ymin
- (destY
- drawHeight
));
186 /* setup array of fragment Z value to pass to zoom function */
187 GLdepth z
= (GLdepth
) (ctx
->Current
.RasterPos
[2] * ctx
->Visual
.DepthMaxF
);
189 ASSERT(drawWidth
< MAX_WIDTH
);
190 for (i
=0; i
<drawWidth
; i
++)
193 /* save Y value of first row */
194 zoomY0
= (GLint
) (ctx
->Current
.RasterPos
[1] + 0.5F
);
200 * The window region at (destX, destY) of size (drawWidth, drawHeight)
201 * will be written to.
202 * We'll take pixel data from buffer pointed to by "pixels" but we'll
203 * skip "skipRows" rows and skip "skipPixels" pixels/row.
206 if (format
== GL_RGBA
&& type
== CHAN_TYPE
207 && ctx
->ImageTransferState
==0) {
208 if (ctx
->Visual
.RGBAflag
) {
209 GLchan
*src
= (GLchan
*) pixels
210 + (skipRows
* rowLength
+ skipPixels
) * 4;
211 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
214 for (row
=0; row
<drawHeight
; row
++) {
215 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
217 src
+= rowLength
* 4;
221 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
224 for (row
=0; row
<drawHeight
; row
++) {
226 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
228 src
+= rowLength
* 4;
234 for (row
=0; row
<drawHeight
; row
++) {
235 gl_write_zoomed_rgba_span(ctx
, drawWidth
, destX
, destY
,
236 zSpan
, 0, (void *) src
, zoomY0
);
237 src
+= rowLength
* 4;
244 else if (format
== GL_RGB
&& type
== CHAN_TYPE
245 && ctx
->ImageTransferState
== 0) {
246 if (ctx
->Visual
.RGBAflag
) {
247 GLchan
*src
= (GLchan
*) pixels
248 + (skipRows
* rowLength
+ skipPixels
) * 3;
249 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
251 for (row
=0; row
<drawHeight
; row
++) {
252 (*ctx
->Driver
.WriteRGBSpan
)(ctx
, drawWidth
, destX
, destY
,
254 src
+= rowLength
* 3;
258 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
261 for (row
=0; row
<drawHeight
; row
++) {
263 (*ctx
->Driver
.WriteRGBSpan
)(ctx
, drawWidth
, destX
, destY
,
265 src
+= rowLength
* 3;
271 for (row
=0; row
<drawHeight
; row
++) {
272 gl_write_zoomed_rgb_span(ctx
, drawWidth
, destX
, destY
,
273 zSpan
, 0, (void *) src
, zoomY0
);
274 src
+= rowLength
* 3;
281 else if (format
== GL_LUMINANCE
&& type
== CHAN_TYPE
282 && ctx
->ImageTransferState
==0) {
283 if (ctx
->Visual
.RGBAflag
) {
284 GLchan
*src
= (GLchan
*) pixels
285 + (skipRows
* rowLength
+ skipPixels
);
286 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
289 ASSERT(drawWidth
< MAX_WIDTH
);
290 for (row
=0; row
<drawHeight
; row
++) {
292 for (i
=0;i
<drawWidth
;i
++) {
297 (*ctx
->Driver
.WriteRGBSpan
)(ctx
, drawWidth
, destX
, destY
,
303 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
306 ASSERT(drawWidth
< MAX_WIDTH
);
307 for (row
=0; row
<drawHeight
; row
++) {
309 for (i
=0;i
<drawWidth
;i
++) {
315 (*ctx
->Driver
.WriteRGBSpan
)(ctx
, drawWidth
, destX
, destY
,
323 ASSERT(drawWidth
< MAX_WIDTH
);
324 for (row
=0; row
<drawHeight
; row
++) {
326 for (i
=0;i
<drawWidth
;i
++) {
331 gl_write_zoomed_rgb_span(ctx
, drawWidth
, destX
, destY
,
332 zSpan
, 0, (void *) rgb
, zoomY0
);
340 else if (format
== GL_LUMINANCE_ALPHA
&& type
== CHAN_TYPE
341 && ctx
->ImageTransferState
== 0) {
342 if (ctx
->Visual
.RGBAflag
) {
343 GLchan
*src
= (GLchan
*) pixels
344 + (skipRows
* rowLength
+ skipPixels
)*2;
345 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
348 ASSERT(drawWidth
< MAX_WIDTH
);
349 for (row
=0; row
<drawHeight
; row
++) {
352 for (i
=0;i
<drawWidth
;i
++) {
358 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
359 (void *) rgba
, NULL
);
364 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
367 ASSERT(drawWidth
< MAX_WIDTH
);
368 for (row
=0; row
<drawHeight
; row
++) {
371 for (i
=0;i
<drawWidth
;i
++) {
378 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
379 (void *) rgba
, NULL
);
386 ASSERT(drawWidth
< MAX_WIDTH
);
387 for (row
=0; row
<drawHeight
; row
++) {
390 for (i
=0;i
<drawWidth
;i
++) {
396 gl_write_zoomed_rgba_span(ctx
, drawWidth
, destX
, destY
,
397 zSpan
, 0, (void *) rgba
, zoomY0
);
405 else if (format
==GL_COLOR_INDEX
&& type
==GL_UNSIGNED_BYTE
) {
406 GLubyte
*src
= (GLubyte
*) pixels
+ skipRows
* rowLength
+ skipPixels
;
407 if (ctx
->Visual
.RGBAflag
) {
408 /* convert CI data to RGBA */
409 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
412 for (row
=0; row
<drawHeight
; row
++) {
413 ASSERT(drawWidth
< MAX_WIDTH
);
414 _mesa_map_ci8_to_rgba(ctx
, drawWidth
, src
, rgba
);
415 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
416 (const GLchan (*)[4]) rgba
,
423 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
426 for (row
=0; row
<drawHeight
; row
++) {
427 ASSERT(drawWidth
< MAX_WIDTH
);
428 _mesa_map_ci8_to_rgba(ctx
, drawWidth
, src
, rgba
);
430 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
431 (const GLchan (*)[4]) rgba
,
440 for (row
=0; row
<drawHeight
; row
++) {
441 ASSERT(drawWidth
< MAX_WIDTH
);
442 _mesa_map_ci8_to_rgba(ctx
, drawWidth
, src
, rgba
);
443 gl_write_zoomed_rgba_span(ctx
, drawWidth
, destX
, destY
,
444 zSpan
, 0, (void *) rgba
, zoomY0
);
451 else if (ctx
->ImageTransferState
==0) {
452 /* write CI data to CI frame buffer */
454 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
456 for (row
=0; row
<drawHeight
; row
++) {
457 (*ctx
->Driver
.WriteCI8Span
)(ctx
, drawWidth
, destX
, destY
,
471 /* can't handle this pixel format and/or data type here */
476 /* can't do a simple draw, have to use slow path */
483 * Do glDrawPixels of index pixels.
486 draw_index_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
487 GLsizei width
, GLsizei height
,
488 GLenum type
, const GLvoid
*pixels
)
490 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
491 const GLint desty
= y
;
492 GLint row
, drawWidth
;
493 GLdepth zspan
[MAX_WIDTH
];
495 drawWidth
= (width
> MAX_WIDTH
) ? MAX_WIDTH
: width
;
497 /* Fragment depth values */
498 if (ctx
->Depth
.Test
|| ctx
->Fog
.Enabled
) {
499 GLdepth zval
= (GLdepth
) (ctx
->Current
.RasterPos
[2] * ctx
->Visual
.DepthMaxF
);
501 for (i
= 0; i
< drawWidth
; i
++) {
509 for (row
= 0; row
< height
; row
++, y
++) {
510 GLuint indexes
[MAX_WIDTH
];
511 const GLvoid
*source
= _mesa_image_address(&ctx
->Unpack
,
512 pixels
, width
, height
, GL_COLOR_INDEX
, type
, 0, row
, 0);
513 _mesa_unpack_index_span(ctx
, drawWidth
, GL_UNSIGNED_INT
, indexes
,
514 type
, source
, &ctx
->Unpack
,
515 ctx
->ImageTransferState
);
517 gl_write_zoomed_index_span(ctx
, drawWidth
, x
, y
, zspan
, 0, indexes
, desty
);
520 gl_write_index_span(ctx
, drawWidth
, x
, y
, zspan
, 0, indexes
, GL_BITMAP
);
528 * Do glDrawPixels of stencil image. The image datatype may either
529 * be GLubyte or GLbitmap.
532 draw_stencil_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
533 GLsizei width
, GLsizei height
,
534 GLenum type
, const GLvoid
*pixels
)
536 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
537 const GLint desty
= y
;
538 GLint row
, drawWidth
;
540 if (type
!= GL_BYTE
&&
541 type
!= GL_UNSIGNED_BYTE
&&
543 type
!= GL_UNSIGNED_SHORT
&&
545 type
!= GL_UNSIGNED_INT
&&
548 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawPixels(stencil type)");
552 drawWidth
= (width
> MAX_WIDTH
) ? MAX_WIDTH
: width
;
554 for (row
= 0; row
< height
; row
++, y
++) {
555 GLstencil values
[MAX_WIDTH
];
556 GLenum destType
= (sizeof(GLstencil
) == sizeof(GLubyte
))
557 ? GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
558 const GLvoid
*source
= _mesa_image_address(&ctx
->Unpack
,
559 pixels
, width
, height
, GL_COLOR_INDEX
, type
, 0, row
, 0);
560 _mesa_unpack_index_span(ctx
, drawWidth
, destType
, values
,
561 type
, source
, &ctx
->Unpack
,
562 ctx
->ImageTransferState
);
563 if (ctx
->ImageTransferState
& IMAGE_SHIFT_OFFSET_BIT
) {
564 _mesa_shift_and_offset_stencil( ctx
, drawWidth
, values
);
566 if (ctx
->Pixel
.MapStencilFlag
) {
567 _mesa_map_stencil( ctx
, drawWidth
, values
);
571 gl_write_zoomed_stencil_span( ctx
, (GLuint
) drawWidth
, x
, y
,
575 _mesa_write_stencil_span( ctx
, (GLuint
) drawWidth
, x
, y
, values
);
583 * Do a glDrawPixels of depth values.
586 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
587 GLsizei width
, GLsizei height
,
588 GLenum type
, const GLvoid
*pixels
)
590 const GLboolean bias_or_scale
= ctx
->Pixel
.DepthBias
!=0.0 || ctx
->Pixel
.DepthScale
!=1.0;
591 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
592 const GLint desty
= y
;
593 GLchan rgba
[MAX_WIDTH
][4];
594 GLuint ispan
[MAX_WIDTH
];
595 GLint drawWidth
= (width
> MAX_WIDTH
) ? MAX_WIDTH
: width
;
598 && type
!= GL_UNSIGNED_BYTE
600 && type
!= GL_UNSIGNED_SHORT
602 && type
!= GL_UNSIGNED_INT
603 && type
!= GL_FLOAT
) {
604 gl_error(ctx
, GL_INVALID_ENUM
, "glDrawPixels(type)");
608 /* Colors or indexes */
609 if (ctx
->Visual
.RGBAflag
) {
610 GLint r
= FLOAT_TO_CHAN(ctx
->Current
.RasterColor
[0]);
611 GLint g
= FLOAT_TO_CHAN(ctx
->Current
.RasterColor
[1]);
612 GLint b
= FLOAT_TO_CHAN(ctx
->Current
.RasterColor
[2]);
613 GLint a
= FLOAT_TO_CHAN(ctx
->Current
.RasterColor
[3]);
615 for (i
= 0; i
< drawWidth
; i
++) {
624 for (i
= 0; i
< drawWidth
; i
++) {
625 ispan
[i
] = ctx
->Current
.RasterIndex
;
629 if (type
==GL_UNSIGNED_SHORT
&& sizeof(GLdepth
)==sizeof(GLushort
)
630 && !bias_or_scale
&& !zoom
&& ctx
->Visual
.RGBAflag
) {
631 /* Special case: directly write 16-bit depth values */
633 for (row
= 0; row
< height
; row
++, y
++) {
634 GLdepth zspan
[MAX_WIDTH
];
635 const GLushort
*zptr
= _mesa_image_address(&ctx
->Unpack
,
636 pixels
, width
, height
, GL_DEPTH_COMPONENT
, type
, 0, row
, 0);
638 for (i
= 0; i
< width
; i
++)
640 gl_write_rgba_span( ctx
, width
, x
, y
, zspan
, 0, rgba
, GL_BITMAP
);
643 else if (type
==GL_UNSIGNED_INT
&& ctx
->Visual
.DepthBits
== 32
644 && !bias_or_scale
&& !zoom
&& ctx
->Visual
.RGBAflag
) {
645 /* Special case: directly write 32-bit depth values */
647 for (row
= 0; row
< height
; row
++, y
++) {
648 const GLuint
*zptr
= _mesa_image_address(&ctx
->Unpack
,
649 pixels
, width
, height
, GL_DEPTH_COMPONENT
, type
, 0, row
, 0);
650 gl_write_rgba_span( ctx
, width
, x
, y
, zptr
, 0, rgba
, GL_BITMAP
);
656 for (row
= 0; row
< height
; row
++, y
++) {
657 GLdepth zspan
[MAX_WIDTH
];
658 const GLvoid
*src
= _mesa_image_address(&ctx
->Unpack
,
659 pixels
, width
, height
, GL_DEPTH_COMPONENT
, type
, 0, row
, 0);
660 _mesa_unpack_depth_span( ctx
, drawWidth
, zspan
, type
, src
,
661 &ctx
->Unpack
, ctx
->ImageTransferState
);
662 if (ctx
->Visual
.RGBAflag
) {
664 gl_write_zoomed_rgba_span(ctx
, width
, x
, y
, zspan
, 0,
665 (const GLchan (*)[4]) rgba
, desty
);
668 gl_write_rgba_span(ctx
, width
, x
, y
, zspan
, 0, rgba
, GL_BITMAP
);
673 gl_write_zoomed_index_span(ctx
, width
, x
, y
, zspan
, 0,
677 gl_write_index_span(ctx
, width
, x
, y
, zspan
, 0,
688 * Do glDrawPixels of RGBA pixels.
691 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
692 GLsizei width
, GLsizei height
,
693 GLenum format
, GLenum type
, const GLvoid
*pixels
)
695 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
696 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
697 const GLint desty
= y
;
698 GLdepth zspan
[MAX_WIDTH
];
700 GLfloat
*convImage
= NULL
;
701 GLuint transferOps
= ctx
->ImageTransferState
;
703 if (!_mesa_is_legal_format_and_type(format
, type
)) {
704 gl_error(ctx
, GL_INVALID_ENUM
, "glDrawPixels(format or type)");
708 /* Try an optimized glDrawPixels first */
709 if (fast_draw_pixels(ctx
, x
, y
, width
, height
, format
, type
, pixels
))
712 /* Fragment depth values */
713 if (ctx
->Depth
.Test
|| ctx
->Fog
.Enabled
) {
714 /* fill in array of z values */
715 GLdepth z
= (GLdepth
) (ctx
->Current
.RasterPos
[2] * ctx
->Visual
.DepthMaxF
);
717 for (i
=0;i
<width
;i
++) {
723 if (ctx
->RasterMask
== 0 && !zoom
&& x
>= 0 && y
>= 0
724 && x
+ width
<= ctx
->DrawBuffer
->Width
725 && y
+ height
<= ctx
->DrawBuffer
->Height
) {
729 quickDraw
= GL_FALSE
;
732 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
733 /* Convolution has to be handled specially. We'll create an
734 * intermediate image, applying all pixel transfer operations
735 * up to convolution. Then we'll convolve the image. Then
736 * we'll proceed with the rest of the transfer operations and
737 * rasterize the image.
740 GLfloat
*dest
, *tmpImage
;
742 tmpImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
744 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
747 convImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
750 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
754 /* Unpack the image and apply transfer ops up to convolution */
756 for (row
= 0; row
< height
; row
++) {
757 const GLvoid
*source
= _mesa_image_address(unpack
,
758 pixels
, width
, height
, format
, type
, 0, row
, 0);
759 _mesa_unpack_float_color_span(ctx
, width
, GL_RGBA
, (void *) dest
,
760 format
, type
, source
, unpack
,
761 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
,
767 if (ctx
->Pixel
.Convolution2DEnabled
) {
768 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
771 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
772 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
776 /* continue transfer ops and draw the convolved image */
777 unpack
= &_mesa_native_packing
;
781 transferOps
&= IMAGE_POST_CONVOLUTION_BITS
;
788 GLchan rgba
[MAX_WIDTH
][4];
790 if (width
> MAX_WIDTH
)
792 for (row
= 0; row
< height
; row
++, y
++) {
793 const GLvoid
*source
= _mesa_image_address(unpack
,
794 pixels
, width
, height
, format
, type
, 0, row
, 0);
795 _mesa_unpack_chan_color_span(ctx
, width
, GL_RGBA
, (void*) rgba
,
796 format
, type
, source
, unpack
,
798 if ((ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
) ||
799 (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
))
802 if (ctx
->Texture
.ReallyEnabled
&& ctx
->Pixel
.PixelTextureEnabled
) {
803 GLfloat s
[MAX_WIDTH
], t
[MAX_WIDTH
], r
[MAX_WIDTH
], q
[MAX_WIDTH
];
804 GLchan primary_rgba
[MAX_WIDTH
][4];
806 /* XXX not sure how multitexture is supposed to work here */
808 MEMCPY(primary_rgba
, rgba
, 4 * width
* sizeof(GLchan
));
810 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
811 if (ctx
->Texture
.Unit
[unit
].ReallyEnabled
) {
812 _mesa_pixeltexgen(ctx
, width
, (const GLchan (*)[4]) rgba
,
814 gl_texture_pixels(ctx
, unit
, width
, s
, t
, r
, NULL
,
821 (*ctx
->Driver
.WriteRGBASpan
)( ctx
, width
, x
, y
,
822 (CONST
GLchan (*)[]) rgba
, NULL
);
825 gl_write_zoomed_rgba_span( ctx
, width
, x
, y
, zspan
, 0,
826 (CONST
GLchan (*)[]) rgba
, desty
);
829 gl_write_rgba_span( ctx
, (GLuint
) width
, x
, y
, zspan
, 0,
843 * Execute glDrawPixels
846 _swrast_DrawPixels( GLcontext
*ctx
,
848 GLsizei width
, GLsizei height
,
849 GLenum format
, GLenum type
,
850 const struct gl_pixelstore_attrib
*unpack
,
851 const GLvoid
*pixels
)
856 case GL_STENCIL_INDEX
:
857 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, pixels
);
859 case GL_DEPTH_COMPONENT
:
860 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, pixels
);
863 if (ctx
->Visual
.RGBAflag
)
864 draw_rgba_pixels(ctx
, x
,y
, width
, height
, format
, type
, pixels
);
866 draw_index_pixels(ctx
, x
, y
, width
, height
, type
, pixels
);
873 case GL_LUMINANCE_ALPHA
:
879 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, pixels
);
882 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawPixels(format)" );