Skip to content

Commit

Permalink
Fix DISABLE, add compiler macros for ENABLE/DISABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Aug 4, 2017
1 parent ec2ba74 commit f212005
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion attributes.lisp
Expand Up @@ -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*))

Expand Down

0 comments on commit f212005

Please sign in to comment.