diff --git a/src/lights/ibl/brdf.lisp b/src/lights/ibl/brdf.lisp index bcf0944..7f7dab4 100644 --- a/src/lights/ibl/brdf.lisp +++ b/src/lights/ibl/brdf.lisp @@ -7,11 +7,6 @@ (brdf-fbo :reader brdf-fbo)) (:documentation "brdf lookup table")) -(defmethod free :after ((obj brdf)) - (free (bs obj)) - (free (brdf-fbo obj)) - (free (brdf-tex obj))) - (defun-g importance-sample-ggx ((xi :vec2) (n :vec3) (roughness :float)) diff --git a/src/lights/lights.lisp b/src/lights/lights.lisp index 7c63839..f48a6cb 100644 --- a/src/lights/lights.lisp +++ b/src/lights/lights.lisp @@ -24,21 +24,6 @@ (point-ubo :reader point-ubo :documentation "common point lights ubo")) (:documentation "state global pointlight resources")) -(defmethod free :after ((obj spotlights)) - (with-slots (spot-tex spot-ubo) obj - (free spot-tex) - (free spot-ubo))) - -(defmethod free :after ((obj pointlights)) - (with-slots (point-tex point-ubo) obj - (free point-tex) - (free point-ubo))) - -(defmethod free :after ((obj dirlights)) - (with-slots (dir-tex dir-ubo) obj - (free dir-tex) - (free dir-ubo))) - (defmethod initialize-instance :before ((obj lights) &key dim) (check-type dim (integer 256 4096))) diff --git a/src/material/material.lisp b/src/material/material.lisp index 4f6991c..f1209d6 100644 --- a/src/material/material.lisp +++ b/src/material/material.lisp @@ -60,3 +60,9 @@ (setf (aref-c (pbr-material-specular (aref-c c 0)) idx) specular) (setf (aref-c (pbr-material-metallic (aref-c c 0)) idx) metallic) (setf (aref-c (pbr-material-emissive (aref-c c 0)) idx) emissive)))) + +(defun set-and-upload-materials (materials materials-ubo) + (mapc (lambda (m) + (setf (slot-value m 'ubo) materials-ubo) + (upload m)) + materials)) diff --git a/src/screen.lisp b/src/screen.lisp index 760dcb6..5b1f815 100644 --- a/src/screen.lisp +++ b/src/screen.lisp @@ -15,10 +15,6 @@ (setf (slot-value obj 'prev) (make-renderable)) (setf (slot-value obj 'next) (make-renderable)))) -(defmethod free :after ((obj screen)) - (free (prev obj)) - (free (next obj))) - (defmethod handle :after ((e resize) (obj screen)) (setf (dim (prev *state*)) (list (width e) (height e)) (dim (next *state*)) (list (width e) (height e)))) diff --git a/src/state.lisp b/src/state.lisp index 1a51e54..d31c3dd 100644 --- a/src/state.lisp +++ b/src/state.lisp @@ -18,16 +18,26 @@ (defmethod initialize-instance :after ((obj state) &key materials) (with-slots (materials-ubo) obj (setf materials-ubo (make-ubo NIL 'pbr-material)) - (mapc (lambda (m) - (setf (slot-value m 'ubo) materials-ubo) - (upload m)) - materials))) + (set-and-upload-materials materials materials-ubo))) + +(defmethod reinitialize-instance :after ((obj state) &key materials) + (with-slots (scenes scene-index last-time materials-ubo) obj + (set-and-upload-materials materials materials-ubo) + (setf last-time (get-internal-real-time)) + (setf scene-index -1) + (setf scenes ()))) (defun init-state (materials) - (setf *state* (make-instance 'state :materials materials))) + (if *state* + (reinitialize-instance *state* :materials materials) + (setf *state* (make-instance 'state :materials materials)))) + +(defun init-default-state () + (init-state (list (make-material :roughness .8 :metallic .02 :specular .1) + (make-material :roughness .4 :metallic .4 :specular .1)))) (defmethod free ((obj state)) - (free (materials-ubo obj)) + (reset-material-counter) (mapc #'free (scenes obj))) (defmethod (setf scene-index) :before (new-value (obj state)) @@ -51,7 +61,3 @@ (defmethod handle :around ((e resize) (obj perspective)) (when (equal obj (current-camera)) (call-next-method))) - -(defun init-default-state () - (init-state (list (make-material :roughness .8 :metallic .02 :specular .1) - (make-material :roughness .4 :metallic .4 :specular .1))))