62722972b2aa65c6060348c2f7b74ae0e07e1eaf
[mesa.git] / src / mesa / drivers / ggi / default / stubs.c
1 /* GGI-Driver for MESA
2 *
3 * Copyright (C) 1997 Uwe Maurer
4 *
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.
9 *
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.
14 *
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:
20 *
21 * svgamesa.c and ddsample.c by Brian Paul
22 *
23 */
24
25 #include <stdio.h>
26
27 #include <ggi/internal/ggi-dl.h>
28 #include <ggi/mesa/ggimesa_int.h>
29 #include <ggi/mesa/debug.h>
30
31 #include "swrast/swrast.h"
32 //#include "swrast_setup/swrast_setup.h"
33 //#include "swrast/s_context.h"
34 //#include "swrast/s_depth.h"
35 //#include "swrast/s_triangle.h"
36
37 #define FLIP(coord) (LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y-(coord)-1)
38
39 /**********************************************************************/
40 /***** Write spans of pixels *****/
41 /**********************************************************************/
42
43 void GGIwrite_ci32_span(const GLcontext *ctx,
44 GLuint n, GLint x, GLint y,
45 const GLuint ci[],
46 const GLubyte mask[] )
47 {
48 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
49 y = FLIP(y);
50 if (mask)
51 {
52 while (n--) {
53 if (*mask++)
54 ggiPutPixel(ggi_ctx->ggi_visual, x, y, *ci);
55 x++;
56 ci++;
57 }
58 }
59 else
60 {
61 while (n--)
62 ggiPutPixel(ggi_ctx->ggi_visual, x++, y, *ci++);
63 }
64 }
65
66 void GGIwrite_ci8_span(const GLcontext *ctx,
67 GLuint n, GLint x, GLint y,
68 const GLubyte ci[],
69 const GLubyte mask[] )
70 {
71 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
72 y = FLIP(y);
73 if (mask)
74 {
75 while (n--) {
76 if (*mask++)
77 ggiPutPixel(ggi_ctx->ggi_visual, x, y, *ci);
78 x++;
79 ci++;
80 }
81 }
82 else
83 {
84 while (n--)
85 ggiPutPixel(ggi_ctx->ggi_visual, x++, y, *ci++);
86 }
87 }
88
89 void GGIwrite_mono_ci_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
90 const GLuint ci, const GLubyte mask[])
91 {
92 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
93 y = FLIP(y);
94 if (mask)
95 {
96 while (n--) {
97 if (*mask++)
98 ggiPutPixel(ggi_ctx->ggi_visual, x, y, ci);
99 x++;
100 }
101 }
102 else
103 {
104 while (n--)
105 ggiPutPixel(ggi_ctx->ggi_visual, x++, y, ci);
106 }
107 }
108
109 void GGIwrite_mono_rgba_span(const GLcontext *ctx, GLuint n, GLint x, GLint y,
110 const GLchan rgba[4], const GLubyte mask[])
111 {
112 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
113 ggi_color rgb;
114 ggi_pixel col;
115
116 y = FLIP(y);
117
118 rgb.r = (uint16)(rgba[RCOMP]) << SHIFT;
119 rgb.g = (uint16)(rgba[GCOMP]) << SHIFT;
120 rgb.b = (uint16)(rgba[BCOMP]) << SHIFT;
121 col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
122
123 if (mask)
124 {
125 while (n--) {
126 if (*mask++)
127 ggiPutPixel(ggi_ctx->ggi_visual, x, y, col);
128 x++;
129 }
130 }
131 else
132 {
133 ggiDrawHLine(ggi_ctx->ggi_visual, x, y, n);
134 }
135 }
136
137 void GGIwrite_rgba_span( const GLcontext *ctx,
138 GLuint n, GLint x, GLint y,
139 const GLubyte rgba[][4],
140 const GLubyte mask[])
141 {
142 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
143 ggi_color rgb;
144 ggi_pixel col;
145 y = FLIP(y);
146
147 if (mask)
148 {
149 while (n--) {
150 if (*mask++)
151 {
152 rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
153 rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
154 rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
155 col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
156 ggiPutPixel(ggi_ctx->ggi_visual, x, y, col);
157 }
158 x++;
159 rgba++;
160 }
161 }
162 else
163 {
164 while (n--)
165 {
166 rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
167 rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
168 rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
169 col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
170 ggiPutPixel(ggi_ctx->ggi_visual, x++, y, col);
171 rgba++;
172 }
173 }
174 }
175
176 void GGIwrite_rgb_span( const GLcontext *ctx,
177 GLuint n, GLint x, GLint y,
178 const GLubyte rgba[][3],
179 const GLubyte mask[] )
180 {
181 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
182 ggi_color rgb;
183 ggi_pixel col;
184 y = FLIP(y);
185
186 if (mask)
187 {
188 while (n--) {
189 if (*mask++)
190 {
191 rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
192 rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
193 rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
194 col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
195 ggiPutPixel(ggi_ctx->ggi_visual, x, y, col);
196 }
197 x++;
198 rgba++;
199 }
200 }
201 else
202 {
203 while (n--)
204 {
205 rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
206 rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
207 rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
208 col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
209 ggiPutPixel(ggi_ctx->ggi_visual, x++, y, col);
210 rgba++;
211 }
212 }
213 }
214
215
216
217 /**********************************************************************/
218 /***** Read spans of pixels *****/
219 /**********************************************************************/
220
221
222 void GGIread_ci32_span( const GLcontext *ctx,
223 GLuint n, GLint x, GLint y, GLuint ci[])
224 {
225 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
226 y = FLIP(y);
227 while (n--)
228 ggiGetPixel(ggi_ctx->ggi_visual, x++, y, ci++);
229 }
230
231 void GGIread_rgba_span( const GLcontext *ctx,
232 GLuint n, GLint x, GLint y,
233 GLubyte rgba[][4])
234 {
235 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
236 ggi_color rgb;
237 ggi_pixel col;
238
239 y = FLIP(y);
240
241 while (n--)
242 {
243 ggiGetPixel(ggi_ctx->ggi_visual, x++, y, &col);
244 ggiUnmapPixel(ggi_ctx->ggi_visual, col, &rgb);
245 rgba[0][RCOMP] = (GLubyte) (rgb.r >> SHIFT);
246 rgba[0][GCOMP] = (GLubyte) (rgb.g >> SHIFT);
247 rgba[0][BCOMP] = (GLubyte) (rgb.b >> SHIFT);
248 rgba[0][ACOMP] = 0;
249 rgba++;
250 }
251 }
252
253 /**********************************************************************/
254 /***** Write arrays of pixels *****/
255 /**********************************************************************/
256
257 void GGIwrite_ci32_pixels( const GLcontext *ctx,
258 GLuint n, const GLint x[], const GLint y[],
259 const GLuint ci[], const GLubyte mask[] )
260 {
261 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
262 while (n--) {
263 if (*mask++)
264 ggiPutPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), *ci);
265 ci++;
266 x++;
267 y++;
268 }
269 }
270
271 void GGIwrite_mono_ci_pixels(const GLcontext *ctx,
272 GLuint n, const GLint x[], const GLint y[],
273 GLuint ci, const GLubyte mask[])
274 {
275 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
276 while (n--) {
277 if (*mask++)
278 ggiPutPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), ci);
279 x++;
280 y++;
281 }
282 }
283
284 void GGIwrite_rgba_pixels( const GLcontext *ctx,
285 GLuint n, const GLint x[], const GLint y[],
286 const GLubyte rgba[][4],
287 const GLubyte mask[] )
288 {
289 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
290 ggi_pixel col;
291 ggi_color rgb;
292 while (n--) {
293 if (*mask++) {
294 rgb.r = (uint16)(rgba[0][RCOMP]) << SHIFT;
295 rgb.g = (uint16)(rgba[0][GCOMP]) << SHIFT;
296 rgb.b = (uint16)(rgba[0][BCOMP]) << SHIFT;
297 col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
298 ggiPutPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), col);
299 }
300 x++;
301 y++;
302 rgba++;
303 }
304 }
305
306 void GGIwrite_mono_rgba_pixels(const GLcontext *ctx,
307 GLuint n, const GLint x[], const GLint y[],
308 const GLchan rgba[4], const GLubyte mask[])
309 {
310 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
311 ggi_color rgb;
312 ggi_pixel col;
313
314 rgb.r = (uint16)(rgba[RCOMP]) << SHIFT;
315 rgb.g = (uint16)(rgba[GCOMP]) << SHIFT;
316 rgb.b = (uint16)(rgba[BCOMP]) << SHIFT;
317 col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
318
319 while (n--) {
320 if (*mask++)
321 ggiPutPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), col);
322 x++;
323 y++;
324 }
325 }
326
327 /**********************************************************************/
328 /***** Read arrays of pixels *****/
329 /**********************************************************************/
330
331 void GGIread_ci32_pixels( const GLcontext *ctx,
332 GLuint n, const GLint x[], const GLint y[],
333 GLuint ci[], const GLubyte mask[])
334 {
335 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
336 while (n--) {
337 if (*mask++)
338 ggiGetPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), ci);
339 ci++;
340 x++;
341 y++;
342 }
343 }
344
345 void GGIread_rgba_pixels( const GLcontext *ctx,
346 GLuint n, const GLint x[], const GLint y[],
347 GLubyte rgba[][4],
348 const GLubyte mask[] )
349 {
350 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
351 ggi_color rgb;
352 ggi_pixel col;
353
354 while (n--)
355 {
356 if (*mask++)
357 {
358 ggiGetPixel(ggi_ctx->ggi_visual, *x, FLIP(*y), &col);
359 ggiUnmapPixel(ggi_ctx->ggi_visual, col, &rgb);
360 rgba[0][RCOMP] = rgb.r >> SHIFT;
361 rgba[0][GCOMP] = rgb.g >> SHIFT;
362 rgba[0][BCOMP] = rgb.b >> SHIFT;
363 rgba[0][ACOMP] = 0;
364 }
365 x++;
366 y++;
367 rgba++;
368 }
369 }
370
371 int GGIextend_visual(ggi_visual_t vis)
372 {
373 return 0;
374 }
375
376 //static swrast_tri_func ggimesa_stubs_get_triangle_func(GLcontext *ctx);
377
378 int GGIsetup_driver(ggi_mesa_context_t ggi_ctx)
379 {
380 struct swrast_device_driver *swdd =
381 _swrast_GetDeviceDriverReference(ggi_ctx->gl_ctx);
382
383 GGIMESADPRINT_CORE("stubs: setup_driver\n");
384
385 swdd->WriteRGBASpan = GGIwrite_rgba_span;
386 swdd->WriteRGBSpan = GGIwrite_rgb_span;
387 swdd->WriteMonoRGBASpan = GGIwrite_mono_rgba_span;
388 swdd->WriteRGBAPixels = GGIwrite_rgba_pixels;
389 swdd->WriteMonoRGBAPixels = GGIwrite_mono_rgba_pixels;
390
391 swdd->WriteCI32Span = GGIwrite_ci32_span;
392 swdd->WriteCI8Span = GGIwrite_ci8_span;
393 swdd->WriteMonoCISpan = GGIwrite_mono_ci_span;
394 swdd->WriteCI32Pixels = GGIwrite_ci32_pixels;
395 swdd->WriteMonoCIPixels = GGIwrite_mono_ci_pixels;
396
397 swdd->ReadCI32Span = GGIread_ci32_span;
398 swdd->ReadRGBASpan = GGIread_rgba_span;
399 swdd->ReadCI32Pixels = GGIread_ci32_pixels;
400 swdd->ReadRGBAPixels = GGIread_rgba_pixels;
401
402 return 0;
403 }
404
405 void GGIupdate_state(ggi_mesa_context_t *ctx)
406 {
407 //ctx->Driver.TriangleFunc = _swsetup_Triangle;
408 }
409
410 /*
411 void GGItriangle_flat(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1, const SWvertex *v2)
412 {
413 //#define INTERP_Z 1
414 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
415
416 #define SETUP_CODE \
417 ggi_color color; \
418 color.r = v0->color[0]; \
419 color.g = v0->color[1]; \
420 color.b = v0->color[2]; \
421 color.a = v0->color[3]; \
422 ggiSetGCForeground(VIS, ggiMapColor(VIS, &color));
423
424 #define INNER_LOOP(LEFT,RIGHT,Y) \
425 ggiDrawHLine(VIS,LEFT,FLIP(Y),RIGHT-LEFT);
426
427 #include "swrast/s_tritemp.h"
428 }
429
430
431 static void GGItriangle_flat_depth(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1, const SWvertex *v2)
432 {
433 #define INTERP_Z 1
434 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
435
436 #define SETUP_CODE \
437 ggi_color color; \
438 color.r = v0->color[0]; \
439 color.g = v0->color[1]; \
440 color.b = v0->color[2]; \
441 color.a = v0->color[3]; \
442 ggiSetGCForeground(VIS, ggiMapColor(VIS, &color));
443
444 #define INNER_LOOP(LEFT,RIGHT,Y) \
445 { \
446 GLint i,xx=LEFT,yy=FLIP(Y),n=RIGHT-LEFT,length=0; \
447 GLint startx=xx; \
448 for (i=0;i<n;i++){ \
449 GLdepth z=FixedToDepth(ffz); \
450 if (z<zRow[i]) \
451 { \
452 zRow[i]=z; \
453 length++; \
454 } \
455 else \
456 { \
457 if (length) \
458 { \
459 ggiDrawHLine(VIS,startx,yy,length); \
460 length=0; \
461 } \
462 startx=xx+i+1; \
463 } \
464 ffz+=fdzdx; \
465 } \
466 if (length) ggiDrawHLine(VIS,startx,yy,length); \
467 }
468
469 #include "swrast/s_tritemp.h"
470 }
471
472
473 static swrast_tri_func ggimesa_stubs_get_triangle_func(GLcontext *ctx)
474 {
475 if (ctx->Stencil._Enabled) return NULL;
476 if (ctx->Polygon.SmoothFlag) return NULL;
477 if (ctx->Polygon.StippleFlag) return NULL;
478 if (ctx->Texture._ReallyEnabled) return NULL;
479 if (ctx->Light.ShadeModel==GL_SMOOTH) return NULL;
480 if (ctx->Depth.Test && ctx->Depth.Func != GL_LESS) return NULL;
481
482 if (ctx->Depth.Test)
483 return GGItriangle_flat_depth;
484
485 return GGItriangle_flat;
486 }
487 */
488 static int GGIopen(ggi_visual_t vis, struct ggi_dlhandle *dlh,
489 const char *args, void *argptr, uint32 *dlret)
490 {
491 LIBGGI_MESAEXT(vis)->update_state = GGIupdate_state;
492 LIBGGI_MESAEXT(vis)->setup_driver = GGIsetup_driver;
493
494 *dlret = GGI_DL_OPDRAW;
495 return 0;
496 }
497
498 int MesaGGIdl_stubs(int func, void **funcptr)
499 {
500 switch (func) {
501 case GGIFUNC_open:
502 *funcptr = GGIopen;
503 return 0;
504 case GGIFUNC_exit:
505 case GGIFUNC_close:
506 *funcptr = NULL;
507 return 0;
508 default:
509 *funcptr = NULL;
510 }
511 return GGI_ENOTFOUND;
512 }