Merge branch 'master' of ssh://repo.or.cz/srv/git/tgl
[tgl.git] / src / oscontext.c
blobf74e8f977d0428b2a860d4fed231bc1707a81b70
1 #include <GL/oscontext.h>
2 #include "zbuffer.h"
3 #include "zgl.h"
4 #include <GL/gl.h>
5 #include <stdlib.h>
6 #include <assert.h>
8 static int buffercnt = 0;
10 ostgl_context *
11 ostgl_create_context(const int xsize,
12 const int ysize,
13 const int depth,
14 void **framebuffers,
15 const int numbuffers)
17 ostgl_context *context;
18 int i;
19 ZBuffer *zb;
21 assert(depth == 16); /* support for other depths must include bpp
22 convertion */
23 assert(numbuffers >= 1);
25 context = gl_malloc(sizeof(ostgl_context));
26 assert(context);
27 context->zbs = gl_malloc(sizeof(void*)*numbuffers);
28 context->framebuffers = gl_malloc(sizeof(void*)*numbuffers);
30 assert(context->zbs != NULL && context->framebuffers != NULL);
32 for (i = 0; i < numbuffers; i++) {
33 context->framebuffers[i] = framebuffers[i];
34 zb = ZB_open(xsize, ysize, ZB_MODE_5R6G5B, 0, NULL, NULL, framebuffers[i]);
35 if (zb == NULL) {
36 fprintf(stderr, "Error while initializing Z buffer\n");
37 exit(1);
39 context->zbs[i] = zb;
41 if (++buffercnt == 1) {
42 glInit(context->zbs[0]);
44 context->xsize = xsize;
45 context->ysize = ysize;
46 context->numbuffers = numbuffers;
47 return context;
50 void
51 ostgl_delete_context(ostgl_context *context)
53 int i;
54 for (i = 0; i < context->numbuffers; i++) {
55 ZB_close(context->zbs[i]);
57 gl_free(context->zbs);
58 gl_free(context->framebuffers);
59 gl_free(context);
61 if (--buffercnt == 0) {
62 glClose();
66 void
67 ostgl_make_current(ostgl_context *oscontext, const int idx)
69 GLContext *context = gl_get_context();
70 assert(idx < oscontext->numbuffers);
71 context->zb = oscontext->zbs[idx];
74 void
75 ostgl_resize(ostgl_context *context,
76 const int xsize,
77 const int ysize,
78 void **framebuffers)
80 int i;
81 for (i = 0; i < context->numbuffers; i++) {
82 ZB_resize(context->zbs[i], framebuffers[i], xsize, ysize);