(bind-func load_cube_data
(lambda (tex:Texture* flipped:i32 front:String* back:String* top:String* bottom:String* left:String* right:String*)
;; seems to need to be set
(stbi_set_flip_vertically_on_load flipped)
(let ((width_ptr:i32* (tref-ptr tex 2))
(height_ptr:i32* (tref-ptr tex 3))
(comp_ptr:i32* (salloc))
(i:i32 0)
(wp:i32* (salloc 6))
(hp:i32* (salloc 6))
(cp:i32* (salloc 6))
(wpt:i32 0)
(hpt:i32 0)
(cpt:i32 0)
(front_data (stbi_load (cstring front) (pref-ptr wp 0) (pref-ptr hp 0) (pref-ptr cp 0) 4))
(back_data (stbi_load (cstring back) (pref-ptr wp 1) (pref-ptr hp 1) (pref-ptr cp 1) 4))
(top_data (stbi_load (cstring top) (pref-ptr wp 2) (pref-ptr hp 2) (pref-ptr cp 2) 4))
(bottom_data (stbi_load (cstring bottom) (pref-ptr wp 3) (pref-ptr hp 3) (pref-ptr cp 3) 4))
(left_data (stbi_load (cstring left) (pref-ptr wp 4) (pref-ptr hp 4) (pref-ptr cp 4) 4))
(right_data (stbi_load (cstring right) (pref-ptr wp 5) (pref-ptr hp 5) (pref-ptr cp 5) 4))
(w:i32 (pref wp 0))
(h:i32 (pref hp 0))
(c:i32 (pref cp 0))
(whc:i64 (convert (* w h 4))) ;; always 4 channels
(data:i8* (alloc (* whc 6)))) ;; always allocate 4 channels
;; (println "CUBE LOAD: width:" w "height:" h "channels:" c)
(dotimes (i 6)
(set! wpt (+ wpt (pref wp i)))
(set! hpt (+ hpt (pref hp i)))
(set! cpt (+ cpt (pref cp i))))
(if (<> (/ wpt 6) w)
(begin (println "Bad cube map! All 6 images must have the same width!" w)
(set! front_data null)))
(if (<> (/ hpt 6) h)
(begin (println "Bad cube map! All 6 images must have the same height!" h)
(set! front_data null)))
(if (<> (/ cpt 6) c)
(begin (println "Bad cube map! All 6 images must have the same number of components" c)
(set! front_data null)))
(pset! width_ptr 0 w)
(pset! height_ptr 0 h)
(pset! comp_ptr 0 4) ;; we actually forced (stbi_load ... 4) to 4 channels
(tset! tex 1 GL_RGBA) ;; 4 componenets
(if (or (null? front_data)
(null? back_data)
(null? top_data)
(null? bottom_data)
(null? left_data)
(null? right_data))
(begin
(println "failed to load some images" (stbi_failure_reason))
1)
(begin
;; front
(memcpy (pref-ptr data (* whc 0)) front_data whc)
;; back
(memcpy (pref-ptr data (* whc 1)) back_data whc)
;; top
(memcpy (pref-ptr data (* whc 2)) top_data whc)
;; bottom
(memcpy (pref-ptr data (* whc 3)) bottom_data whc)
;; left
(memcpy (pref-ptr data (* whc 4)) left_data whc)
;; right
(memcpy (pref-ptr data (* whc 5)) right_data whc)
;; back
(tset! tex 4 data)
1))
void)))