aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/assets/png.lisp
blob: 4408d02c70272db3313f6b0fff6170d4825a90a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
;;;; png.lisp

(in-package #:wheelwork)

(def:class 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)
      ;; what does this do?
      (when (texture-mipmap png)
        (gl:generate-mipmap :texture-2d)))))