Skip to content

Instantly share code, notes, and snippets.

@psilord
Created July 13, 2024 05:48
Show Gist options
  • Save psilord/fc6be265b6b2adc0eb4f245bafd51b5f to your computer and use it in GitHub Desktop.
Save psilord/fc6be265b6b2adc0eb4f245bafd51b5f to your computer and use it in GitHub Desktop.
;; The logical form which is written 99% of the time by a human.
(c:define-texture-map g001-1d-log-inf-all-non (:1d :unique)
;; USER MUST PUT THEM IN ORDER.
(c:mipmap (textures 1d-64x1))
(c:mipmap (textures 1d-32x1))
(c:mipmap (textures 1d-16x1))
(c:mipmap (textures 1d-8x1))
(c:mipmap (textures 1d-4x1))
(c:mipmap (textures 1d-2x1))
(c:mipmap (textures 1d-1x1)))
;; |
;; | Converted at macro expansion time to the below. The expander simply
;; | honors the mipmap images found.
;; |
;; v
(c:define-texture-map g001-1d-phy-inf-all-non (:1d :unique)
(c:data-elements
(0 (c:image-element :logloc (textures 1d-64x1)))
(1 (c:image-element :logloc (textures 1d-32x1)))
(2 (c:image-element :logloc (textures 1d-16x1)))
(3 (c:image-element :logloc (textures 1d-8x1)))
(4 (c:image-element :logloc (textures 1d-4x1)))
(5 (c:image-element :logloc (textures 1d-2x1)))
(6 (c:image-element :logloc (textures 1d-1x1))))
(c:mipmap-1d
:extent (c:span-1d)
(c:mapping-span-1d :to (c:data-span-1d)
:from (c:data-span-1d :elidx 0)))
(c:mipmap-1d
:extent (c:span-1d)
(c:mapping-span-1d :to (c:data-span-1d)
:from (c:data-span-1d :elidx 1)))
(c:mipmap-1d
:extent (c:span-1d)
(c:mapping-span-1d :to (c:data-span-1d)
:from (c:data-span-1d :elidx 2)))
(c:mipmap-1d
:extent (c:span-1d)
(c:mapping-span-1d :to (c:data-span-1d)
:from (c:data-span-1d :elidx 3)))
(c:mipmap-1d
:extent (c:span-1d)
(c:mapping-span-1d :to (c:data-span-1d)
:from (c:data-span-1d :elidx 4)))
(c:mipmap-1d
:extent (c:span-1d)
(c:mapping-span-1d :to (c:data-span-1d)
:from (c:data-span-1d :elidx 5)))
(c:mipmap-1d
:extent (c:span-1d)
(c:mapping-span-1d :to (c:data-span-1d)
:from (c:data-span-1d :elidx 6))))
;; |
;; | One or more mipmaps image headers are read and ultimately produce
;; | the following. However, in order to mark the texture-map as "complete"
;; | we need to eventually see the entire set of image headers.
;; |
;; v
(c:define-texture-map g001-1d-phy-gnd-all-non (:1d :unique)
(c:data-elements
(0 (c:image-element :logloc (textures 1d-64x1)))
(1 (c:image-element :logloc (textures 1d-32x1)))
(2 (c:image-element :logloc (textures 1d-16x1)))
(3 (c:image-element :logloc (textures 1d-8x1)))
(4 (c:image-element :logloc (textures 1d-4x1)))
(5 (c:image-element :logloc (textures 1d-2x1)))
(6 (c:image-element :logloc (textures 1d-1x1))))
(c:mipmap-1d
:extent (c:span-1d :origin 0 :extent 64)
(c:mapping-span-1d :to (c:data-span-1d :origin 0 :extent 64)
:from (c:data-span-1d :origin 0 :extent 64 :elidx 0)))
(c:mipmap-1d
:extent (c:span-1d :origin 0 :extent 32)
(c:mapping-span-1d :to (c:data-span-1d :origin 0 :extent 32)
:from (c:data-span-1d :origin 0 :extent 32 :elidx 1)))
(c:mipmap-1d
:extent (c:span-1d :origin 0 :extent 16)
(c:mapping-span-1d :to (c:data-span-1d :origin 0 :extent 16)
:from (c:data-span-1d :origin 0 :extent 16 :elidx 2)))
(c:mipmap-1d
:extent (c:span-1d :origin 0 :extent 8)
(c:mapping-span-1d :to (c:data-span-1d :origin 0 :extent 8)
:from (c:data-span-1d :origin 0 :extent 8 :elidx 3)))
(c:mipmap-1d
:extent (c:span-1d :origin 0 :extent 4)
(c:mapping-span-1d :to (c:data-span-1d :origin 0 :extent 4)
:from (c:data-span-1d :origin 0 :extent 4 :elidx 4)))
(c:mipmap-1d
:extent (c:span-1d :origin 0 :extent 2)
(c:mapping-span-1d :to (c:data-span-1d :origin 0 :extent 2)
:from (c:data-span-1d :origin 0 :extent 2 :elidx 5)))
(c:mipmap-1d
:extent (c:span-1d :origin 0 :extent 1)
(c:mapping-span-1d :to (c:data-span-1d :origin 0 :extent 1)
:from (c:data-span-1d :origin 0 :extent 1 :elidx 6))))
;; -
;; |
;; | The same grounded form as above, but built from programmatic API.
;; |
;; v
(defun test-g001-1d-imp-gnd-all-non ()
(let* (;; define all data elements
(de0 (texmap:make-image-element :logloc '(textures 1d-64x1)))
(de1 (texmap:make-image-element :logloc '(textures 1d-32x1)))
(de2 (texmap:make-image-element :logloc '(textures 1d-16x1)))
(de3 (texmap:make-image-element :logloc '(textures 1d-8x1)))
(de4 (texmap:make-image-element :logloc '(textures 1d-4x1)))
(de5 (texmap:make-image-element :logloc '(textures 1d-2x1)))
(de6 (texmap:make-image-element :logloc '(textures 1d-1x1)))
;; create the data-elements array
(data-elements
(texmap:make-data-elements :encode de0 de1 de2 de3 de4 de5 de6))
;; define, in groups, all mapping spans for each mipmap and then the
;; mipmap itself.
;; mipmap 0
(mip0-ms0-to (texmap:make-data-span-1d :origin 0 :extent 64))
(mip0-ms0-from (texmap:make-data-span-1d :origin 0 :extent 64
:elidx 0))
(mip0-ms0 (texmap:make-mapping-span-1d :to mip0-ms0-to
:from mip0-ms0-from))
(mip0-mspans (texmap:make-mapping-spans :encode mip0-ms0))
(mip0-extent (texmap:make-span-1d :origin 0 :extent 64))
(mip0 (texmap:make-mipmap-1d :extent mip0-extent
:mapping-spans mip0-mspans))
;; mipmap 1
(mip1-ms0-to (texmap:make-data-span-1d :origin 0 :extent 32))
(mip1-ms0-from (texmap:make-data-span-1d :origin 0 :extent 32
:elidx 1))
(mip1-ms0 (texmap:make-mapping-span-1d :to mip1-ms0-to
:from mip1-ms0-from))
(mip1-mspans (texmap:make-mapping-spans :encode mip1-ms0))
(mip1-extent (texmap:make-span-1d :origin 0 :extent 32))
(mip1 (texmap:make-mipmap-1d :extent mip1-extent
:mapping-spans mip1-mspans))
;; mipmap 2
(mip2-ms0-to (texmap:make-data-span-1d :origin 0 :extent 16))
(mip2-ms0-from (texmap:make-data-span-1d :origin 0 :extent 16
:elidx 2))
(mip2-ms0 (texmap:make-mapping-span-1d :to mip2-ms0-to
:from mip2-ms0-from))
(mip2-mspans (texmap:make-mapping-spans :encode mip2-ms0))
(mip2-extent (texmap:make-span-1d :origin 0 :extent 16))
(mip2 (texmap:make-mipmap-1d :extent mip2-extent
:mapping-spans mip2-mspans))
;; mipmap 3
(mip3-ms0-to (texmap:make-data-span-1d :origin 0 :extent 8))
(mip3-ms0-from (texmap:make-data-span-1d :origin 0 :extent 8
:elidx 3))
(mip3-ms0 (texmap:make-mapping-span-1d :to mip3-ms0-to
:from mip3-ms0-from))
(mip3-mspans (texmap:make-mapping-spans :encode mip3-ms0))
(mip3-extent (texmap:make-span-1d :origin 0 :extent 8))
(mip3 (texmap:make-mipmap-1d :extent mip3-extent
:mapping-spans mip3-mspans))
;; mipmap 4
(mip4-ms0-to (texmap:make-data-span-1d :origin 0 :extent 4))
(mip4-ms0-from (texmap:make-data-span-1d :origin 0 :extent 4
:elidx 4))
(mip4-ms0 (texmap:make-mapping-span-1d :to mip4-ms0-to
:from mip4-ms0-from))
(mip4-mspans (texmap:make-mapping-spans :encode mip4-ms0))
(mip4-extent (texmap:make-span-1d :origin 0 :extent 4))
(mip4 (texmap:make-mipmap-1d :extent mip4-extent
:mapping-spans mip4-mspans))
;; mipmap 5
(mip5-ms0-to (texmap:make-data-span-1d :origin 0 :extent 2))
(mip5-ms0-from (texmap:make-data-span-1d :origin 0 :extent 2
:elidx 5))
(mip5-ms0 (texmap:make-mapping-span-1d :to mip5-ms0-to
:from mip5-ms0-from))
(mip5-mspans (texmap:make-mapping-spans :encode mip5-ms0))
(mip5-extent (texmap:make-span-1d :origin 0 :extent 2))
(mip5 (texmap:make-mipmap-1d :extent mip5-extent
:mapping-spans mip5-mspans))
;; mipmap 6
(mip6-ms0-to (texmap:make-data-span-1d :origin 0 :extent 1))
(mip6-ms0-from (texmap:make-data-span-1d :origin 0 :extent 1
:elidx 6))
(mip6-ms0 (texmap:make-mapping-span-1d :to mip6-ms0-to
:from mip6-ms0-from))
(mip6-mspans (texmap:make-mapping-spans :encode mip6-ms0))
(mip6-extent (texmap:make-span-1d :origin 0 :extent 1))
(mip6 (texmap:make-mipmap-1d :extent mip6-extent
:mapping-spans mip6-mspans))
;; create the mipmaps array
(mipmaps
(texmap:make-mipmaps :encode mip0 mip1 mip2 mip3 mip4 mip5 mip6))
;; finally wire together the texture-map
(texture-map (texmap:make-texture-map-1d
:name 'g001-1d-imp-gnd-all-non
:anonymous-p nil
:model :1d
:style :unique
:store nil
:data-elements data-elements
:mipmaps mipmaps
;; If any attributes, put them here as appropriate.
;; :cattrs ((...) ...)
)))
;; HOWEVER: If there were any attributes, deal with them here. Each
;; storage-forms absorbs the texture-map while using :cattr (or whatever as
;; appropriate)
texture-map))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment