Permalink
Browse files

Fix DISABLE, add compiler macros for ENABLE/DISABLE

  • Loading branch information...
Shinmera committed Aug 4, 2017
1 parent ec2ba74 commit f212005d8f44175b499d2ecab832e0f1a01919e4
Showing with 39 additions and 1 deletion.
  1. +39 −1 attributes.lisp
View
@@ -65,13 +65,51 @@
(gl:enable attrib)
(setf (gethash attrib table) T)))))
(define-compiler-macro enable (&whole whole &environment env &rest attributes)
(let ((constants) (variants) (table (gensym "TABLE")))
(dolist (attribute attributes)
(if (constantp attribute env)
(push attribute constants)
(push attribute variants)))
(cond ((and (null constants) (null variants))
())
((null constants)
whole)
(T
`(let ((,table (attribute-table)))
(enable ,@variants)
,@(loop for constant in constants
for attrib = `(load-time-value ,constant)
collect `(unless (gethash ,attrib ,table)
(gl:enable ,attrib)
(setf (gethash ,attrib ,table) T))))))))
(defun disable (&rest attributes)
(let ((table (attribute-table)))
(dolist (attrib attributes)
(when (gethash attrib table)
(gl:enable attrib)
(gl:disable attrib)
(setf (gethash attrib table) NIL)))))
(define-compiler-macro disable (&whole whole &environment env &rest attributes)
(let ((constants) (variants) (table (gensym "TABLE")))
(dolist (attribute attributes)
(if (constantp attribute env)
(push attribute constants)
(push attribute variants)))
(cond ((and (null constants) (null variants))
())
((null constants)
whole)
(T
`(let ((,table (attribute-table)))
(disable ,@variants)
,@(loop for constant in constants
for attrib = `(load-time-value ,constant)
collect `(when (gethash ,attrib ,table)
(gl:disable ,attrib)
(setf (gethash ,attrib ,table) NIL))))))))
(defun push-attribs (&optional (table (make-attribute-table (attribute-table))))
(push table *attribute-stack*))

0 comments on commit f212005

Please sign in to comment.