1 /* $Id: drawpix.c,v 1.34 2000/09/12 21:09:24 brianp 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.
53 * Given the dest position, size and skipPixels and skipRows values
54 * for a glDrawPixels command, perform clipping of the image bounds
55 * so the result lies withing the context's buffer bounds.
56 * Return: GL_TRUE if image is ready for drawing
57 * GL_FALSE if image was completely clipped away (draw nothing)
60 _mesa_clip_pixelrect(const GLcontext
*ctx
,
61 GLint
*destX
, GLint
*destY
,
62 GLsizei
*width
, GLsizei
*height
,
63 GLint
*skipPixels
, GLint
*skipRows
)
65 const GLframebuffer
*buffer
= ctx
->DrawBuffer
;
68 if (*destX
< buffer
->Xmin
) {
69 *skipPixels
+= (buffer
->Xmin
- *destX
);
70 *width
-= (buffer
->Xmin
- *destX
);
71 *destX
= buffer
->Xmin
;
74 if (*destX
+ *width
> buffer
->Xmax
)
75 *width
-= (*destX
+ *width
- buffer
->Xmax
);
81 if (*destY
< buffer
->Ymin
) {
82 *skipRows
+= (buffer
->Ymin
- *destY
);
83 *height
-= (buffer
->Ymin
- *destY
);
84 *destY
= buffer
->Ymin
;
87 if (*destY
+ *height
> buffer
->Ymax
)
88 *height
-= (*destY
+ *height
- buffer
->Ymax
);
99 * Try to do a fast and simple RGB(a) glDrawPixels.
100 * Return: GL_TRUE if success, GL_FALSE if slow path must be used instead
103 fast_draw_pixels(GLcontext
*ctx
, GLint x
, GLint y
,
104 GLsizei width
, GLsizei height
,
105 GLenum format
, GLenum type
, const GLvoid
*pixels
)
107 const GLuint cantTransferBits
=
108 IMAGE_SCALE_BIAS_BIT
|
109 IMAGE_SHIFT_OFFSET_BIT
|
110 IMAGE_MAP_COLOR_BIT
|
111 IMAGE_COLOR_TABLE_BIT
|
112 IMAGE_CONVOLUTION_BIT
|
113 IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
|
114 IMAGE_COLOR_MATRIX_BIT
|
115 IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
|
116 IMAGE_HISTOGRAM_BIT
|
118 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
119 GLubyte rgb
[MAX_WIDTH
][3];
120 GLubyte rgba
[MAX_WIDTH
][4];
122 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx
, "glDrawPixels",
126 if (!ctx
->Current
.RasterPosValid
) {
127 return GL_TRUE
; /* no-op */
130 if ((ctx
->RasterMask
&(~(SCISSOR_BIT
|WINCLIP_BIT
)))==0
131 && (ctx
->ImageTransferState
& cantTransferBits
) == 0
132 && ctx
->Texture
.ReallyEnabled
== 0
133 && unpack
->Alignment
== 1
134 && !unpack
->SwapBytes
135 && !unpack
->LsbFirst
) {
139 GLint drawWidth
= width
; /* actual width drawn */
140 GLint drawHeight
= height
; /* actual height drawn */
141 GLint skipPixels
= unpack
->SkipPixels
;
142 GLint skipRows
= unpack
->SkipRows
;
144 GLdepth zSpan
[MAX_WIDTH
]; /* only used when zooming */
147 if (unpack
->RowLength
> 0)
148 rowLength
= unpack
->RowLength
;
152 /* If we're not using pixel zoom then do all clipping calculations
153 * now. Otherwise, we'll let the gl_write_zoomed_*_span() functions
154 * handle the clipping.
156 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
157 /* horizontal clipping */
158 if (destX
< ctx
->DrawBuffer
->Xmin
) {
159 skipPixels
+= (ctx
->DrawBuffer
->Xmin
- destX
);
160 drawWidth
-= (ctx
->DrawBuffer
->Xmin
- destX
);
161 destX
= ctx
->DrawBuffer
->Xmin
;
163 if (destX
+ drawWidth
> ctx
->DrawBuffer
->Xmax
)
164 drawWidth
-= (destX
+ drawWidth
- ctx
->DrawBuffer
->Xmax
);
168 /* vertical clipping */
169 if (destY
< ctx
->DrawBuffer
->Ymin
) {
170 skipRows
+= (ctx
->DrawBuffer
->Ymin
- destY
);
171 drawHeight
-= (ctx
->DrawBuffer
->Ymin
- destY
);
172 destY
= ctx
->DrawBuffer
->Ymin
;
174 if (destY
+ drawHeight
> ctx
->DrawBuffer
->Ymax
)
175 drawHeight
-= (destY
+ drawHeight
- ctx
->DrawBuffer
->Ymax
);
179 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
180 /* upside-down image */
181 /* horizontal clipping */
182 if (destX
< ctx
->DrawBuffer
->Xmin
) {
183 skipPixels
+= (ctx
->DrawBuffer
->Xmin
- destX
);
184 drawWidth
-= (ctx
->DrawBuffer
->Xmin
- destX
);
185 destX
= ctx
->DrawBuffer
->Xmin
;
187 if (destX
+ drawWidth
> ctx
->DrawBuffer
->Xmax
)
188 drawWidth
-= (destX
+ drawWidth
- ctx
->DrawBuffer
->Xmax
);
192 /* vertical clipping */
193 if (destY
> ctx
->DrawBuffer
->Ymax
) {
194 skipRows
+= (destY
- ctx
->DrawBuffer
->Ymax
);
195 drawHeight
-= (destY
- ctx
->DrawBuffer
->Ymax
);
196 destY
= ctx
->DrawBuffer
->Ymax
;
198 if (destY
- drawHeight
< ctx
->DrawBuffer
->Ymin
)
199 drawHeight
-= (ctx
->DrawBuffer
->Ymin
- (destY
- drawHeight
));
204 /* setup array of fragment Z value to pass to zoom function */
205 GLdepth z
= (GLdepth
) (ctx
->Current
.RasterPos
[2] * ctx
->Visual
->DepthMaxF
);
207 ASSERT(drawWidth
< MAX_WIDTH
);
208 for (i
=0; i
<drawWidth
; i
++)
211 /* save Y value of first row */
212 zoomY0
= (GLint
) (ctx
->Current
.RasterPos
[1] + 0.5F
);
218 * The window region at (destX, destY) of size (drawWidth, drawHeight)
219 * will be written to.
220 * We'll take pixel data from buffer pointed to by "pixels" but we'll
221 * skip "skipRows" rows and skip "skipPixels" pixels/row.
224 if (format
==GL_RGBA
&& type
==GL_UNSIGNED_BYTE
) {
225 if (ctx
->Visual
->RGBAflag
) {
226 GLubyte
*src
= (GLubyte
*) pixels
227 + (skipRows
* rowLength
+ skipPixels
) * 4;
228 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
231 for (row
=0; row
<drawHeight
; row
++) {
232 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
234 src
+= rowLength
* 4;
238 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
241 for (row
=0; row
<drawHeight
; row
++) {
243 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
245 src
+= rowLength
* 4;
251 for (row
=0; row
<drawHeight
; row
++) {
252 gl_write_zoomed_rgba_span(ctx
, drawWidth
, destX
, destY
,
253 zSpan
, (void *) src
, zoomY0
);
254 src
+= rowLength
* 4;
261 else if (format
==GL_RGB
&& type
==GL_UNSIGNED_BYTE
) {
262 if (ctx
->Visual
->RGBAflag
) {
263 GLubyte
*src
= (GLubyte
*) pixels
264 + (skipRows
* rowLength
+ skipPixels
) * 3;
265 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
267 for (row
=0; row
<drawHeight
; row
++) {
268 (*ctx
->Driver
.WriteRGBSpan
)(ctx
, drawWidth
, destX
, destY
,
270 src
+= rowLength
* 3;
274 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
277 for (row
=0; row
<drawHeight
; row
++) {
279 (*ctx
->Driver
.WriteRGBSpan
)(ctx
, drawWidth
, destX
, destY
,
281 src
+= rowLength
* 3;
287 for (row
=0; row
<drawHeight
; row
++) {
288 gl_write_zoomed_rgb_span(ctx
, drawWidth
, destX
, destY
,
289 zSpan
, (void *) src
, zoomY0
);
290 src
+= rowLength
* 3;
297 else if (format
==GL_LUMINANCE
&& type
==GL_UNSIGNED_BYTE
) {
298 if (ctx
->Visual
->RGBAflag
) {
299 GLubyte
*src
= (GLubyte
*) pixels
300 + (skipRows
* rowLength
+ skipPixels
);
301 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
304 ASSERT(drawWidth
< MAX_WIDTH
);
305 for (row
=0; row
<drawHeight
; row
++) {
307 for (i
=0;i
<drawWidth
;i
++) {
312 (*ctx
->Driver
.WriteRGBSpan
)(ctx
, drawWidth
, destX
, destY
,
318 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
321 ASSERT(drawWidth
< MAX_WIDTH
);
322 for (row
=0; row
<drawHeight
; row
++) {
324 for (i
=0;i
<drawWidth
;i
++) {
330 (*ctx
->Driver
.WriteRGBSpan
)(ctx
, drawWidth
, destX
, destY
,
338 ASSERT(drawWidth
< MAX_WIDTH
);
339 for (row
=0; row
<drawHeight
; row
++) {
341 for (i
=0;i
<drawWidth
;i
++) {
346 gl_write_zoomed_rgb_span(ctx
, drawWidth
, destX
, destY
,
347 zSpan
, (void *) rgb
, zoomY0
);
355 else if (format
==GL_LUMINANCE_ALPHA
&& type
==GL_UNSIGNED_BYTE
) {
356 if (ctx
->Visual
->RGBAflag
) {
357 GLubyte
*src
= (GLubyte
*) pixels
358 + (skipRows
* rowLength
+ skipPixels
)*2;
359 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
362 ASSERT(drawWidth
< MAX_WIDTH
);
363 for (row
=0; row
<drawHeight
; row
++) {
366 for (i
=0;i
<drawWidth
;i
++) {
372 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
373 (void *) rgba
, NULL
);
378 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
381 ASSERT(drawWidth
< MAX_WIDTH
);
382 for (row
=0; row
<drawHeight
; row
++) {
385 for (i
=0;i
<drawWidth
;i
++) {
392 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
393 (void *) rgba
, NULL
);
400 ASSERT(drawWidth
< MAX_WIDTH
);
401 for (row
=0; row
<drawHeight
; row
++) {
404 for (i
=0;i
<drawWidth
;i
++) {
410 gl_write_zoomed_rgba_span(ctx
, drawWidth
, destX
, destY
,
411 zSpan
, (void *) rgba
, zoomY0
);
419 else if (format
==GL_COLOR_INDEX
&& type
==GL_UNSIGNED_BYTE
) {
420 GLubyte
*src
= (GLubyte
*) pixels
+ skipRows
* rowLength
+ skipPixels
;
421 if (ctx
->Visual
->RGBAflag
) {
422 /* convert CI data to RGBA */
423 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
);
429 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
430 (const GLubyte (*)[4])rgba
,
437 else if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==-1.0F
) {
440 for (row
=0; row
<drawHeight
; row
++) {
441 ASSERT(drawWidth
< MAX_WIDTH
);
442 _mesa_map_ci8_to_rgba(ctx
, drawWidth
, src
, rgba
);
444 (*ctx
->Driver
.WriteRGBASpan
)(ctx
, drawWidth
, destX
, destY
,
445 (const GLubyte (*)[4])rgba
,
454 for (row
=0; row
<drawHeight
; row
++) {
455 ASSERT(drawWidth
< MAX_WIDTH
);
456 _mesa_map_ci8_to_rgba(ctx
, drawWidth
, src
, rgba
);
457 gl_write_zoomed_rgba_span(ctx
, drawWidth
, destX
, destY
,
458 zSpan
, (void *) rgba
, zoomY0
);
466 /* write CI data to CI frame buffer */
468 if (ctx
->Pixel
.ZoomX
==1.0F
&& ctx
->Pixel
.ZoomY
==1.0F
) {
470 for (row
=0; row
<drawHeight
; row
++) {
471 (*ctx
->Driver
.WriteCI8Span
)(ctx
, drawWidth
, destX
, destY
,
485 /* can't handle this pixel format and/or data type here */
490 /* can't do a simple draw, have to use slow path */
497 * Do glDrawPixels of index pixels.
500 draw_index_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
501 GLsizei width
, GLsizei height
,
502 GLenum type
, const GLvoid
*pixels
)
504 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
505 const GLint desty
= y
;
506 GLint row
, drawWidth
;
507 GLdepth zspan
[MAX_WIDTH
];
509 drawWidth
= (width
> MAX_WIDTH
) ? MAX_WIDTH
: width
;
511 /* Fragment depth values */
512 if (ctx
->Depth
.Test
|| ctx
->Fog
.Enabled
) {
513 GLdepth zval
= (GLdepth
) (ctx
->Current
.RasterPos
[2] * ctx
->Visual
->DepthMaxF
);
515 for (i
= 0; i
< drawWidth
; i
++) {
523 for (row
= 0; row
< height
; row
++, y
++) {
524 GLuint indexes
[MAX_WIDTH
];
525 const GLvoid
*source
= _mesa_image_address(&ctx
->Unpack
,
526 pixels
, width
, height
, GL_COLOR_INDEX
, type
, 0, row
, 0);
527 _mesa_unpack_index_span(ctx
, drawWidth
, GL_UNSIGNED_INT
, indexes
,
528 type
, source
, &ctx
->Unpack
,
529 ctx
->ImageTransferState
);
531 gl_write_zoomed_index_span(ctx
, drawWidth
, x
, y
, zspan
, indexes
, desty
);
534 gl_write_index_span(ctx
, drawWidth
, x
, y
, zspan
, indexes
, GL_BITMAP
);
542 * Do glDrawPixels of stencil image. The image datatype may either
543 * be GLubyte or GLbitmap.
546 draw_stencil_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
547 GLsizei width
, GLsizei height
,
548 GLenum type
, const GLvoid
*pixels
)
550 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
551 const GLint desty
= y
;
552 GLint row
, drawWidth
;
554 if (type
!= GL_BYTE
&&
555 type
!= GL_UNSIGNED_BYTE
&&
557 type
!= GL_UNSIGNED_SHORT
&&
559 type
!= GL_UNSIGNED_INT
&&
562 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawPixels(stencil type)");
566 drawWidth
= (width
> MAX_WIDTH
) ? MAX_WIDTH
: width
;
568 for (row
= 0; row
< height
; row
++, y
++) {
569 GLstencil values
[MAX_WIDTH
];
570 GLenum destType
= (sizeof(GLstencil
) == sizeof(GLubyte
))
571 ? GL_UNSIGNED_BYTE
: GL_UNSIGNED_SHORT
;
572 const GLvoid
*source
= _mesa_image_address(&ctx
->Unpack
,
573 pixels
, width
, height
, GL_COLOR_INDEX
, type
, 0, row
, 0);
574 _mesa_unpack_index_span(ctx
, drawWidth
, destType
, values
,
575 type
, source
, &ctx
->Unpack
,
576 ctx
->ImageTransferState
);
577 if (ctx
->ImageTransferState
& IMAGE_SHIFT_OFFSET_BIT
) {
578 _mesa_shift_and_offset_stencil( ctx
, drawWidth
, values
);
580 if (ctx
->Pixel
.MapStencilFlag
) {
581 _mesa_map_stencil( ctx
, drawWidth
, values
);
585 gl_write_zoomed_stencil_span( ctx
, (GLuint
) drawWidth
, x
, y
,
589 _mesa_write_stencil_span( ctx
, (GLuint
) drawWidth
, x
, y
, values
);
597 * Do a glDrawPixels of depth values.
600 draw_depth_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
601 GLsizei width
, GLsizei height
,
602 GLenum type
, const GLvoid
*pixels
)
604 const GLboolean bias_or_scale
= ctx
->Pixel
.DepthBias
!=0.0 || ctx
->Pixel
.DepthScale
!=1.0;
605 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
606 const GLint desty
= y
;
607 GLubyte rgba
[MAX_WIDTH
][4];
608 GLuint ispan
[MAX_WIDTH
];
609 GLint drawWidth
= (width
> MAX_WIDTH
) ? MAX_WIDTH
: width
;
612 && type
!= GL_UNSIGNED_BYTE
614 && type
!= GL_UNSIGNED_SHORT
616 && type
!= GL_UNSIGNED_INT
617 && type
!= GL_FLOAT
) {
618 gl_error(ctx
, GL_INVALID_ENUM
, "glDrawPixels(type)");
622 /* Colors or indexes */
623 if (ctx
->Visual
->RGBAflag
) {
624 GLint r
= (GLint
) (ctx
->Current
.RasterColor
[0] * 255.0F
);
625 GLint g
= (GLint
) (ctx
->Current
.RasterColor
[1] * 255.0F
);
626 GLint b
= (GLint
) (ctx
->Current
.RasterColor
[2] * 255.0F
);
627 GLint a
= (GLint
) (ctx
->Current
.RasterColor
[3] * 255.0F
);
629 for (i
= 0; i
< drawWidth
; i
++) {
638 for (i
= 0; i
< drawWidth
; i
++) {
639 ispan
[i
] = ctx
->Current
.RasterIndex
;
643 if (type
==GL_UNSIGNED_SHORT
&& sizeof(GLdepth
)==sizeof(GLushort
)
644 && !bias_or_scale
&& !zoom
&& ctx
->Visual
->RGBAflag
) {
645 /* Special case: directly write 16-bit depth values */
647 for (row
= 0; row
< height
; row
++, y
++) {
648 GLdepth zspan
[MAX_WIDTH
];
649 const GLushort
*zptr
= _mesa_image_address(&ctx
->Unpack
,
650 pixels
, width
, height
, GL_DEPTH_COMPONENT
, type
, 0, row
, 0);
652 for (i
= 0; i
< width
; i
++)
654 gl_write_rgba_span( ctx
, width
, x
, y
, zspan
, rgba
, GL_BITMAP
);
657 else if (type
==GL_UNSIGNED_INT
&& ctx
->Visual
->DepthBits
== 32
658 && !bias_or_scale
&& !zoom
&& ctx
->Visual
->RGBAflag
) {
659 /* Special case: directly write 32-bit depth values */
661 for (row
= 0; row
< height
; row
++, y
++) {
662 const GLuint
*zptr
= _mesa_image_address(&ctx
->Unpack
,
663 pixels
, width
, height
, GL_DEPTH_COMPONENT
, type
, 0, row
, 0);
664 gl_write_rgba_span( ctx
, width
, x
, y
, zptr
, rgba
, GL_BITMAP
);
670 for (row
= 0; row
< height
; row
++, y
++) {
671 GLdepth zspan
[MAX_WIDTH
];
672 const GLvoid
*src
= _mesa_image_address(&ctx
->Unpack
,
673 pixels
, width
, height
, GL_DEPTH_COMPONENT
, type
, 0, row
, 0);
674 _mesa_unpack_depth_span( ctx
, drawWidth
, zspan
, type
, src
,
675 &ctx
->Unpack
, ctx
->ImageTransferState
);
676 if (ctx
->Visual
->RGBAflag
) {
678 gl_write_zoomed_rgba_span(ctx
, width
, x
, y
, zspan
,
679 (const GLubyte (*)[4])rgba
, desty
);
682 gl_write_rgba_span(ctx
, width
, x
, y
, zspan
, rgba
, GL_BITMAP
);
687 gl_write_zoomed_index_span(ctx
, width
, x
, y
, zspan
,
691 gl_write_index_span(ctx
, width
, x
, y
, zspan
, ispan
, GL_BITMAP
);
701 * Do glDrawPixels of RGBA pixels.
704 draw_rgba_pixels( GLcontext
*ctx
, GLint x
, GLint y
,
705 GLsizei width
, GLsizei height
,
706 GLenum format
, GLenum type
, const GLvoid
*pixels
)
708 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
709 const GLboolean zoom
= ctx
->Pixel
.ZoomX
!=1.0 || ctx
->Pixel
.ZoomY
!=1.0;
710 const GLint desty
= y
;
711 GLdepth zspan
[MAX_WIDTH
];
713 GLfloat
*convImage
= NULL
;
714 GLuint transferOps
= ctx
->ImageTransferState
;
716 if (!_mesa_is_legal_format_and_type(format
, type
)) {
717 gl_error(ctx
, GL_INVALID_ENUM
, "glDrawPixels(format or type)");
721 /* Try an optimized glDrawPixels first */
722 if (fast_draw_pixels(ctx
, x
, y
, width
, height
, format
, type
, pixels
))
725 /* Fragment depth values */
726 if (ctx
->Depth
.Test
|| ctx
->Fog
.Enabled
) {
727 /* fill in array of z values */
728 GLdepth z
= (GLdepth
) (ctx
->Current
.RasterPos
[2] * ctx
->Visual
->DepthMaxF
);
730 for (i
=0;i
<width
;i
++) {
736 if (ctx
->RasterMask
== 0 && !zoom
&& x
>= 0 && y
>= 0
737 && x
+ width
<= ctx
->DrawBuffer
->Width
738 && y
+ height
<= ctx
->DrawBuffer
->Height
) {
742 quickDraw
= GL_FALSE
;
745 if (ctx
->Pixel
.Convolution2DEnabled
|| ctx
->Pixel
.Separable2DEnabled
) {
746 /* Convolution has to be handled specially. We'll create an
747 * intermediate image, applying all pixel transfer operations
748 * up to convolution. Then we'll convolve the image. Then
749 * we'll proceed with the rest of the transfer operations and
750 * rasterize the image.
753 GLfloat
*dest
, *tmpImage
;
755 tmpImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
757 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
760 convImage
= (GLfloat
*) MALLOC(width
* height
* 4 * sizeof(GLfloat
));
763 gl_error(ctx
, GL_OUT_OF_MEMORY
, "glDrawPixels");
767 /* Unpack the image and apply transfer ops up to convolution */
769 for (row
= 0; row
< height
; row
++) {
770 const GLvoid
*source
= _mesa_image_address(unpack
,
771 pixels
, width
, height
, format
, type
, 0, row
, 0);
772 _mesa_unpack_float_color_span(ctx
, width
, GL_RGBA
, (void *) dest
,
773 format
, type
, source
, unpack
,
774 transferOps
& IMAGE_PRE_CONVOLUTION_BITS
,
780 if (ctx
->Pixel
.Convolution2DEnabled
) {
781 _mesa_convolve_2d_image(ctx
, &width
, &height
, tmpImage
, convImage
);
784 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
785 _mesa_convolve_sep_image(ctx
, &width
, &height
, tmpImage
, convImage
);
789 /* continue transfer ops and draw the convolved image */
790 unpack
= &_mesa_native_packing
;
794 transferOps
&= IMAGE_POST_CONVOLUTION_BITS
;
801 GLubyte rgba
[MAX_WIDTH
][4];
803 if (width
> MAX_WIDTH
)
805 for (row
= 0; row
< height
; row
++, y
++) {
806 const GLvoid
*source
= _mesa_image_address(unpack
,
807 pixels
, width
, height
, format
, type
, 0, row
, 0);
808 _mesa_unpack_ubyte_color_span(ctx
, width
, GL_RGBA
, (void*) rgba
,
809 format
, type
, source
, unpack
,
811 if ((ctx
->Pixel
.MinMaxEnabled
&& ctx
->MinMax
.Sink
) ||
812 (ctx
->Pixel
.HistogramEnabled
&& ctx
->Histogram
.Sink
))
815 if (ctx
->Texture
.ReallyEnabled
&& ctx
->Pixel
.PixelTextureEnabled
) {
816 GLfloat s
[MAX_WIDTH
], t
[MAX_WIDTH
], r
[MAX_WIDTH
], q
[MAX_WIDTH
];
817 GLubyte primary_rgba
[MAX_WIDTH
][4];
819 /* XXX not sure how multitexture is supposed to work here */
821 MEMCPY(primary_rgba
, rgba
, 4 * width
* sizeof(GLubyte
));
823 for (unit
= 0; unit
< MAX_TEXTURE_UNITS
; unit
++) {
824 _mesa_pixeltexgen(ctx
, width
, (const GLubyte (*)[4]) rgba
,
826 gl_texture_pixels(ctx
, unit
, width
, s
, t
, r
, NULL
,
832 (*ctx
->Driver
.WriteRGBASpan
)( ctx
, width
, x
, y
,
833 (CONST
GLubyte (*)[]) rgba
, NULL
);
836 gl_write_zoomed_rgba_span( ctx
, width
, x
, y
, zspan
,
837 (CONST
GLubyte (*)[]) rgba
, desty
);
840 gl_write_rgba_span( ctx
, (GLuint
) width
, x
, y
, zspan
, rgba
, GL_BITMAP
);
853 * Execute glDrawPixels
856 _mesa_DrawPixels( GLsizei width
, GLsizei height
,
857 GLenum format
, GLenum type
, const GLvoid
*pixels
)
859 GET_CURRENT_CONTEXT(ctx
);
860 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glDrawPixels");
862 if (ctx
->RenderMode
==GL_RENDER
) {
864 if (!pixels
|| !ctx
->Current
.RasterPosValid
) {
869 gl_update_state(ctx
);
872 if (ctx
->ImageTransferState
== UPDATE_IMAGE_TRANSFER_STATE
)
873 _mesa_update_image_transfer_state(ctx
);
875 x
= (GLint
) (ctx
->Current
.RasterPos
[0] + 0.5F
);
876 y
= (GLint
) (ctx
->Current
.RasterPos
[1] + 0.5F
);
878 ctx
->OcclusionResult
= GL_TRUE
;
880 /* see if device driver can do the drawpix */
881 if (ctx
->Driver
.DrawPixels
882 && (*ctx
->Driver
.DrawPixels
)(ctx
, x
, y
, width
, height
, format
, type
,
883 &ctx
->Unpack
, pixels
)) {
888 case GL_STENCIL_INDEX
:
889 draw_stencil_pixels( ctx
, x
, y
, width
, height
, type
, pixels
);
891 case GL_DEPTH_COMPONENT
:
892 draw_depth_pixels( ctx
, x
, y
, width
, height
, type
, pixels
);
895 if (ctx
->Visual
->RGBAflag
)
896 draw_rgba_pixels(ctx
, x
,y
, width
, height
, format
, type
, pixels
);
898 draw_index_pixels(ctx
, x
, y
, width
, height
, type
, pixels
);
905 case GL_LUMINANCE_ALPHA
:
911 draw_rgba_pixels(ctx
, x
, y
, width
, height
, format
, type
, pixels
);
914 gl_error( ctx
, GL_INVALID_ENUM
, "glDrawPixels(format)" );
918 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
919 if (ctx
->Current
.RasterPosValid
) {
921 GLfloat texcoord
[4], invq
;
922 UBYTE_RGBA_TO_FLOAT_RGBA(color
, ctx
->Current
.ByteColor
);
923 invq
= 1.0F
/ ctx
->Current
.Texcoord
[0][3];
924 texcoord
[0] = ctx
->Current
.Texcoord
[0][0] * invq
;
925 texcoord
[1] = ctx
->Current
.Texcoord
[0][1] * invq
;
926 texcoord
[2] = ctx
->Current
.Texcoord
[0][2] * invq
;
927 texcoord
[3] = ctx
->Current
.Texcoord
[0][3];
928 FEEDBACK_TOKEN( ctx
, (GLfloat
) (GLint
) GL_DRAW_PIXEL_TOKEN
);
929 gl_feedback_vertex( ctx
,
930 ctx
->Current
.RasterPos
,
931 color
, ctx
->Current
.Index
, texcoord
);
934 else if (ctx
->RenderMode
==GL_SELECT
) {
935 if (ctx
->Current
.RasterPosValid
) {
936 gl_update_hitflag( ctx
, ctx
->Current
.RasterPos
[2] );