sgl

changeset 3:1b6c5dadb460

started hacking the X11 module
author John Tsiombikas <nuclear@siggraph.org>
date Wed, 11 May 2011 09:09:43 +0300
parents e55e71da991d
children 648f8604d2b2
files configure src/sgl.c src/wsys.c src/wsys.h src/wsys_x11.c
diffstat 5 files changed, 119 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/configure	Wed May 11 05:53:26 2011 +0300
     1.2 +++ b/configure	Wed May 11 09:09:43 2011 +0300
     1.3 @@ -7,7 +7,7 @@
     1.4  
     1.5  	echo "/* this file is generated by $0, do not edit */"
     1.6  	for m in $modules; do
     1.7 -		echo "int sgl_register_$m();"
     1.8 +		echo "void sgl_register_$m();"
     1.9  	done
    1.10  
    1.11  	echo
     2.1 --- a/src/sgl.c	Wed May 11 05:53:26 2011 +0300
     2.2 +++ b/src/sgl.c	Wed May 11 09:09:43 2011 +0300
     2.3 @@ -1,11 +1,11 @@
     2.4  #include "sgl.h"
     2.5  
     2.6 +void sgl_register_modules(void);
     2.7 +
     2.8  int sgl_init(void)
     2.9  {
    2.10 -	/*if(wsys_init() <= 0) {
    2.11 -		fprintf(stderr, "no window system modules found\n");
    2.12 -		return -1;
    2.13 -	}*/
    2.14 +	sgl_register_modules();
    2.15 +	sgl_sort_modules();
    2.16  	return 0;
    2.17  }
    2.18  
     3.1 --- a/src/wsys.c	Wed May 11 05:53:26 2011 +0300
     3.2 +++ b/src/wsys.c	Wed May 11 09:09:43 2011 +0300
     3.3 @@ -1,6 +1,10 @@
     3.4  #include <stdio.h>
     3.5  #include "wsys.h"
     3.6  
     3.7 +static struct wsys_module *merge(struct wsys_module *list1, struct wsys_module *list2);
     3.8 +static struct wsys_module *msort(struct wsys_module *list, int count);
     3.9 +
    3.10 +
    3.11  struct wsys_module *wslist;
    3.12  int wscount;
    3.13  
    3.14 @@ -12,6 +16,16 @@
    3.15  	return 0;
    3.16  }
    3.17  
    3.18 +void sgl_sort_modules(void)
    3.19 +{
    3.20 +	wslist = msort(wslist, wscount);
    3.21 +}
    3.22 +
    3.23 +struct wsys_module *sgl_wsys_module(void)
    3.24 +{
    3.25 +	return wslist;
    3.26 +}
    3.27 +
    3.28  #define APPEND(node) \
    3.29  	do { \
    3.30  		if(!res) { \
     4.1 --- a/src/wsys.h	Wed May 11 05:53:26 2011 +0300
     4.2 +++ b/src/wsys.h	Wed May 11 09:09:43 2011 +0300
     4.3 @@ -10,13 +10,14 @@
     4.4  
     4.5  	int (*set_vidmode)(int, int, int);
     4.6  	int (*get_vidmode)(int*, int*, int*);
     4.7 -	int (*window)(int, int, unsigned int);
     4.8 -	void (*close_win)(int);
     4.9 +	int (*create_window)(int, int, unsigned int);
    4.10 +	void (*close_window)(int);
    4.11  
    4.12  	struct wsys_module *next;
    4.13  };
    4.14  
    4.15  int sgl_register_module(struct wsys_module *ws);
    4.16 +void sgl_sort_modules(void);
    4.17  struct wsys_module *sgl_wsys_module(void);
    4.18  
    4.19  void dbg(void);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/wsys_x11.c	Wed May 11 09:09:43 2011 +0300
     5.3 @@ -0,0 +1,97 @@
     5.4 +#include <X11/Xlib.h>
     5.5 +#include <GL/glx.h>
     5.6 +#include "wsys.h"
     5.7 +
     5.8 +struct window {
     5.9 +	Window win;
    5.10 +	GLXContext ctx;
    5.11 +	struct window *next;
    5.12 +};
    5.13 +
    5.14 +static int init(void);
    5.15 +static void shutdown(void);
    5.16 +static int set_vidmode(int xsz, int ysz, int bpp);
    5.17 +static int get_vidmode(int *xsz, int *ysz, int *bpp);
    5.18 +static int create_window(int xsz, int ysz, unsigned int flags);
    5.19 +static void close_window(int id);
    5.20 +
    5.21 +static struct wsys_module ws = {
    5.22 +	"x11-glx", 0,
    5.23 +	init,
    5.24 +	shutdown,
    5.25 +	set_vidmode,
    5.26 +	get_vidmode,
    5.27 +	create_window,
    5.28 +	close_window,
    5.29 +	0
    5.30 +};
    5.31 +
    5.32 +static Display *dpy;
    5.33 +static int scr;
    5.34 +static struct window *winlist;
    5.35 +
    5.36 +
    5.37 +void sgl_register_x11(void)
    5.38 +{
    5.39 +	sgl_register_module(&ws);
    5.40 +}
    5.41 +
    5.42 +static int init(void)
    5.43 +{
    5.44 +	winlist = 0;
    5.45 +
    5.46 +	if(!(dpy = XOpenDisplay(0))) {
    5.47 +		return -1;
    5.48 +	}
    5.49 +	scr = DefaultScreen(dpy);
    5.50 +
    5.51 +	return 0;
    5.52 +}
    5.53 +
    5.54 +static void shutdown(void)
    5.55 +{
    5.56 +	while(winlist) {
    5.57 +		struct window *win = winlist;
    5.58 +		winlist = winlist->next;
    5.59 +
    5.60 +		glXDestroyContext(dpy, win->ctx);
    5.61 +		XCloseWindow(dpy, win->win);
    5.62 +		free(win);
    5.63 +	}
    5.64 +	XCloseDisplay(dpy);
    5.65 +	dpy = 0;
    5.66 +}
    5.67 +
    5.68 +static int set_vidmode(int xsz, int ysz, int bpp)
    5.69 +{
    5.70 +	/* TODO */
    5.71 +}
    5.72 +
    5.73 +static int get_vidmode(int *xsz, int *ysz, int *bpp)
    5.74 +{
    5.75 +	/* TODO */
    5.76 +}
    5.77 +
    5.78 +static int create_window(int xsz, int ysz, unsigned int flags)
    5.79 +{
    5.80 +}
    5.81 +
    5.82 +static void close_window(int id)
    5.83 +{
    5.84 +	struct window dummy, *win, *prev;
    5.85 +	dummy.next = winlist;
    5.86 +
    5.87 +	prev = &dummy;
    5.88 +	win = prev->next;
    5.89 +
    5.90 +	while(win) {
    5.91 +		if(win->win == id) {
    5.92 +			glXDestroyContext(dpy, win->ctx);
    5.93 +			XCloseWindow(dpy, win->win);
    5.94 +			prev->next = win->next;
    5.95 +			free(win);
    5.96 +			return;
    5.97 +		}
    5.98 +		win = win->next;
    5.99 +	}
   5.100 +}