Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (45 sloc) 1.67 KB
#|
This file is a part of trial
(c) 2018 Shirakumo http://tymoon.eu (shinmera@tymoon.eu)
Author: Nicolas Hafner <shinmera@tymoon.eu>
|#
(in-package #:org.shirakumo.fraf.trial)
;; FIXME: configurable defaults
(defclass resource ()
())
(defgeneric allocate (resource))
(defgeneric deallocate (resource))
(defgeneric allocated-p (resource))
(defmethod load ((resource resource))
(unless (allocated-p resource)
(v:trace :trial.resource "Loading ~a" resource)
(allocate resource)))
(defmethod allocate :around ((resource resource))
(call-next-method)
resource)
(defmethod deallocate :around ((resource resource))
(call-next-method)
resource)
(defmethod allocate :after ((resource resource))
(setf (gethash resource (resources *context*)) resource))
(defmethod deallocate :after ((resource resource))
(remhash resource (resources *context*)))
(defun check-allocated (resource)
(unless (allocated-p resource)
(error "~s is not yet allocated." resource)))
(defclass foreign-resource (resource)
((data-pointer :initform NIL :initarg :data-pointer :accessor data-pointer)))
(defgeneric destructor (foreign-resource))
(defmethod destructor ((resource foreign-resource))
(lambda ()))
(defmethod allocated-p ((resource foreign-resource))
(data-pointer resource))
(defmethod allocate :after ((resource foreign-resource))
(tg:finalize resource (destructor resource)))
(defmethod deallocate ((resource foreign-resource))
(funcall (destructor resource)))
(defmethod deallocate :after ((resource foreign-resource))
(tg:cancel-finalization resource)
(setf (data-pointer resource) NIL))
(defclass gl-resource (foreign-resource)
((data-pointer :accessor gl-name)))