From 82f71b0d13788b1cff9a24c5b652effd11631523 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Wed, 29 Jun 2022 11:54:24 -0500 Subject: [refactor] [structure] modularized project file structure --- src/assets/asset.lisp | 18 ++++++++++++++++++ src/assets/font.lisp | 17 +++++++++++++++++ src/assets/png.lisp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 src/assets/asset.lisp create mode 100644 src/assets/font.lisp create mode 100644 src/assets/png.lisp (limited to 'src/assets') diff --git a/src/assets/asset.lisp b/src/assets/asset.lisp new file mode 100644 index 0000000..5f847da --- /dev/null +++ b/src/assets/asset.lisp @@ -0,0 +1,18 @@ +;;;; asset.lisp + +(in-package #:wheelwork) + +(defclass/std asset () + ((path :with :ri :std (error "An asset requires a path")) + (loadedp :with :a))) + +(defmethod cleanup :around ((asset asset)) + (when (asset-loadedp asset) + (call-next-method)) + (setf (asset-loadedp asset) nil)) + +(defmethod ensure-loaded :around ((thing asset)) + (unless (asset-loadedp thing) + (call-next-method) + (setf (asset-loadedp thing) t)) + thing) diff --git a/src/assets/font.lisp b/src/assets/font.lisp new file mode 100644 index 0000000..3ff29d5 --- /dev/null +++ b/src/assets/font.lisp @@ -0,0 +1,17 @@ +;;;; asset/font.lisp + +(in-package #:wheelwork) + +(define-symbol-macro +standard-font-chars+ + " +ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890\".,!?-'" ) + +(defclass/std font (asset) + ((characters :i :std +standard-font-chars+) + (oversample :i :doc "ovesampling factor to pass to cl-fond:make-font") + (object :with :r :doc "The font as returned from cl-fond:make-font"))) + +(defmethod ensure-loaded ((font font)) + (with-slots (path characters oversample object) font + (setf object (cl-fond:make-font path characters :oversample oversample)))) + diff --git a/src/assets/png.lisp b/src/assets/png.lisp new file mode 100644 index 0000000..aa259f0 --- /dev/null +++ b/src/assets/png.lisp @@ -0,0 +1,31 @@ +;;;; png.lisp + +(in-package #:wheelwork) + +(defclass/std png (asset texture) ()) + +(defmethod ensure-loaded ((png png)) + (with-slots + (width height id wrap-s wrap-t min-filter mag-filter internal-format image-format) + png + (pngload:with-png-in-static-vector (data (asset-path png) :flip-y t) + (setf width (pngload:width data) + height (pngload:height data) + id (gl:gen-texture)) + (gl:bind-texture :texture-2d id) + (gl:tex-parameter :texture-2d :texture-wrap-s wrap-s) + (gl:tex-parameter :texture-2d :texture-wrap-t wrap-t) + (gl:tex-parameter :texture-2d :texture-min-filter min-filter) + (gl:tex-parameter :texture-2d :texture-mag-filter mag-filter) + (gl:tex-image-2d :texture-2d + 0 + internal-format + width + height + 0 + image-format + :unsigned-byte + (pngload:data data)) + (gl:bind-texture :texture-2d 0) + (when (texture-mipmap png) + (gl:generate-mipmap :texture-2d))))) -- cgit v1.2.3