Export fix and extra convenience macro.
[cl-glfw.git] / lib / opengl-convenience.lisp
blob8e95bfb009ac634fb1330d48c1845e2d11c579c1
1 (in-package #:opengl)
3 (defmacro with-new-list (list mode &body forms)
4 "New/End-List wrapper."
5 `(progn
6 (gl:new-list ,list ,mode)
7 (unwind-protect (progn ,@forms)
8 (gl:end-list))))
10 (defmacro with-push-name (name &body forms)
11 "Select name push/pop wrapper"
12 `(progn
13 (gl:push-name ,name)
14 (unwind-protect (progn ,@forms)
15 (gl:pop-name))))
17 (defmacro with-begin (mode &body forms)
18 "Immediate mode block wrapper."
19 `(progn
20 (gl:begin ,mode)
21 (unwind-protect (progn ,@forms)
22 (gl:end))))
24 (defmacro with-push-attrib ((&rest attrib-bits) &body forms)
25 "Pushes the bitwise or of attrib-bits, executing forms and clean up with pop-attrib."
26 `(progn
27 (gl:push-attrib (logior ,@attrib-bits))
28 (unwind-protect (progn ,@forms)
29 (gl:pop-attrib))))
31 (defmacro with-push-matrix (&body forms)
32 "Pushes the current matrix onto the stack, executes forms and clean up with pop-matrix."
33 `(progn
34 (gl:push-matrix)
35 (unwind-protect (progn ,@forms)
36 (gl:pop-matrix))))
38 (defmacro with-setup-projection (&body forms)
39 "Switch to projection mode, load identity, execute forms and return to modelview matrix mode."
40 `(progn
41 (gl:matrix-mode gl:+projection+)
42 (gl:load-identity)
43 (unwind-protect (progn ,@forms)
44 (gl:matrix-mode gl:+modelview+))))
46 ;; 1.1 Conveniences
48 (defmacro with-push-client-attrib ((&rest attrib-bits) &body forms)
49 "Pushes the bitwise or of the client attrib-bits, executing forms and clean up with pop-client-attrib."
50 `(progn
51 (gl:push-client-attrib (logior ,@attrib-bits))
52 (unwind-protect (progn ,@forms)
53 (gl:pop-client-attrib))))
55 ;; 1.5 Conveniences
56 (defmacro with-begin-query ((target id) &body forms)
57 `(progn
58 (gl:begin-query ,target ,id)
59 (unwind-protect (progn ,@forms)
60 (gl:end-query))))
62 (defmacro with-map-buffer ((target access) &body forms)
63 (let ((ntarget (gensym "TARGET-")))
64 `(let ((,ntarget ,target))
65 (gl:map-buffer ,ntarget ,access)
66 (unwind-protect (progn ,@forms)
67 (gl:unmap-buffer ,ntarget)))))
69 (export '(with-new-list with-push-name with-begin with-push-attrib with-push-matrix with-setup-projection with-push-client-attrib with-begin-query with-map-buffer))