2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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 * \file swrast/s_bitmap.c
27 * \brief glBitmap rendering.
32 #include "bufferobj.h"
37 #include "s_context.h"
44 * Called via ctx->Driver.Bitmap()
45 * All parameter error checking will have been done before this is called.
48 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
49 GLsizei width
, GLsizei height
,
50 const struct gl_pixelstore_attrib
*unpack
,
51 const GLubyte
*bitmap
)
53 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
58 ASSERT(ctx
->RenderMode
== GL_RENDER
);
60 bitmap
= _mesa_validate_and_map_bitmap_pbo(ctx
, width
, height
,
66 RENDER_START(swrast
,ctx
);
68 if (SWRAST_CONTEXT(ctx
)->NewState
)
69 _swrast_validate_derived( ctx
);
71 INIT_SPAN(span
, GL_BITMAP
);
73 span
.arrayMask
= SPAN_XY
;
74 _swrast_span_default_attribs(ctx
, &span
);
76 for (row
= 0; row
< height
; row
++) {
77 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
78 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
80 if (unpack
->LsbFirst
) {
82 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
83 for (col
= 0; col
< width
; col
++) {
85 span
.array
->x
[count
] = px
+ col
;
86 span
.array
->y
[count
] = py
+ row
;
98 /* get ready for next row */
104 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
105 for (col
= 0; col
< width
; col
++) {
107 span
.array
->x
[count
] = px
+ col
;
108 span
.array
->y
[count
] = py
+ row
;
120 /* get ready for next row */
125 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
128 if (ctx
->Visual
.rgbMode
)
129 _swrast_write_rgba_span(ctx
, &span
);
131 _swrast_write_index_span(ctx
, &span
);
137 RENDER_FINISH(swrast
,ctx
);
139 _mesa_unmap_bitmap_pbo(ctx
, unpack
);
145 * XXX this is another way to implement Bitmap. Use horizontal runs of
146 * fragments, initializing the mask array to indicate which fragments to
150 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
151 GLsizei width
, GLsizei height
,
152 const struct gl_pixelstore_attrib
*unpack
,
153 const GLubyte
*bitmap
)
155 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
159 ASSERT(ctx
->RenderMode
== GL_RENDER
);
162 RENDER_START(swrast
,ctx
);
164 if (SWRAST_CONTEXT(ctx
)->NewState
)
165 _swrast_validate_derived( ctx
);
167 INIT_SPAN(span
, GL_BITMAP
);
169 span
.arrayMask
= SPAN_MASK
;
170 _swrast_span_default_attribs(ctx
, &span
);
172 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
175 /*span.end = width;*/
177 for (row
=0; row
<height
; row
++, span
.y
++) {
178 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
179 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
181 if (unpack
->LsbFirst
) {
183 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
184 for (col
=0; col
<width
; col
++) {
185 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
195 if (ctx
->Visual
.rgbMode
)
196 _swrast_write_rgba_span(ctx
, &span
);
198 _swrast_write_index_span(ctx
, &span
);
200 /* get ready for next row */
206 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
207 for (col
=0; col
<width
; col
++) {
208 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
218 if (ctx
->Visual
.rgbMode
)
219 _swrast_write_rgba_span(ctx
, &span
);
221 _swrast_write_index_span(ctx
, &span
);
223 /* get ready for next row */
229 RENDER_FINISH(swrast
,ctx
);