Bill's coming back online merge. API breaking changes!
[cl-glfw.git] / lib / opengl-extensions.lisp
blobd253f88e5b0dcd45e00d2646214028140ef269ac
1 (defpackage #:cl-glfw-opengl-extensions
2 (:nicknames #:gl-ext)
3 (:use #:cl)
4 (:export #:scan-available-extensions #:available-extensions #:extension-available-p #:load-extension))
6 (in-package #:gl-ext)
8 (defparameter *available* nil)
10 (defun scan-available-extensions ()
11 (let ((*readtable* (copy-readtable nil)))
12 (setf (readtable-case *readtable*) :preserve)
13 (setf *available*
14 (mapcar #'(lambda (ext-name) (subseq (symbol-name ext-name) 3))
15 (read-from-string (format nil "(~a)" (gl:get-string gl:+extensions+)))))))
17 (defun available-extensions ()
18 (if (and *available* (not (equal *available* '(""))) (not (eql *available* '(nil))))
19 *available*
20 (scan-available-extensions)))
22 (defun extension-available-p (extension)
23 (declare (type string extension))
24 (find extension (available-extensions) :test 'equalp))
26 (defun load-extension (extension)
27 "Try to load an opengl extension where the extension name is a string of the form
28 \"ARB_vertex_buffer_object\". Returns t if the extension is available and loads,
29 otherwise, nil."
30 (let ((extension (extension-available-p extension)))
31 (when extension
32 (handler-case
33 (asdf:oos 'asdf:load-op (string-downcase (format nil "cl-glfw-opengl-~a" extension)))
34 (asdf:missing-component () (warn "Extension ~a has nothing to load~%" extension)))
35 t)))