2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
26 * \file swrast/s_bitmap.c
27 * \brief glBitmap rendering.
31 #include "main/glheader.h"
32 #include "main/bufferobj.h"
33 #include "main/condrender.h"
34 #include "main/image.h"
35 #include "main/macros.h"
38 #include "s_context.h"
45 * Called via ctx->Driver.Bitmap()
46 * All parameter error checking will have been done before this is called.
49 _swrast_Bitmap( struct gl_context
*ctx
, GLint px
, GLint py
,
50 GLsizei width
, GLsizei height
,
51 const struct gl_pixelstore_attrib
*unpack
,
52 const GLubyte
*bitmap
)
58 assert(ctx
->RenderMode
== GL_RENDER
);
60 if (!_mesa_check_conditional_render(ctx
))
61 return; /* don't draw */
63 bitmap
= (const GLubyte
*) _mesa_map_pbo_source(ctx
, unpack
, bitmap
);
67 swrast_render_start(ctx
);
69 if (SWRAST_CONTEXT(ctx
)->NewState
)
70 _swrast_validate_derived( ctx
);
72 INIT_SPAN(span
, GL_BITMAP
);
74 span
.arrayMask
= SPAN_XY
;
75 _swrast_span_default_attribs(ctx
, &span
);
77 for (row
= 0; row
< height
; row
++) {
78 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
79 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
81 if (unpack
->LsbFirst
) {
83 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
84 for (col
= 0; col
< width
; col
++) {
86 span
.array
->x
[count
] = px
+ col
;
87 span
.array
->y
[count
] = py
+ row
;
99 /* get ready for next row */
105 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
106 for (col
= 0; col
< width
; col
++) {
108 span
.array
->x
[count
] = px
+ col
;
109 span
.array
->y
[count
] = py
+ row
;
121 /* get ready for next row */
126 if (count
+ width
>= SWRAST_MAX_WIDTH
|| row
+ 1 == height
) {
129 _swrast_write_rgba_span(ctx
, &span
);
135 swrast_render_finish(ctx
);
137 _mesa_unmap_pbo_source(ctx
, unpack
);
143 * XXX this is another way to implement Bitmap. Use horizontal runs of
144 * fragments, initializing the mask array to indicate which fragments to
148 _swrast_Bitmap( struct gl_context
*ctx
, GLint px
, GLint py
,
149 GLsizei width
, GLsizei height
,
150 const struct gl_pixelstore_attrib
*unpack
,
151 const GLubyte
*bitmap
)
153 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
157 assert(ctx
->RenderMode
== GL_RENDER
);
160 swrast_render_start(ctx
);
162 if (SWRAST_CONTEXT(ctx
)->NewState
)
163 _swrast_validate_derived( ctx
);
165 INIT_SPAN(span
, GL_BITMAP
);
167 span
.arrayMask
= SPAN_MASK
;
168 _swrast_span_default_attribs(ctx
, &span
);
170 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
173 /*span.end = width;*/
175 for (row
=0; row
<height
; row
++, span
.y
++) {
176 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
177 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
179 if (unpack
->LsbFirst
) {
181 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
182 for (col
=0; col
<width
; col
++) {
183 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
193 _swrast_write_rgba_span(ctx
, &span
);
195 /* get ready for next row */
201 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
202 for (col
=0; col
<width
; col
++) {
203 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
213 _swrast_write_rgba_span(ctx
, &span
);
215 /* get ready for next row */
221 swrast_render_finish(ctx
);