(C-include "gl")
(define (with-glx-widget widget thunk)
- (with-gl-library
- (lambda ()
- (let ((xdisplay (glx-widget-xdisplay widget))
- (xwindow (glx-widget-xwindow widget))
- (glxcontext (glx-widget-glxcontext widget)))
- (if (zero? (C-call "glXMakeCurrent" xdisplay xwindow glxcontext))
- (error "glXMakeCurrent failed"))
- (let ((value (thunk)))
- (if (zero? (C-call "glXMakeCurrent" xdisplay (C-enum "None") 0))
- (error "glXMakeCurrent NULL failed"))
- value)))))
+ (let ((xdisplay (glx-widget-xdisplay widget))
+ (xwindow (glx-widget-xwindow widget))
+ (glxcontext (glx-widget-glxcontext widget)))
+ (if (zero? (C-call "glXMakeCurrent" xdisplay xwindow glxcontext))
+ (error "glXMakeCurrent failed"))
+ (let ((value (with-gl-context thunk)))
+ (if (zero? (C-call "glXMakeCurrent" xdisplay (C-enum "None") 0))
+ (error "glXMakeCurrent NULL failed"))
+ value)))
(define (glx:swap-buffers widget)
(let ((xdisplay (glx-widget-xdisplay widget))
(guarantee-current 'GL:PERSPECTIVE)
(C-call "gluPerspective" fovy aspect z-near z-far))
\f
-(define gl-library-mutex)
+(define param:gl-context-current?)
(define (init)
- (set! gl-library-mutex (make-thread-mutex)))
+ (set! param:gl-context-current? (make-parameter #f)))
(define (initialize-package!)
(init)
(define (reset-gl)
(init))
-(define (with-gl-library thunk)
- (with-thread-mutex-lock gl-library-mutex thunk))
+(define (with-gl-context thunk)
+ (if (param:gl-context-current?)
+ (error "The GL library already has a context."))
+ (parameterize ((param:gl-context-current? #t))
+ (thunk)))
(define (guarantee-current operator)
- (if (not (eq? (current-thread)
- (thread-mutex-owner gl-library-mutex)))
- (error "The GL library has not been locked:" operator)))
+ (if (not (param:gl-context-current?))
+ (error "The GL library has no context:" operator)))
(define (guarantee-flonum object operator)
(if (not (flo:flonum? object))
(files "glxgears")
(parent (gl))
(import (gl internals)
- with-gl-library))
\ No newline at end of file
+ with-gl-context))
\ No newline at end of file
(%trace ";XMapWindow\n")
(C-call "XMapWindow" dpy win)
- (with-gl-library
+ (with-gl-context
(lambda ()
(%trace ";glXMakeCurrent\n")
(C-call "glXMakeCurrent" dpy win ctx)