Header file clean-up:
[mesa.git] / src / mesa / drivers / ggi / ggimesa.c
1 /* GGI-Driver for MESA
2 *
3 * Copyright (C) 1997-1998 Uwe Maurer - uwe_maurer@t-online.de
4 * 2002 Filip Spacek
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 * This code was derived from the following source of information:
21 *
22 * svgamesa.c and ddsample.c by Brian Paul
23 *
24 */
25
26 #ifdef HAVE_CONFIG_H
27 #include "conf.h"
28 #endif
29
30 #include <ggi/mesa/ggimesa_int.h>
31 #include <ggi/mesa/debug.h>
32 #include "extensions.h"
33 #include "imports.h"
34 #include "matrix.h"
35 #include "swrast/swrast.h"
36 #include "swrast_setup/swrast_setup.h"
37 #include "tnl/tnl.h"
38 #include "tnl/t_context.h"
39 #include "tnl/t_pipeline.h"
40 #include "array_cache/acache.h"
41 #include "texformat.h"
42 #include "texstore.h"
43
44 ggi_extid ggiMesaID = -1;
45 static int _ggimesaLibIsUp = 0;
46 static void *_ggimesaConfigHandle;
47
48 static char ggimesaconffile[] = GGIMESACONFFILE;
49
50 int _ggimesaDebugSync = 0;
51 uint32 _ggimesaDebugState = 0;
52
53 static void gl_ggiUpdateState(GLcontext *ctx, GLuint new_state);
54 static int changed(ggi_visual_t vis, int whatchanged);
55
56
57 static int _ggi_error(void)
58 {
59 GGIMESADPRINT_CORE("_ggi_error() called\n");
60
61 return -1;
62 }
63
64 static void gl_ggiGetSize(GLframebuffer *fb, GLuint *width, GLuint *height)
65 {
66 /* FIXME: this is a hack to work around the new interface */
67 GLcontext *ctx;
68 ggi_mesa_context_t ggi_ctx;
69 ctx = _mesa_get_current_context();
70 ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
71
72 GGIMESADPRINT_CORE("gl_ggiGetSize() called\n");
73
74 *width = LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.x;
75 *height = LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y;
76 printf("returning %d, %d\n", *width, *height);
77 }
78
79 static void gl_ggiSetIndex(GLcontext *ctx, GLuint ci)
80 {
81 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
82
83 GGIMESADPRINT_CORE("gl_ggiSetIndex() called\n");
84
85 ggiSetGCForeground(ggi_ctx->ggi_visual, ci);
86 ggi_ctx->color = (ggi_pixel)ci;
87 }
88
89 static void gl_ggiSetClearIndex(GLcontext *ctx, GLuint ci)
90 {
91 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
92
93 GGIMESADPRINT_CORE("gl_ggiSetClearIndex() called\n");
94
95 ggiSetGCForeground(ggi_ctx->ggi_visual, ci);
96 ggi_ctx->clearcolor = (ggi_pixel)ci;
97 }
98
99 static void gl_ggiSetClearColor(GLcontext *ctx, const GLfloat color[4])
100 {
101 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
102 ggi_color rgb;
103 ggi_pixel col;
104 GLubyte byteColor[3];
105
106 GGIMESADPRINT_CORE("gl_ggiSetClearColor() called\n");
107
108 CLAMPED_FLOAT_TO_UBYTE(byteColor[0], color[0]);
109 CLAMPED_FLOAT_TO_UBYTE(byteColor[1], color[1]);
110 CLAMPED_FLOAT_TO_UBYTE(byteColor[2], color[2]);
111
112 rgb.r = (uint16)byteColor[0] << SHIFT;
113 rgb.g = (uint16)byteColor[1] << SHIFT;
114 rgb.b = (uint16)byteColor[2] << SHIFT;
115 col = ggiMapColor(ggi_ctx->ggi_visual, &rgb);
116 ggiSetGCForeground(ggi_ctx->ggi_visual, col);
117 ggi_ctx->clearcolor = col;
118 }
119
120 static void gl_ggiClear(GLcontext *ctx, GLbitfield mask, GLboolean all,
121 GLint x, GLint y, GLint width, GLint height)
122 {
123 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
124
125 GGIMESADPRINT_CORE("gl_ggiClear() called\n");
126
127 if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT))
128 {
129 ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->clearcolor);
130
131 if (all)
132 {
133 int w, h;
134 w = LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.x;
135 h = LIBGGI_MODE(ggi_ctx->ggi_visual)->visible.y;
136 ggiDrawBox(ggi_ctx->ggi_visual, 0, 0, w, h);
137 }
138 else
139 {
140 ggiDrawBox(ggi_ctx->ggi_visual, x, y, //FLIP(y),
141 width, height);
142 }
143 ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->color);
144
145 mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT);
146 }
147 _swrast_Clear(ctx, mask, all, x, y, width, height);
148
149 }
150
151
152 /* Set the buffer used for reading */
153 /* XXX support for separate read/draw buffers hasn't been tested */
154 static GLboolean gl_ggiSetBuffer(GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit)
155 {
156 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
157
158 printf("set read %d\n", mode);
159 GGIMESADPRINT_CORE("gl_ggiSetBuffer() called\n");
160
161 if (bufferBit == FRONT_LEFT_BIT)
162 {
163 ggiSetReadFrame(ggi_ctx->ggi_visual,
164 ggiGetDisplayFrame(ggi_ctx->ggi_visual));
165 ggiSetWriteFrame(ggi_ctx->ggi_visual,
166 ggiGetDisplayFrame(ggi_ctx->ggi_visual));
167 return GL_TRUE;
168 }
169 else if (bufferBit == BACK_LEFT_BIT)
170 {
171 ggiSetReadFrame(ggi_ctx->ggi_visual,
172 ggiGetDisplayFrame(ggi_ctx->ggi_visual)?0 : 1);
173 ggiSetWriteFrame(ggi_ctx->ggi_visual,
174 ggiGetDisplayFrame(ggi_ctx->ggi_visual)?0 : 1);
175 return GL_TRUE;
176 }
177 else
178 return GL_FALSE;
179 }
180
181
182 static const GLubyte * gl_ggiGetString(GLcontext *ctx, GLenum name)
183 {
184 GGIMESADPRINT_CORE("gl_ggiGetString() called\n");
185
186 if (name == GL_RENDERER)
187 return (GLubyte *) "Mesa GGI";
188 else
189 return NULL;
190 }
191
192 static void gl_ggiFlush(GLcontext *ctx)
193 {
194 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
195
196 GGIMESADPRINT_CORE("gl_ggiFlush() called\n");
197
198 ggiFlush(ggi_ctx->ggi_visual);
199 }
200
201 static void gl_ggiIndexMask(GLcontext *ctx, GLuint mask)
202 {
203 GGIMESADPRINT_CORE("gl_ggiIndexMask() called\n");
204 }
205
206 static void gl_ggiColorMask(GLcontext *ctx, GLboolean rmask, GLboolean gmask,
207 GLboolean bmask, GLboolean amask)
208 {
209 GGIMESADPRINT_CORE("gl_ggiColorMask() called\n");
210 }
211
212 static void gl_ggiEnable(GLcontext *ctx, GLenum pname, GLboolean state)
213 {
214 GGIMESADPRINT_CORE("gl_ggiEnable() called\n");
215 }
216
217 static void gl_ggiSetupPointers(GLcontext *ctx)
218 {
219 TNLcontext *tnl;
220
221 GGIMESADPRINT_CORE("gl_ggiSetupPointers() called\n");
222
223 /* General information */
224 ctx->Driver.GetString = gl_ggiGetString;
225 ctx->Driver.GetBufferSize = gl_ggiGetSize;
226 ctx->Driver.Finish = gl_ggiFlush;
227 ctx->Driver.Flush = gl_ggiFlush;
228
229 /* Software rasterizer pixel paths */
230 ctx->Driver.Accum = _swrast_Accum;
231 ctx->Driver.Bitmap = _swrast_Bitmap;
232 ctx->Driver.Clear = gl_ggiClear;
233 ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
234 ctx->Driver.CopyPixels = _swrast_CopyPixels;
235 ctx->Driver.DrawPixels = _swrast_DrawPixels;
236 ctx->Driver.ReadPixels = _swrast_ReadPixels;
237 ctx->Driver.DrawBuffer = _swrast_DrawBuffer;
238
239 /* Software texturing */
240 ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
241 ctx->Driver.TexImage1D = _mesa_store_teximage1d;
242 ctx->Driver.TexImage2D = _mesa_store_teximage2d;
243 ctx->Driver.TexImage3D = _mesa_store_teximage3d;
244 ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
245 ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;
246 ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
247 ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
248
249 ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d;
250 ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d;
251 ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d;
252 ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
253 ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
254 ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
255
256 ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
257 ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
258 ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
259 ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;
260 ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;
261
262 /* Imaging extensions */
263 ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
264 ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
265 ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
266 ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
267
268 /* State change callbacks */
269 ctx->Driver.ClearIndex = gl_ggiSetClearIndex;
270 ctx->Driver.ClearColor = gl_ggiSetClearColor;
271 ctx->Driver.IndexMask = gl_ggiIndexMask;
272 ctx->Driver.ColorMask = gl_ggiColorMask;
273 ctx->Driver.Enable = gl_ggiEnable;
274
275 ctx->Driver.UpdateState = gl_ggiUpdateState;
276
277 /* Initialize TNL driver interface */
278 tnl = TNL_CONTEXT(ctx);
279 tnl->Driver.RunPipeline = _tnl_run_pipeline;
280
281 /* Install setup for tnl */
282 _swsetup_Wakeup(ctx);
283 }
284
285 static void get_mode_info(ggi_visual_t vis, int *r, int *g, int *b,
286 GLboolean *rgb, GLboolean *db, int *ci)
287 {
288 int i;
289
290 *r = 0;
291 *g = 0;
292 *b = 0;
293
294 for(i = 0; i < sizeof(ggi_pixel)*8; ++i){
295 int mask = 1 << i;
296 if(LIBGGI_PIXFMT(vis)->red_mask & mask)
297 ++(*r);
298 if(LIBGGI_PIXFMT(vis)->green_mask & mask)
299 ++(*g);
300 if(LIBGGI_PIXFMT(vis)->blue_mask & mask)
301 ++(*b);
302 }
303
304 *rgb = GT_SCHEME(LIBGGI_MODE(vis)->graphtype) == GT_TRUECOLOR;
305 *db = LIBGGI_MODE(vis)->frames > 1;
306 *ci = GT_SIZE(LIBGGI_MODE(vis)->graphtype);
307
308 printf("rgb (%d, %d, %d) db %d, rgb %d ci %d\n",*r,*g,*b,*db,*rgb,*ci);
309 }
310
311 int ggiMesaInit()
312 {
313 int err;
314 char *str;
315
316 GGIMESADPRINT_CORE("ggiMesaInit() called\n");
317
318 str = getenv("GGIMESA_DEBUG");
319 if (str != NULL) {
320 _ggimesaDebugState = atoi(str);
321 GGIMESADPRINT_CORE("Debugging=%d\n", _ggimesaDebugState);
322 }
323
324 str = getenv("GGIMESA_DEBUGSYNC");
325 if (str != NULL) {
326 _ggimesaDebugSync = 1;
327 }
328
329 GGIMESADPRINT_CORE("ggiMesaInit()\n");
330
331 _ggimesaLibIsUp++;
332 if (_ggimesaLibIsUp > 1)
333 return 0; /* Initialize only at first call */
334
335 err = ggLoadConfig(ggimesaconffile, &_ggimesaConfigHandle);
336 if (err != GGI_OK)
337 {
338 GGIMESADPRINT_CORE("GGIMesa: Couldn't open %s\n",
339 ggimesaconffile);
340 _ggimesaLibIsUp--;
341 return err;
342 }
343
344 ggiMesaID = ggiExtensionRegister("GGIMesa",
345 sizeof(struct ggi_mesa_ext), changed);
346
347 if (ggiMesaID < 0)
348 {
349 GGIMESADPRINT_CORE("GGIMesa: failed to register as extension\n");
350 _ggimesaLibIsUp--;
351 ggFreeConfig(_ggimesaConfigHandle);
352 return ggiMesaID;
353 }
354
355 return 0;
356 }
357
358 int ggiMesaExit(void)
359 {
360 int rc;
361
362 GGIMESADPRINT_CORE("ggiMesaExit() called\n");
363
364 if (!_ggimesaLibIsUp)
365 return -1;
366
367 if (_ggimesaLibIsUp > 1)
368 {
369 /* Exit only at last call */
370 _ggimesaLibIsUp--;
371 return 0;
372 }
373
374 rc = ggiExtensionUnregister(ggiMesaID);
375 ggFreeConfig(_ggimesaConfigHandle);
376
377 _ggimesaLibIsUp = 0;
378
379 return rc;
380 }
381
382 int ggiMesaAttach(ggi_visual_t vis)
383 {
384 int rc;
385
386 GGIMESADPRINT_CORE("ggiMesaAttach() called\n");
387
388 rc = ggiExtensionAttach(vis, ggiMesaID);
389 if (rc == 0)
390 {
391 int r, g, b, ci;
392 GLboolean rgb, db;
393 GLvisual *gl_visual;
394 GLframebuffer *gl_fb;
395
396 /* We are creating the primary instance */
397 memset(LIBGGI_MESAEXT(vis), 0, sizeof(struct ggi_mesa_ext));
398 LIBGGI_MESAEXT(vis)->update_state = (void *)_ggi_error;
399 LIBGGI_MESAEXT(vis)->setup_driver = (void *)_ggi_error;
400
401 /* Initialize default mesa visual */
402 get_mode_info(vis, &r, &g, &b, &rgb, &db, &ci);
403 gl_visual = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual);
404 _mesa_initialize_visual(gl_visual,
405 rgb, db, 0 /* No stereo */,
406 r, g, b, 0 /* No alpha */, ci,
407 0 /* No depth */, 0 /* No stencil */,
408 0, 0, 0, 0 /* No accum */, 0);
409
410 /* Now fake an "API change" so the right libs get loaded */
411 changed(vis, GGI_CHG_APILIST);
412 }
413
414 return rc;
415 }
416
417 int ggiMesaDetach(ggi_visual_t vis)
418 {
419 GGIMESADPRINT_CORE("ggiMesaDetach() called\n");
420
421 return ggiExtensionDetach(vis, ggiMesaID);
422 }
423
424 int ggiMesaExtendVisual(ggi_visual_t vis, GLboolean alpha_flag,
425 GLboolean stereo_flag, GLint depth_size,
426 GLint stencil_size, GLint accum_red_size,
427 GLint accum_green_size, GLint accum_blue_size,
428 GLint accum_alpha_size, GLint num_samples)
429 {
430 GLvisual *gl_vis = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual);
431 int r, g, b, ci;
432 GLboolean db, rgb;
433
434 get_mode_info(vis, &r, &g, &b, &rgb, &db, &ci);
435
436 /* Initialize the visual with the provided information */
437 _mesa_initialize_visual(&(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual),
438 rgb, db, stereo_flag,
439 r, g, b, 0 /* FIXME */, ci,
440 depth_size, stencil_size,
441 accum_red_size, accum_green_size,
442 accum_blue_size, accum_alpha_size, 0);
443
444 /* Now fake an "API change" so the right libs get loaded. After all,
445 extending the visual by all these new buffers could be considered
446 a "mode change" which requires an "API change".
447 */
448 changed(vis, GGI_CHG_APILIST);
449
450 return 0;
451 }
452
453
454 ggi_mesa_context_t ggiMesaCreateContext(ggi_visual_t vis)
455 {
456 ggi_mesa_context_t ctx;
457 int err;
458 ggi_color pal[256];
459 int i;
460
461 GGIMESADPRINT_CORE("ggiMesaCreateContext() called\n");
462
463 ctx = (ggi_mesa_context_t)malloc(sizeof(struct ggi_mesa_context));
464 if (!ctx)
465 return NULL;
466
467 ctx->ggi_visual = vis;
468 ctx->color = 0;
469
470 ctx->gl_ctx =
471 _mesa_create_context(&(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual),
472 NULL, (void *) ctx, GL_FALSE);
473 if (!ctx->gl_ctx)
474 goto free_context;
475
476 _mesa_enable_sw_extensions(ctx->gl_ctx);
477
478 _swrast_CreateContext(ctx->gl_ctx);
479 _ac_CreateContext(ctx->gl_ctx);
480 _tnl_CreateContext(ctx->gl_ctx);
481 _swsetup_CreateContext(ctx->gl_ctx);
482
483 gl_ggiSetupPointers(ctx->gl_ctx);
484
485 /* Make sure that an appropriate sublib has been loaded */
486 if (!LIBGGI_MESAEXT(ctx->ggi_visual)->setup_driver){
487 GGIMESADPRINT_CORE("setup_driver==NULL!\n");
488 GGIMESADPRINT_CORE("Please check your config files!\n");
489 goto free_context;
490 }
491
492 /* Set up the sublib driver */
493 err = LIBGGI_MESAEXT(ctx->ggi_visual)->setup_driver(ctx);
494 if (err){
495 GGIMESADPRINT_CORE("setup_driver failed (err = %d)", err);
496 goto free_gl_context;
497 }
498
499 return ctx;
500
501 free_gl_context:
502 _mesa_destroy_context(ctx->gl_ctx);
503 free_context:
504 free(ctx);
505
506 return NULL;
507 }
508
509 void ggiMesaDestroyContext(ggi_mesa_context_t ctx)
510 {
511 GGIMESADPRINT_CORE("ggiMesaDestroyContext() called\n");
512
513 if(!ctx)
514 return;
515
516 _mesa_destroy_context(ctx->gl_ctx);
517 free(ctx);
518 }
519
520 void ggiMesaMakeCurrent(ggi_mesa_context_t ctx, ggi_visual_t vis)
521 {
522 GGIMESADPRINT_CORE("ggiMesaMakeCurrent(ctx = %p) called\n", ctx);
523
524 /* FIXME: clean up where are ggi_vis */
525 if (ctx->ggi_visual != vis) {
526 GGIMESADPRINT_CORE("Cannot migrate GL contexts\n");
527 return;
528 }
529
530 _mesa_make_current(ctx->gl_ctx, &LIBGGI_MESAEXT(vis)->mesa_buffer);
531
532 if (ctx->gl_ctx->Viewport.Width == 0)
533 {
534 _mesa_Viewport(0, 0,
535 LIBGGI_MODE(vis)->visible.x,
536 LIBGGI_MODE(vis)->visible.y);
537 ctx->gl_ctx->Scissor.Width = LIBGGI_MODE(vis)->visible.x;
538 ctx->gl_ctx->Scissor.Height = LIBGGI_MODE(vis)->visible.y;
539 }
540 }
541
542
543 /*
544 * Swap front/back buffers for current context if double buffered.
545 */
546 void ggiMesaSwapBuffers(void)
547 {
548 GLcontext *ctx;
549 ggi_mesa_context_t ggi_ctx;
550 ctx = _mesa_get_current_context();
551 ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
552
553 GGIMESADPRINT_CORE("ggiMesaSwapBuffers() called\n");
554
555 _mesa_notifySwapBuffers(ctx);
556 gl_ggiFlush(ctx);
557
558 ggiSetDisplayFrame(ggi_ctx->ggi_visual,
559 !ggiGetDisplayFrame(ggi_ctx->ggi_visual));
560 ggiSetWriteFrame(ggi_ctx->ggi_visual,
561 !ggiGetWriteFrame(ggi_ctx->ggi_visual));
562 ggiSetReadFrame(ggi_ctx->ggi_visual,
563 !ggiGetReadFrame(ggi_ctx->ggi_visual));
564
565 GGIMESADPRINT_CORE("swap disp: %d, write %d\n",
566 ggiGetDisplayFrame(ggi_ctx->ggi_visual),
567 ggiGetWriteFrame(ggi_ctx->ggi_visual));
568 }
569
570 static void gl_ggiUpdateState(GLcontext *ctx, GLuint new_state)
571 {
572 ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx;
573
574 GGIMESADPRINT_CORE("gl_ggiUpdateState() called\n");
575
576 /* Propogate statechange information to swrast and swrast_setup
577 * modules. The GGI driver has no internal GL-dependent state.
578 */
579 _swrast_InvalidateState(ctx, new_state);
580 _swsetup_InvalidateState(ctx, new_state);
581 _tnl_InvalidateState(ctx, new_state);
582
583 if (!LIBGGI_MESAEXT(ggi_ctx->ggi_visual)->update_state) {
584 GGIMESADPRINT_CORE("update_state == NULL!\n");
585 GGIMESADPRINT_CORE("Please check your config files!\n");
586 ggiPanic("");
587 }
588
589 LIBGGI_MESAEXT(ggi_ctx->ggi_visual)->update_state(ggi_ctx);
590 }
591
592 static int changed(ggi_visual_t vis, int whatchanged)
593 {
594 GLcontext *ctx;
595 ctx = _mesa_get_current_context();
596
597 GGIMESADPRINT_CORE("changed() called\n");
598
599 switch (whatchanged)
600 {
601 case GGI_CHG_APILIST:
602 {
603 char api[256];
604 char args[256];
605 int i;
606 const char *fname;
607 ggi_dlhandle *lib;
608 GLvisual *gl_vis=&(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual);
609 GLframebuffer *gl_fb = &(LIBGGI_MESAEXT(vis)->mesa_buffer);
610
611 /* Initialize the framebuffer to provide all necessary
612 buffers in software. The target libraries that are loaded
613 next are free to modify this according to their
614 capabilities.
615 */
616 /* FIXME: if the target changes capabilities we'll leak
617 swrast's memory !!! Need to deallocate first */
618 _mesa_initialize_framebuffer(gl_fb, gl_vis,
619 gl_vis->depthBits > 0,
620 gl_vis->stencilBits > 0,
621 gl_vis->accumRedBits > 0,
622 gl_vis->alphaBits > 0);
623
624 for (i = 0; ggiGetAPI(vis, i, api, args) == 0; i++)
625 {
626 strcat(api, "-mesa");
627 fname = ggMatchConfig(_ggimesaConfigHandle, api, NULL);
628 if (fname == NULL)
629 {
630 /* No special implementation for this sublib */
631 continue;
632 }
633 lib = ggiExtensionLoadDL(vis, fname, args, NULL,
634 GGI_SYMNAME_PREFIX);
635 }
636
637 /* The targets have cleared everything they can do from
638 the framebuffer structure so we provide the rest in sw
639 */
640 _swrast_alloc_buffers(gl_fb);
641
642 break;
643 }
644 }
645 return 0;
646 }
647