Major package refactoring.
[cl-glfw/jecs.git] / lib / opengl-extensions.lisp
blob459add41c1f18ca621e56205fcdcd9cd8a040785
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 (setf *available*
12 (mapcar #'(lambda (ext-name) (subseq (symbol-name ext-name) 3))
13 (let ((*readtable* (copy-readtable nil)))
14 (setf (readtable-case *readtable*) :preserve)
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)))