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.
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 if (unpack
->BufferObj
->Name
) {
63 if (!_mesa_validate_pbo_access(2, unpack
, width
, height
, 1,
64 GL_COLOR_INDEX
, GL_BITMAP
,
66 _mesa_error(ctx
, GL_INVALID_OPERATION
,"glBitmap(invalid PBO access)");
69 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
73 /* buffer is already mapped - that's an error */
74 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBitmap(PBO is mapped)");
77 bitmap
= ADD_POINTERS(buf
, bitmap
);
80 RENDER_START(swrast
,ctx
);
82 if (SWRAST_CONTEXT(ctx
)->NewState
)
83 _swrast_validate_derived( ctx
);
85 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_XY
);
87 _swrast_span_default_color(ctx
, &span
);
88 if (ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
)
89 _swrast_span_default_secondary_color(ctx
, &span
);
91 _swrast_span_default_z(ctx
, &span
);
92 if (swrast
->_FogEnabled
)
93 _swrast_span_default_fog(ctx
, &span
);
94 if (ctx
->Texture
._EnabledCoordUnits
)
95 _swrast_span_default_texcoords(ctx
, &span
);
97 for (row
= 0; row
< height
; row
++) {
98 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
99 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
101 if (unpack
->LsbFirst
) {
103 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
104 for (col
= 0; col
< width
; col
++) {
106 span
.array
->x
[count
] = px
+ col
;
107 span
.array
->y
[count
] = py
+ row
;
119 /* get ready for next row */
125 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
126 for (col
= 0; col
< width
; col
++) {
128 span
.array
->x
[count
] = px
+ col
;
129 span
.array
->y
[count
] = py
+ row
;
141 /* get ready for next row */
146 if (count
+ width
>= MAX_WIDTH
|| row
+ 1 == height
) {
149 if (ctx
->Visual
.rgbMode
)
150 _swrast_write_rgba_span(ctx
, &span
);
152 _swrast_write_index_span(ctx
, &span
);
158 RENDER_FINISH(swrast
,ctx
);
160 if (unpack
->BufferObj
->Name
) {
161 /* done with PBO so unmap it now */
162 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
170 * XXX this is another way to implement Bitmap. Use horizontal runs of
171 * fragments, initializing the mask array to indicate which fragments to
175 _swrast_Bitmap( GLcontext
*ctx
, GLint px
, GLint py
,
176 GLsizei width
, GLsizei height
,
177 const struct gl_pixelstore_attrib
*unpack
,
178 const GLubyte
*bitmap
)
180 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
184 ASSERT(ctx
->RenderMode
== GL_RENDER
);
187 RENDER_START(swrast
,ctx
);
189 if (SWRAST_CONTEXT(ctx
)->NewState
)
190 _swrast_validate_derived( ctx
);
192 INIT_SPAN(span
, GL_BITMAP
, width
, 0, SPAN_MASK
);
194 /*span.arrayMask |= SPAN_MASK;*/ /* we'll init span.mask[] */
197 /*span.end = width;*/
199 _swrast_span_default_color(ctx
, &span
);
201 _swrast_span_default_z(ctx
, &span
);
202 if (swrast
->_FogEnabled
)
203 _swrast_span_default_fog(ctx
, &span
);
204 if (ctx
->Texture
._EnabledCoordUnits
)
205 _swrast_span_default_texcoords(ctx
, &span
);
207 for (row
=0; row
<height
; row
++, span
.y
++) {
208 const GLubyte
*src
= (const GLubyte
*) _mesa_image_address2d(unpack
,
209 bitmap
, width
, height
, GL_COLOR_INDEX
, GL_BITMAP
, row
, 0);
211 if (unpack
->LsbFirst
) {
213 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
214 for (col
=0; col
<width
; col
++) {
215 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
225 if (ctx
->Visual
.rgbMode
)
226 _swrast_write_rgba_span(ctx
, &span
);
228 _swrast_write_index_span(ctx
, &span
);
230 /* get ready for next row */
236 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
237 for (col
=0; col
<width
; col
++) {
238 span
.array
->mask
[col
] = (*src
& mask
) ? GL_TRUE
: GL_FALSE
;
248 if (ctx
->Visual
.rgbMode
)
249 _swrast_write_rgba_span(ctx
, &span
);
251 _swrast_write_index_span(ctx
, &span
);
253 /* get ready for next row */
259 RENDER_FINISH(swrast
,ctx
);