| /* $Id: gears.c,v 1.2 1999/08/21 08:53:27 jtaylor Exp $ */ | |||||
| /* $Id: gears.c,v 1.3 1999/08/22 08:56:50 jtaylor Exp $ */ | |||||
| /* | /* | ||||
| * 3-D gear wheels. This program is in the public domain. | * 3-D gear wheels. This program is in the public domain. | ||||
| view_rotz -= 5.0; | view_rotz -= 5.0; | ||||
| break; | break; | ||||
| case 27: /* Escape */ | case 27: /* Escape */ | ||||
| exit(0); | |||||
| exit(0); /* FIXME: Shutdown and free resources cleanly in ggiglut */ | |||||
| break; | break; | ||||
| default: | default: | ||||
| return; | return; | ||||
| int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||||
| { | { | ||||
| glutInit(&argc, argv); | |||||
| glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); | |||||
| glutInitWindowPosition(0, 0); | |||||
| glutInitWindowSize(300, 300); | |||||
| glutCreateWindow("Gears"); | |||||
| init(); | |||||
| glutDisplayFunc(draw); | |||||
| glutReshapeFunc(reshape); | |||||
| glutKeyboardFunc(key); | |||||
| glutSpecialFunc(special); | |||||
| glutVisibilityFunc(visible); | |||||
| glutMainLoop(); | |||||
| return 0; /* ANSI C requires main to return int. */ | |||||
| glutInit(&argc, argv); | |||||
| glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); | |||||
| // glutInitWindowPosition(0, 0); | |||||
| // glutInitWindowSize(300, 300); | |||||
| glutCreateWindow("Gears"); | |||||
| init(); | |||||
| glutDisplayFunc(draw); | |||||
| glutReshapeFunc(reshape); | |||||
| glutKeyboardFunc(key); | |||||
| glutSpecialFunc(special); | |||||
| glutVisibilityFunc(visible); | |||||
| glutMainLoop(); | |||||
| return 0; | |||||
| } | } |
| static GGIMesaContext __glut_ctx; | static GGIMesaContext __glut_ctx; | ||||
| static int __glut_width = WIDTH; | |||||
| static int __glut_height = HEIGHT; | |||||
| static ggi_graphtype __glut_gt_rgb = GRAPHTYPE_RGB; | |||||
| static ggi_graphtype __glut_gt_index = GRAPHTYPE_INDEX; | |||||
| //static int __glut_width = WIDTH; | |||||
| //static int __glut_height = HEIGHT; | |||||
| //static ggi_graphtype __glut_gt_rgb = GRAPHTYPE_RGB; | |||||
| //static ggi_graphtype __glut_gt_index = GRAPHTYPE_INDEX; | |||||
| static int __glut_width = GGI_AUTO; | |||||
| static int __glut_height = GGI_AUTO; | |||||
| static ggi_graphtype __glut_gt_rgb = GT_AUTO; | |||||
| static ggi_graphtype __glut_gt_index = GT_8BIT; | |||||
| static int __glut_init = GL_FALSE; | static int __glut_init = GL_FALSE; | ||||
| static int mousex = WIDTH / 2; | static int mousex = WIDTH / 2; | ||||
| vfprintf(stderr, format, args); | vfprintf(stderr, format, args); | ||||
| va_end(args); | va_end(args); | ||||
| } | } | ||||
| } | } | ||||
| void glutInit(int *argc, char **argv) | void glutInit(int *argc, char **argv) | ||||
| case 24: gt = GT_24BIT; break; | case 24: gt = GT_24BIT; break; | ||||
| case 32: gt = GT_32BIT; break; | case 32: gt = GT_32BIT; break; | ||||
| default: | default: | ||||
| glut_ggiDEBUG("\"%s\" bits per pixel?\n", | |||||
| argv[i+1]); | |||||
| exit(1); | |||||
| ggiPanic("\"%s\" bits per pixel?\n", argv[i+1]); | |||||
| } | } | ||||
| __glut_gt_rgb = __glut_gt_index = gt; | __glut_gt_rgb = __glut_gt_index = gt; | ||||
| REMOVE; | REMOVE; | ||||
| else | else | ||||
| if (strcmp(argv[i], "-size") == 0 && (i + 2) < (*argc)) | if (strcmp(argv[i], "-size") == 0 && (i + 2) < (*argc)) | ||||
| { | { | ||||
| __glut_width=atoi(argv[i+1]); | |||||
| __glut_height=atoi(argv[i+2]); | |||||
| __glut_width = atoi(argv[i + 1]); | |||||
| __glut_height = atoi(argv[i + 2]); | |||||
| REMOVE; | REMOVE; | ||||
| REMOVE; | REMOVE; | ||||
| REMOVE; | REMOVE; | ||||
| } | } | ||||
| } | } | ||||
| if (ggiInit()<0) | |||||
| if (ggiInit() < 0) | |||||
| { | { | ||||
| ggiPanic("ggiInit() failed!\n"); | ggiPanic("ggiInit() failed!\n"); | ||||
| } | } | ||||
| __glut_init=GL_TRUE; | |||||
| __glut_init = GL_TRUE; | |||||
| #undef REMOVE | |||||
| #undef REMOVE | |||||
| } | } | ||||
| void glutInitWindowPosition(int x, int y) | void glutInitWindowPosition(int x, int y) | ||||
| ggiPanic("GGIMesaSetVisual failed!\n"); | ggiPanic("GGIMesaSetVisual failed!\n"); | ||||
| } | } | ||||
| __glut_width = mode.visible.x; | |||||
| __glut_height = mode.visible.y; | |||||
| mousex = mode.visible.x / 2; | |||||
| mousey = mode.visible.y / 2; | |||||
| GGIMesaMakeCurrent(__glut_ctx); | GGIMesaMakeCurrent(__glut_ctx); | ||||
| if (__glut_reshape) | if (__glut_reshape) | ||||
| __glut_reshape(__glut_width, __glut_height); | __glut_reshape(__glut_width, __glut_height); | ||||
| return GL_TRUE; | return GL_TRUE; | ||||
| } | } | ||||
| ggi_event ev; | ggi_event ev; | ||||
| ggi_event_mask evmask = (emKeyPress | emKeyRepeat | emPtrMove | emPtrButton); | ggi_event_mask evmask = (emKeyPress | emKeyRepeat | emPtrMove | emPtrButton); | ||||
| ggiSetEventMask(__glut_vis, evmask); | ggiSetEventMask(__glut_vis, evmask); | ||||
| glutPostRedisplay(); | glutPostRedisplay(); | ||||
| if (__glut_visibility) | if (__glut_visibility) |
| # GGIMesa genkgi helper configuration | # GGIMesa genkgi helper configuration | ||||
| .root: @ggi_libdir@/ggi/mesa/default/ | |||||
| .root: @ggi_libdir@/ggi/mesa/default | |||||
| tgt-fbdev-kgicon-savage4-mesa kgi/savage4.so | |||||
| tgt-fbdev-kgicon-d3dim-mesa d3dim.so |
| /* $Id: genkgi.h,v 1.2 1999/08/21 22:36:52 jtaylor Exp $ | |||||
| /* $Id: genkgi.h,v 1.3 1999/08/22 08:56:50 jtaylor Exp $ | |||||
| ****************************************************************************** | ****************************************************************************** | ||||
| GGIMesa - KGIcon specific overrides for fbcon-mesa | GGIMesa - KGIcon specific overrides for fbcon-mesa | ||||
| ****************************************************************************** | ****************************************************************************** | ||||
| */ | */ | ||||
| #ifndef _GENKGI_MESA_H | |||||
| #define _GENKGI_MESA_H | |||||
| #undef KGI_USE_PPBUFS | |||||
| #include <unistd.h> | |||||
| #include <sys/mman.h> | |||||
| #include <ggi/internal/ggi-dl.h> | #include <ggi/internal/ggi-dl.h> | ||||
| #include <ggi/mesa/display_fbdev.h> | #include <ggi/mesa/display_fbdev.h> | ||||
| #include <kgi/kgi.h> | |||||
| //ggifunc_setmode GGIMesa_genkgi_setmode; | |||||
| ggifunc_getapi GGIMesa_genkgi_getapi; | |||||
| #ifndef MAP_FAILED | |||||
| #define MAP_FAILED ((void *)-1) | |||||
| #endif | |||||
| typedef struct genkgi_hook_mesa | |||||
| /* FIXME: LibGGI needs to export its genkgi.h */ | |||||
| struct genkgi_priv | |||||
| { | |||||
| ggi_gc *mapped_gc; | |||||
| unsigned int gc_size; | |||||
| ggifunc_drawline *drawline; | |||||
| ggifunc_drawbox *drawbox; | |||||
| ggifunc_fillscreen *fillscreen; | |||||
| int fd_gc; | |||||
| int close_gc; | |||||
| int fd_kgicommand; | |||||
| uint8 *mapped_kgicommand; | |||||
| uint8 *kgicommand_ptr; | |||||
| unsigned int kgicommand_buffersize; | |||||
| }; | |||||
| #define GENKGI_PRIV(vis) ((struct genkgi_priv *)FBDEV_PRIV(vis)->accelpriv) | |||||
| extern ggifunc_getapi GGIMesa_genkgi_getapi; | |||||
| extern ggifunc_flush GGIMesa_genkgi_flush; | |||||
| struct genkgi_priv_mesa | |||||
| { | { | ||||
| char accel[100]; | char accel[100]; | ||||
| int have_accel; | int have_accel; | ||||
| void *accelpriv; | |||||
| } genkgi_hook_mesa; | |||||
| void *accelpriv; /* Private data of subdrivers */ | |||||
| struct genkgi_priv *oldpriv; /* LibGGI's private data */ | |||||
| }; | |||||
| #define GENKGI_PRIV_MESA(vis) ((struct genkgi_priv_mesa *)FBDEV_PRIV_MESA(vis)->accelpriv) | |||||
| #define GENKGI_PRIVATE(vis) ((genkgi_hook_mesa *)FBDEV_PRIV_MESA(vis)->accelpriv) | |||||
| #endif /* _GENKHI_MESA_H */ |
| /* $Id: genkgi_mode.c,v 1.2 1999/08/21 22:36:52 jtaylor Exp $ | |||||
| /* $Id: genkgi_mode.c,v 1.3 1999/08/22 08:56:50 jtaylor Exp $ | |||||
| ****************************************************************************** | ****************************************************************************** | ||||
| display-fbdev-kgicon-generic-mesa | display-fbdev-kgicon-generic-mesa | ||||
| int GGIMesa_genkgi_getapi(ggi_visual *vis, int num, char *apiname, char *arguments) | int GGIMesa_genkgi_getapi(ggi_visual *vis, int num, char *apiname, char *arguments) | ||||
| { | { | ||||
| genkgi_hook_mesa *priv = GENKGI_PRIVATE(vis); | |||||
| struct genkgi_priv_mesa *priv = GENKGI_PRIV_MESA(vis); | |||||
| gl_ggiDEBUG("Entered mesa_genkgi_getapi, num=%d\n", num); | gl_ggiDEBUG("Entered mesa_genkgi_getapi, num=%d\n", num); | ||||
| } | } | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| int GGIMesa_genkgi_flush(ggi_visual *vis, int x, int y, int w, int h, int tryflag) | |||||
| { | |||||
| struct genkgi_priv_mesa *priv = GENKGI_PRIV_MESA(vis); | |||||
| int junkval; // There must be a better way to do this | |||||
| priv->oldpriv->kgicommand_ptr += getpagesize(); | |||||
| (kgiu32)(priv->oldpriv->kgicommand_ptr) &= 0xfffff000; | |||||
| junkval = *((int *)(priv->oldpriv->kgicommand_ptr)); | |||||
| /* Check if we are now in the last page, and reset the | |||||
| * FIFO if so. We can't use the last page to send | |||||
| * more commands, since there's no page after it that | |||||
| * we can touch to fault in the last page's commands. | |||||
| * | |||||
| * FIXME: This will be replaced with a flush-and-reset handler | |||||
| * on the end-of-buffer pagefault at some point.... | |||||
| * | |||||
| */ | |||||
| if ((priv->oldpriv->kgicommand_ptr - priv->oldpriv->mapped_kgicommand) | |||||
| >= (priv->oldpriv->kgicommand_buffersize - getpagesize())) | |||||
| { | |||||
| gl_ggiDEBUG("Hit end of FIFO, attempting remap"); | |||||
| munmap(priv->oldpriv->mapped_kgicommand, priv->oldpriv->kgicommand_buffersize); | |||||
| gl_ggiDEBUG("Passed munmap"); | |||||
| if ((priv->oldpriv->mapped_kgicommand = | |||||
| mmap(NULL, | |||||
| priv->oldpriv->kgicommand_buffersize, | |||||
| PROT_READ | PROT_WRITE, | |||||
| MAP_SHARED, | |||||
| priv->oldpriv->fd_kgicommand, | |||||
| 0)) == MAP_FAILED) | |||||
| { | |||||
| ggiPanic("Failed to remap kgicommand!"); | |||||
| } | |||||
| gl_ggiDEBUG("Passed mmap"); | |||||
| priv->oldpriv->kgicommand_ptr = priv->oldpriv->mapped_kgicommand; | |||||
| gl_ggiDEBUG("Passed kgicommand_ptr reset"); | |||||
| } | |||||
| return 0; | |||||
| } |
| /* $Id: genkgi_visual.c,v 1.3 1999/08/21 22:46:13 jtaylor Exp $ | |||||
| /* $Id: genkgi_visual.c,v 1.4 1999/08/22 08:56:50 jtaylor Exp $ | |||||
| ****************************************************************************** | ****************************************************************************** | ||||
| genkgi_visual.c: visual handling for the generic KGI helper | genkgi_visual.c: visual handling for the generic KGI helper | ||||
| static accel_info accel_strings[] = | static accel_info accel_strings[] = | ||||
| { | { | ||||
| { 0, "savage4" }, /* S3 Savage4 */ | |||||
| { 0, "d3dim" }, /* Direct3D Immedaite Mode */ | |||||
| }; | }; | ||||
| #define NUM_ACCELS (sizeof(accel_strings)/sizeof(accel_info)) | #define NUM_ACCELS (sizeof(accel_strings)/sizeof(accel_info)) | ||||
| int GGIdlinit(ggi_visual *vis, const char *args, void *argptr) | int GGIdlinit(ggi_visual *vis, const char *args, void *argptr) | ||||
| { | { | ||||
| genkgi_hook_mesa *priv; | |||||
| struct genkgi_priv_mesa *priv; | |||||
| char libname[256], libargs[256]; | char libname[256], libargs[256]; | ||||
| int id, err; | int id, err; | ||||
| struct stat junk; | struct stat junk; | ||||
| gl_ggiDEBUG("display-fbdev-kgicon-mesa: GGIdlinit start\n"); | gl_ggiDEBUG("display-fbdev-kgicon-mesa: GGIdlinit start\n"); | ||||
| GENKGI_PRIVATE(vis) = priv = malloc(sizeof(genkgi_hook_mesa)); | |||||
| GENKGI_PRIV_MESA(vis) = priv = malloc(sizeof(struct genkgi_priv_mesa)); | |||||
| if (priv == NULL) | if (priv == NULL) | ||||
| { | { | ||||
| fprintf(stderr, "Failed to allocate genkgi_hook!\n"); | |||||
| fprintf(stderr, "Failed to allocate genkgi private data\n"); | |||||
| return GGI_DL_ERROR; | return GGI_DL_ERROR; | ||||
| } | } | ||||
| priv->oldpriv = GENKGI_PRIV(vis); | |||||
| #if 0 | |||||
| err = ggLoadConfig(conffile, &_configHandle); | err = ggLoadConfig(conffile, &_configHandle); | ||||
| if (err != GGI_OK) | if (err != GGI_OK) | ||||
| { | { | ||||
| return err; | return err; | ||||
| } | } | ||||
| /* Hack city here. We need to probe the KGI driver properly to discover | |||||
| * the acceleration type. | |||||
| /* Hack city here. We need to probe the KGI driver properly for | |||||
| * suggest-strings to discover the acceleration type(s). | |||||
| */ | */ | ||||
| priv->have_accel = 0; | priv->have_accel = 0; | ||||
| #if 0 | |||||
| if (stat("/proc/savage4", &junk) == 0) | |||||
| #if 1 | |||||
| if (stat("/proc/gfx0", &junk) == 0) | |||||
| { | { | ||||
| sprintf(priv->accel, "%s%s", accel_prefix, "savage4"); | |||||
| sprintf(priv->accel, "%s%s", accel_prefix, "d3dim"); | |||||
| priv->have_accel = 1; | priv->have_accel = 1; | ||||
| gl_ggiDEBUG("display-fbdev-kgicon-mesa: Using accel: \"%s\"\n", priv->accel); | gl_ggiDEBUG("display-fbdev-kgicon-mesa: Using accel: \"%s\"\n", priv->accel); | ||||
| } | } | ||||
| #endif | |||||
| /* Mode management */ | /* Mode management */ | ||||
| vis->opdisplay->getapi = GGIMesa_genkgi_getapi; | |||||
| vis->opdisplay->getapi = GGIMesa_genkgi_getapi; | |||||
| ggiIndicateChange(vis, GGI_CHG_APILIST); | ggiIndicateChange(vis, GGI_CHG_APILIST); | ||||
| #endif | |||||
| /* Give the accel sublibs a chance to set up a driver */ | /* Give the accel sublibs a chance to set up a driver */ | ||||
| if (priv->have_accel == 1) | if (priv->have_accel == 1) | ||||
| (LIBGGI_MESAEXT(vis)->setup_driver == NULL)) | (LIBGGI_MESAEXT(vis)->setup_driver == NULL)) | ||||
| vis->opdisplay->getapi = oldgetapi; | vis->opdisplay->getapi = oldgetapi; | ||||
| } | } | ||||
| #endif | |||||
| LIBGGI_MESAEXT(vis)->update_state = genkgi_update_state; | |||||
| LIBGGI_MESAEXT(vis)->setup_driver = genkgi_setup_driver; | |||||
| gl_ggiDEBUG("display-fbdev-kgicon-mesa: GGIdlinit finished\n"); | gl_ggiDEBUG("display-fbdev-kgicon-mesa: GGIdlinit finished\n"); | ||||
| return 0; | return 0; |
| /* $Id: fbdev_mode.c,v 1.2 1999/08/21 22:46:13 jtaylor Exp $ | |||||
| /* $Id: fbdev_mode.c,v 1.3 1999/08/22 08:56:50 jtaylor Exp $ | |||||
| ****************************************************************************** | ****************************************************************************** | ||||
| display-fbdev-mesa | display-fbdev-mesa | ||||
| int GGIMesa_fbdev_getapi(ggi_visual *vis, int num, char *apiname, char *arguments) | int GGIMesa_fbdev_getapi(ggi_visual *vis, int num, char *apiname, char *arguments) | ||||
| { | { | ||||
| fbdev_hook_mesa *priv = GGIMESA_PRIVATE(vis); | |||||
| struct fbdev_priv_mesa *priv = GGIMESA_PRIVATE(vis); | |||||
| strcpy(arguments, ""); | strcpy(arguments, ""); | ||||
| static int do_setmode(ggi_visual *vis) | static int do_setmode(ggi_visual *vis) | ||||
| { | { | ||||
| fbdev_hook_mesa *priv = GGIMESA_PRIVATE(vis); | |||||
| struct fbdev_priv_mesa *priv = GGIMESA_PRIVATE(vis); | |||||
| int err, id; | int err, id; | ||||
| char libname[256], libargs[256]; | char libname[256], libargs[256]; | ||||
| ggi_graphtype gt; | ggi_graphtype gt; |
| /* $Id: fbdev_visual.c,v 1.2 1999/08/21 22:46:13 jtaylor Exp $ | |||||
| /* $Id: fbdev_visual.c,v 1.3 1999/08/22 08:56:50 jtaylor Exp $ | |||||
| ****************************************************************************** | ****************************************************************************** | ||||
| display-fbdev-mesa: visual handling | display-fbdev-mesa: visual handling | ||||
| int GGIdlinit(ggi_visual *vis, const char *args, void *argptr) | int GGIdlinit(ggi_visual *vis, const char *args, void *argptr) | ||||
| { | { | ||||
| fbdev_hook_mesa *priv; | |||||
| struct fbdev_priv_mesa *priv; | |||||
| char libname[256], libargs[256]; | char libname[256], libargs[256]; | ||||
| int id, err; | int id, err; | ||||
| ggifunc_getapi *oldgetapi; | ggifunc_getapi *oldgetapi; | ||||
| gl_ggiDEBUG("display-fbdev-mesa: GGIdlinit start\n"); | gl_ggiDEBUG("display-fbdev-mesa: GGIdlinit start\n"); | ||||
| GGIMESA_PRIVATE(vis) = priv = malloc(sizeof(fbdev_hook_mesa)); | |||||
| GGIMESA_PRIVATE(vis) = priv = malloc(sizeof(struct fbdev_priv_mesa)); | |||||
| if (priv == NULL) { | if (priv == NULL) { | ||||
| fprintf(stderr, "Failed to allocate fbdev_hook!\n"); | |||||
| fprintf(stderr, "Failed to allocate fbdev private data\n"); | |||||
| return GGI_DL_ERROR; | return GGI_DL_ERROR; | ||||
| } | } | ||||
| ggifunc_setmode GGIMesa_fbdev_setmode; | ggifunc_setmode GGIMesa_fbdev_setmode; | ||||
| ggifunc_getapi GGIMesa_fbdev_getapi; | ggifunc_getapi GGIMesa_fbdev_getapi; | ||||
| #define FBDEV_PRIV_MESA(vis) ((fbdev_hook_mesa *)(FBDEV_PRIV(vis)->accelpriv)) | |||||
| #define FBDEV_PRIV_MESA(vis) ((struct fbdev_priv_mesa *)(FBDEV_PRIV(vis)->accelpriv)) | |||||
| typedef struct fbdev_hook_mesa | |||||
| struct fbdev_priv_mesa | |||||
| { | { | ||||
| char *accel; | char *accel; | ||||
| int have_accel; | int have_accel; | ||||
| void *accelpriv; | void *accelpriv; | ||||
| fbdev_hook *oldpriv; // Hooks back to the LibGGI fbdev target's private data | fbdev_hook *oldpriv; // Hooks back to the LibGGI fbdev target's private data | ||||
| } fbdev_hook_mesa; | |||||
| }; | |||||
| #endif /* _GGIMESA_DISPLAY_FBDEV_H */ | #endif /* _GGIMESA_DISPLAY_FBDEV_H */ |