Convert crlf->lf line endings.
[mesa.git] / src / mesa / drivers / allegro / generic.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 3.0
4 * Copyright (C) 1995-1998 Brian Paul
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 static void clear_color_generic(GLcontext *ctx, const GLfloat color[4])
22 {
23 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
24 GLubyte r, g, b;
25 CLAMPED_FLOAT_TO_UBYTE(r, color[0]);
26 CLAMPED_FLOAT_TO_UBYTE(g, color[1]);
27 CLAMPED_FLOAT_TO_UBYTE(b, color[2]);
28 context->ClearColor = makecol(r, g, b);
29 }
30
31
32 static void set_color_generic(GLcontext *ctx,
33 GLubyte red, GLubyte green,
34 GLubyte blue, GLubyte alpha)
35 {
36 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
37
38 context->CurrentColor = makecol(red, green, blue);
39 }
40
41
42 static GLbitfield clear_generic(GLcontext *ctx,
43 GLbitfield mask, GLboolean all,
44 GLint x, GLint y,
45 GLint width, GLint height)
46 {
47 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
48
49 if (mask & GL_COLOR_BUFFER_BIT)
50 {
51 if (all)
52 clear_to_color(context->Buffer->Active, context->ClearColor);
53 else
54 rect(context->Buffer->Active,
55 x, y, x+width-1, y+height-1,
56 context->ClearColor);
57 }
58
59 return mask & (~GL_COLOR_BUFFER_BIT);
60 }
61
62
63 static void write_rgba_span_generic(const GLcontext *ctx,
64 GLuint n, GLint x, GLint y,
65 const GLubyte rgba[][4],
66 const GLubyte mask[])
67 {
68 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
69 BITMAP *bmp = context->Buffer->Active;
70
71 y = FLIP(context, y);
72
73 if (mask)
74 {
75 while (n--)
76 {
77 if (mask[0]) putpixel(bmp, x, y, makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]));
78 x++; mask++; rgba++;
79 }
80 }
81 else
82 {
83 while (n--)
84 {
85 putpixel(bmp, x, y, makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]));
86 x++; rgba++;
87 }
88 }
89 }
90
91
92 static void write_rgb_span_generic(const GLcontext *ctx,
93 GLuint n, GLint x, GLint y,
94 const GLubyte rgb[][3],
95 const GLubyte mask[])
96 {
97 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
98 BITMAP *bmp = context->Buffer->Active;
99
100 y = FLIP(context, y);
101
102 if (mask)
103 {
104 while(n--)
105 {
106 if (mask[0]) putpixel(bmp, x, y, makecol(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP]));
107 x++; mask++; rgb++;
108 }
109 }
110 else
111 {
112 while (n--)
113 {
114 putpixel(bmp, x, y, makecol(rgb[0][RCOMP], rgb[0][GCOMP], rgb[0][BCOMP]));
115 x++; rgb++;
116 }
117 }
118 }
119
120
121 static void write_mono_rgba_span_generic(const GLcontext *ctx,
122 GLuint n, GLint x, GLint y,
123 const GLubyte mask[])
124 {
125 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
126 BITMAP *bmp = context->Buffer->Active;
127 int color = context->CurrentColor;
128
129 y = FLIP(context, y);
130
131 if (mask)
132 {
133 while(n--)
134 {
135 if (mask[0]) putpixel(bmp, x, y, color);
136 x++; mask++;
137 }
138 }
139 else
140 {
141 while(n--)
142 {
143 putpixel(bmp, x, y, color);
144 x++;
145 }
146 }
147 }
148
149
150 static void read_rgba_span_generic(const GLcontext *ctx,
151 GLuint n, GLint x, GLint y,
152 GLubyte rgba[][4])
153 {
154 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
155 BITMAP *bmp = context->Buffer->Active;
156
157 y = FLIP(context, y);
158
159 while (n--)
160 {
161 int color = getpixel(bmp, x, y);
162
163 rgba[0][RCOMP] = getr(color);
164 rgba[0][GCOMP] = getg(color);
165 rgba[0][BCOMP] = getb(color);
166 rgba[0][ACOMP] = 255;
167
168 x++; rgba++;
169 }
170 }
171
172
173 static void write_rgba_pixels_generic(const GLcontext *ctx,
174 GLuint n,
175 const GLint x[],
176 const GLint y[],
177 const GLubyte rgba[][4],
178 const GLubyte mask[])
179 {
180 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
181 BITMAP *bmp = context->Buffer->Active;
182
183 while (n--)
184 {
185 if (mask[0]) putpixel(bmp, x[0], FLIP(context, y[0]), makecol(rgba[0][RCOMP], rgba[0][GCOMP], rgba[0][BCOMP]));
186 x++; y++; mask++;
187 }
188 }
189
190
191 static void write_mono_rgba_pixels_generic(const GLcontext *ctx,
192 GLuint n,
193 const GLint x[],
194 const GLint y[],
195 const GLubyte mask[])
196 {
197 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
198 BITMAP *bmp = context->Buffer->Active;
199 int color = context->CurrentColor;
200
201 while (n--)
202 {
203 if (mask[0]) putpixel(bmp, x[0], FLIP(context, y[0]), color);
204 x++; y++; mask++;
205 }
206 }
207
208
209 static void read_rgba_pixels_generic(const GLcontext *ctx,
210 GLuint n,
211 const GLint x[],
212 const GLint y[],
213 GLubyte rgba[][4],
214 const GLubyte mask[])
215 {
216 AMesaContext context = (AMesaContext)(ctx->DriverCtx);
217 BITMAP *bmp = context->Buffer->Active;
218
219 while (n--)
220 {
221 if (mask[0])
222 {
223 int color = getpixel(bmp, x[0], FLIP(context, y[0]));
224
225 rgba[0][RCOMP] = getr(color);
226 rgba[0][GCOMP] = getg(color);
227 rgba[0][BCOMP] = getb(color);
228 rgba[0][ACOMP] = 255;
229 }
230
231 x++; y++; mask++; rgba++;
232 }
233 }
234