sgl
view src/cb.c @ 0:40491760d6e3
starting work on SimplyGL
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Tue, 10 May 2011 00:06:20 +0300 |
parents | |
children | 648f8604d2b2 |
line source
1 #include <stdlib.h>
2 #include <string.h>
3 #include "sgl.h"
5 struct cbnode {
6 void (*func[SGL_NUM_CALLBACKS])();
7 struct cbnode *next;
8 };
10 struct cbnode first_cbnode;
11 struct cbnode *cb = &first_cbnode;
13 int sgl_push_callbacks(void)
14 {
15 struct cbnode *node;
17 if(!(node = malloc(sizeof *node))) {
18 return -1;
19 }
20 node->next = cb;
21 cb = node;
22 sgl_clear_callbacks();
23 return 0;
24 }
26 int sgl_pop_callbacks(void)
27 {
28 struct cbnode *node;
30 if(!cb->next) {
31 return -1;
32 }
34 node = cb;
35 cb = cb->next;
36 free(node);
37 return 0;
38 }
40 void sgl_clear_callbacks(void)
41 {
42 memset(cb->func, 0, sizeof cb->func);
43 }
45 void (*sgl_callback(int idx, void (*func)()))()
46 {
47 void (*prev)() = cb->func[idx];
48 cb->func[idx] = func;
49 return prev;
50 }