sgl

changeset 1:0c13a30be2c1

wsys
author John Tsiombikas <nuclear@siggraph.org>
date Wed, 11 May 2011 05:34:37 +0300
parents 40491760d6e3
children e55e71da991d
files Makefile include/sgl.h src/sgl.c src/wsys.c src/wsys.h
diffstat 5 files changed, 125 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Tue May 10 00:06:20 2011 +0300
     1.2 +++ b/Makefile	Wed May 11 05:34:37 2011 +0300
     1.3 @@ -22,7 +22,7 @@
     1.4  
     1.5  AR = ar
     1.6  CC = gcc
     1.7 -CFLAGS = -pedantic -Wall -g -Iinclude
     1.8 +CFLAGS = -pedantic -Wall -g -fPIC -Iinclude -Isrc
     1.9  
    1.10  .PHONY: all
    1.11  all: $(lib_so) $(lib_a)
     2.1 --- a/include/sgl.h	Tue May 10 00:06:20 2011 +0300
     2.2 +++ b/include/sgl.h	Wed May 11 05:34:37 2011 +0300
     2.3 @@ -20,11 +20,14 @@
     2.4  	SGL_NUM_CALLBACKS
     2.5  };
     2.6  
     2.7 +int sgl_init(void);
     2.8 +void sgl_shutdown(void);
     2.9 +
    2.10  int sgl_set_video_mode(int xsz, int ysz, int bpp);
    2.11  int sgl_get_video_mode(int *xsz, int *ysz, int *bpp);
    2.12  
    2.13 -int sgl_window(int x, int y, unsigned int mode);
    2.14 -void sgl_close(int win);
    2.15 +int sgl_window(int xsz, int ysz, unsigned int mode);
    2.16 +void sgl_close_window(int win);
    2.17  
    2.18  int sgl_push_callbacks(void);
    2.19  int sgl_pop_callbacks(void);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/sgl.c	Wed May 11 05:34:37 2011 +0300
     3.3 @@ -0,0 +1,29 @@
     3.4 +#include "sgl.h"
     3.5 +
     3.6 +int sgl_init(void)
     3.7 +{
     3.8 +	/*if(wsys_init() <= 0) {
     3.9 +		fprintf(stderr, "no window system modules found\n");
    3.10 +		return -1;
    3.11 +	}*/
    3.12 +	return 0;
    3.13 +}
    3.14 +
    3.15 +int sgl_set_video_mode(int xsz, int ysz, int bpp)
    3.16 +{
    3.17 +	return 0;
    3.18 +}
    3.19 +
    3.20 +int sgl_get_video_mode(int *xsz, int *ysz, int *bpp)
    3.21 +{
    3.22 +	return 0;
    3.23 +}
    3.24 +
    3.25 +int sgl_window(int x, int y, unsigned int mode)
    3.26 +{
    3.27 +	return 0;
    3.28 +}
    3.29 +
    3.30 +void sgl_close(int win)
    3.31 +{
    3.32 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/wsys.c	Wed May 11 05:34:37 2011 +0300
     4.3 @@ -0,0 +1,66 @@
     4.4 +#include <stdio.h>
     4.5 +#include "wsys.h"
     4.6 +
     4.7 +struct wsys_module *wslist;
     4.8 +int wscount;
     4.9 +
    4.10 +int sgl_register_module(struct wsys_module *ws)
    4.11 +{
    4.12 +	ws->next = wslist;
    4.13 +	wslist = ws;
    4.14 +	wscount++;
    4.15 +	return 0;
    4.16 +}
    4.17 +
    4.18 +#define APPEND(node) \
    4.19 +	do { \
    4.20 +		if(!res) { \
    4.21 +			res = tail = node; \
    4.22 +		} else { \
    4.23 +			tail->next = (node); \
    4.24 +			tail = (node); \
    4.25 +		} \
    4.26 +		(node) = (node)->next; \
    4.27 +		tail->next = 0; \
    4.28 +	} while(0)
    4.29 +
    4.30 +static struct wsys_module *merge(struct wsys_module *list1, struct wsys_module *list2)
    4.31 +{
    4.32 +	struct wsys_module *res, *tail;
    4.33 +
    4.34 +	res = tail = 0;
    4.35 +
    4.36 +	while(list1 || list2) {
    4.37 +		if(list1 && list2) {
    4.38 +			if(list1->prio <= list2->prio) {
    4.39 +				APPEND(list1);
    4.40 +			} else {
    4.41 +				APPEND(list2);
    4.42 +			}
    4.43 +		} else if(list1) {
    4.44 +			APPEND(list1);
    4.45 +		} else {
    4.46 +			APPEND(list2);
    4.47 +		}
    4.48 +	}
    4.49 +	return res;
    4.50 +}
    4.51 +
    4.52 +static struct wsys_module *msort(struct wsys_module *list, int count)
    4.53 +{
    4.54 +	int i, mid = count / 2;
    4.55 +	struct wsys_module *prev, *list2 = list;
    4.56 +
    4.57 +	if(!list->next) {
    4.58 +		return list;
    4.59 +	}
    4.60 +	for(i=0; i<mid; i++) {
    4.61 +		prev = list2;
    4.62 +		list2 = list2->next;
    4.63 +	}
    4.64 +	prev->next = 0;
    4.65 +
    4.66 +	list = msort(list, mid);
    4.67 +	list2 = msort(list2, count - mid);
    4.68 +	return merge(list, list2);
    4.69 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/wsys.h	Wed May 11 05:34:37 2011 +0300
     5.3 @@ -0,0 +1,24 @@
     5.4 +#ifndef WSYS_H_
     5.5 +#define WSYS_H_
     5.6 +
     5.7 +struct wsys_module {
     5.8 +	char *name;
     5.9 +	int prio;
    5.10 +
    5.11 +	int (*init)(void);
    5.12 +	void (*shutdown)(void);
    5.13 +
    5.14 +	int (*set_vidmode)(int, int, int);
    5.15 +	int (*get_vidmode)(int*, int*, int*);
    5.16 +	int (*window)(int, int, unsigned int);
    5.17 +	void (*close_win)(int);
    5.18 +
    5.19 +	struct wsys_module *next;
    5.20 +};
    5.21 +
    5.22 +int sgl_register_module(struct wsys_module *ws);
    5.23 +struct wsys_module *sgl_wsys_module(void);
    5.24 +
    5.25 +void dbg(void);
    5.26 +
    5.27 +#endif	/* WSYS_H_ */