stoe/engine/gl-utils.lisp

50 lines
1.3 KiB
Common Lisp

#|
This file is a part of stoe project.
Copyright (c) 2015 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|#
(uiop:define-package :stoe/engine/gl-utils
(:use :cl)
(:export #:gl-assert
#:gl-restart
#:ctype-size
#:ctype-to-gltype
#:ltype-to-ctype))
(in-package :stoe/engine/gl-utils)
(defmacro gl-assert (&body body)
`(progn
,@(loop for form in body
collect `(prog1
,form
(let ((err-sym (%gl:get-error)))
(unless (eq err-sym :zero)
(error "The OpenGL command `~a'~%~2iresulted in an error: ~s~%"
',form err-sym)))))))
(defmacro gl-restart (form)
`(restart-case
(gl-assert ,form)
(continue () :report "Continue")))
(defun ctype-size (type)
(ecase type
(:unsigned-char 1)
(:unsigned-short 2)
(:unsigned-int 4)
(:float 4)))
(defun ctype-to-gltype (ctype)
(case ctype
(:unsigned-char :unsigned-byte)
(t ctype)))
(defun ltype-to-ctype (ltype len)
(ecase ltype
(single-float :float)
(double-float :double)
(t (cond
((< len 256) :unsigned-char)
((< len 65536) :unsigned-short)
((< len 4294967296) :unsigned-int)
(t :uint64)))))