3 * Copyright (C) 1997 Uwe Maurer
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * ---------------------------------------------------------------------
19 * This code was derived from the following source of information:
21 * svgamesa.c and ddsample.c by Brian Paul
25 #include <ggi/mesa/ggimesa.h>
26 #include <ggi/mesa/ggimesa_int.h>
28 #define RMASK ((1<<R)-1)
29 #define GMASK ((1<<G)-1)
30 #define BMASK ((1<<B)-1)
37 /**********************************************************************/
38 /***** Write spans of pixels *****/
39 /**********************************************************************/
41 void GGIwrite_ci32_span(const GLcontext
*ctx
,
42 GLuint n
, GLint x
, GLint y
,
46 FB_TYPE
*fb
=LFB(FB_TYPE
,x
,FLIP(y
));
57 while (n
--) *fb
++ = *ci
++;
61 void GGIwrite_ci8_span(const GLcontext
*ctx
,
62 GLuint n
, GLint x
, GLint y
,
64 const GLubyte mask
[] )
66 FB_TYPE
*fb
=LFB(FB_TYPE
,x
,FLIP(y
));
78 while (n
--) *fb
++ = *ci
++;
83 void GGIwrite_rgba_span(const GLcontext
*ctx
,
84 GLuint n
, GLint x
, GLint y
,
85 const GLubyte rgba
[][4],
88 FB_TYPE
*fb
=LFB(FB_TYPE
,x
,FLIP(y
));
94 *fb
= ((rgba
[0][RCOMP
]>>RS
) << (G
+B
)) |
95 ((rgba
[0][GCOMP
]>>GS
) << B
) |
96 ((rgba
[0][BCOMP
]>>BS
));
105 *fb
++= ((rgba
[0][RCOMP
]>>RS
) << (G
+B
)) |
106 ((rgba
[0][GCOMP
]>>GS
) << B
)|
107 ((rgba
[0][BCOMP
]>>BS
));
113 void GGIwrite_rgb_span( const GLcontext
*ctx
,
114 GLuint n
, GLint x
, GLint y
,
115 const GLubyte rgba
[][3],
116 const GLubyte mask
[] )
118 FB_TYPE
*fb
=LFB(FB_TYPE
,x
,FLIP(y
));
123 *fb
= ((rgba
[0][RCOMP
]>>RS
) << (G
+B
)) |
124 ((rgba
[0][GCOMP
]>>GS
) << B
) |
125 ((rgba
[0][BCOMP
]>>BS
));
134 *fb
++= ((rgba
[0][RCOMP
]>>RS
) << (G
+B
)) |
135 ((rgba
[0][GCOMP
]>>GS
) << B
) |
136 ((rgba
[0][BCOMP
]>>BS
));
143 void GGIwrite_mono_span( const GLcontext
*ctx
,
144 GLuint n
, GLint x
, GLint y
,
145 const GLubyte mask
[])
152 fb
=LFB(FB_TYPE
,x
,FLIP(y
));
153 color
=(FB_TYPE
) GGICTX
->color
;
157 if (*mask
++) *fb
=color
;
163 ggiDrawHLine(VIS
,x
,FLIP(y
),n
);
168 /**********************************************************************/
169 /***** Read spans of pixels *****/
170 /**********************************************************************/
173 void GGIread_ci32_span(const GLcontext
*ctx
,
174 GLuint n
, GLint x
, GLint y
, GLuint ci
[])
176 FB_TYPE
*fb
=LFB(FB_TYPE
,x
,FLIP(y
));
181 void GGIread_rgba_span(const GLcontext
*ctx
,
182 GLuint n
, GLint x
, GLint y
,
185 FB_TYPE
*fb
=LFB(FB_TYPE
,x
,FLIP(y
));
191 rgba
[0][RCOMP
] = (GLubyte
) (color
>>(G
+B
))<<RS
;
192 rgba
[0][GCOMP
] = (GLubyte
) ((color
>>B
)& ((1<<G
)-1))<<GS
;
193 rgba
[0][BCOMP
] = (GLubyte
) (color
& ((1<<B
)-1))<<BS
;
199 /**********************************************************************/
200 /***** Write arrays of pixels *****/
201 /**********************************************************************/
203 void GGIwrite_ci32_pixels(const GLcontext
*ctx
,
204 GLuint n
, const GLint x
[], const GLint y
[],
205 const GLuint ci
[], const GLubyte mask
[] )
207 FB_TYPE
*fb
=LFB(FB_TYPE
,0,0);
210 if (*mask
++) *(fb
+ *x
+ FLIP(*y
)*GGICTX
->width
)=*ci
;
217 void GGIwrite_mono_pixels(const GLcontext
*ctx
,
219 const GLint x
[], const GLint y
[],
220 const GLubyte mask
[] )
222 FB_TYPE
*fb
=LFB(FB_TYPE
,0,0);
223 FB_TYPE color
=(FB_TYPE
) GGICTX
->color
;
226 if (*mask
++) *(fb
+ *x
+ FLIP(*y
)*GGICTX
->width
)=color
;
232 void GGIwrite_rgba_pixels(const GLcontext
*ctx
,
233 GLuint n
, const GLint x
[], const GLint y
[],
234 const GLubyte rgba
[][4],
235 const GLubyte mask
[] )
237 FB_TYPE
*fb
=LFB(FB_TYPE
,0,0);
242 color
= ((rgba
[0][RCOMP
]>>RS
) << (G
+B
)) |
243 ((rgba
[0][GCOMP
]>>GS
) << B
) |
244 ((rgba
[0][BCOMP
]>>BS
));
245 *(fb
+ *x
+ FLIP(*y
)*GGICTX
->width
)=color
;
253 /**********************************************************************/
254 /***** Read arrays of pixels *****/
255 /**********************************************************************/
257 void GGIread_ci32_pixels(const GLcontext
*ctx
,
258 GLuint n
, const GLint x
[], const GLint y
[],
259 GLuint ci
[], const GLubyte mask
[])
261 FB_TYPE
*fb
=LFB(FB_TYPE
,0,0);
265 *ci
=*(fb
+ *x
+ FLIP(*y
)*GGICTX
->width
);
272 void GGIread_rgba_pixels(const GLcontext
*ctx
,
273 GLuint n
, const GLint x
[], const GLint y
[],
275 const GLubyte mask
[] )
277 FB_TYPE
*fb
=LFB(FB_TYPE
,0,0);
284 color
=*(fb
+ *x
+ FLIP(*y
)*GGICTX
->width
);
285 rgba
[0][RCOMP
] =(GLubyte
)(color
>>(G
+B
))<<RS
;
286 rgba
[0][GCOMP
] =(GLubyte
)((color
>>B
)& ((1<<G
)-1))<<GS
;
287 rgba
[0][BCOMP
] =(GLubyte
) (color
& ((1<<B
)-1))<<BS
;
295 int GGIsetup_driver(GGIMesaContext ggictx
, struct ggi_mesa_info
*info
)
297 GLcontext
*ctx
= ggictx
->gl_ctx
;
299 ctx
->Driver
.WriteRGBASpan
= GGIwrite_rgba_span
;
300 ctx
->Driver
.WriteRGBSpan
= GGIwrite_rgb_span
;
301 // ctx->Driver.WriteMonoRGBASpan = GGIwrite_mono_span;
302 ctx
->Driver
.WriteRGBAPixels
= GGIwrite_rgba_pixels
;
303 // ctx->Driver.WriteMonoRGBAPixels = GGIwrite_mono_pixels;
305 ctx
->Driver
.WriteCI32Span
= GGIwrite_ci32_span
;
306 ctx
->Driver
.WriteCI8Span
= GGIwrite_ci8_span
;
307 // ctx->Driver.WriteMonoCISpan = GGIwrite_mono_span;
308 ctx
->Driver
.WriteCI32Pixels
= GGIwrite_ci32_pixels
;
309 // ctx->Driver.WriteMonoCIPixels = GGIwrite_mono_pixels;
311 ctx
->Driver
.ReadCI32Span
= GGIread_ci32_span
;
312 ctx
->Driver
.ReadRGBASpan
= GGIread_rgba_span
;
313 ctx
->Driver
.ReadCI32Pixels
= GGIread_ci32_pixels
;
314 ctx
->Driver
.ReadRGBAPixels
= GGIread_rgba_pixels
;
323 static int GGIopen(ggi_visual_t vis
,struct ggi_dlhandle
*dlh
,
324 const char *args
,void *argptr
, uint32
*dlret
)
326 LIBGGI_MESAEXT(vis
)->setup_driver
=GGIsetup_driver
;
328 *dlret
= GGI_DL_OPDRAW
;
332 int DLOPENFUNC(int func
, void **funcptr
)
345 return GGI_ENOTFOUND
;