1 /* simple glx like driver for TinyGL and Nano X */
4 #include <microwin/nano-X.h>
12 int pixtype
; /* pixel type in TinyGL */
15 NGLXContext
nglXCreateContext(NGLXContext shareList
, int flags
)
19 if (shareList
!= NULL
) {
20 gl_fatal_error("No sharing available in TinyGL");
22 ctx
=gl_malloc(sizeof(TinyNGLXContext
));
26 return (NGLXContext
) ctx
;
29 void glXDestroyContext( NGLXContext ctx1
)
31 TinyNGLXContext
*ctx
= (TinyNGLXContext
*) ctx1
;
32 if (ctx
->gl_context
!= NULL
) {
39 /* resize the glx viewport : we try to use the xsize and ysize
40 given. We return the effective size which is guaranted to be smaller */
42 static int glX_resize_viewport(GLContext
*c
,int *xsize_ptr
,int *ysize_ptr
)
47 ctx
=(TinyNGLXContext
*)c
->opaque
;
52 /* we ensure that xsize and ysize are multiples of 2 for the zbuffer.
53 TODO: find a better solution */
57 if (xsize
== 0 || ysize
== 0) return -1;
65 /* resize the Z buffer */
66 ZB_resize(c
->zb
,NULL
,xsize
,ysize
);
70 /* we assume here that drawable is a window */
71 int nglXMakeCurrent( NGLXDrawable drawable
,
74 TinyNGLXContext
*ctx
= (TinyNGLXContext
*) ctx1
;
75 int mode
, xsize
, ysize
;
77 GR_WINDOW_INFO win_info
;
79 if (ctx
->gl_context
== NULL
) {
80 /* create the TinyGL context */
81 GrGetWindowInfo(drawable
, &win_info
);
83 xsize
= win_info
.width
;
84 ysize
= win_info
.height
;
86 /* currently, we only support 16 bit rendering */
87 mode
= ZB_MODE_5R6G5B
;
88 zb
=ZB_open(xsize
,ysize
,mode
,0,NULL
,NULL
,NULL
);
90 fprintf(stderr
, "Error while initializing Z buffer\n");
94 ctx
->pixtype
= MWPF_TRUECOLOR565
;
99 /* initialisation of the TinyGL interpreter */
101 ctx
->gl_context
=gl_get_context();
102 ctx
->gl_context
->opaque
=(void *) ctx
;
103 ctx
->gl_context
->gl_resize_viewport
=glX_resize_viewport
;
105 /* set the viewport : we force a call to glX_resize_viewport */
106 ctx
->gl_context
->viewport
.xsize
=-1;
107 ctx
->gl_context
->viewport
.ysize
=-1;
109 glViewport(0, 0, xsize
, ysize
);
115 void nglXSwapBuffers( NGLXDrawable drawable
)
117 GLContext
*gl_context
;
118 TinyNGLXContext
*ctx
;
120 /* retrieve the current NGLXContext */
121 gl_context
=gl_get_context();
122 ctx
=(TinyNGLXContext
*)gl_context
->opaque
;
124 GrArea(drawable
, ctx
->gc
, 0, 0, ctx
->xsize
,
125 ctx
->ysize
, ctx
->gl_context
->zb
->pbuf
, ctx
->pixtype
);