From 8d22d15fe917aac1220270a6b6aa3ff6350ed625 Mon Sep 17 00:00:00 2001 From: malc Date: Sun, 9 Nov 2008 01:00:21 +0300 Subject: [PATCH] Support mipmaps --- nmo.ml | 13 +++++++------ nto.ml | 13 ++++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/nmo.ml b/nmo.ml index 43102bf..4a2ad2b 100644 --- a/nmo.ml +++ b/nmo.ml @@ -24,7 +24,7 @@ type surf1 = type tex = { texname : string - ; nto : (int * int * string) + ; nto : (int * int * string) array ; int5 : int32 array ; half1 : int array ; w : int @@ -335,17 +335,18 @@ let r xff sbufxff = lazy ( let nto = text.nto in - let (_, _, data) = nto in - let id = GlTex.gen_texture () in - let raw = Raw.of_string data `ubyte in - let pix = GlPix.of_raw raw `rgba text.w text.h in GlTex.bind_texture `texture_2d id; GlTex.parameter `texture_2d (`min_filter `linear); GlTex.parameter `texture_2d (`mag_filter `linear); GlTex.parameter `texture_2d (`wrap_s `repeat); GlTex.parameter `texture_2d (`wrap_t `repeat); - GlTex.image2d pix; + Array.iteri + (fun level (w, h, data) -> + let raw = Raw.of_string data `ubyte in + let pix = GlPix.of_raw raw `rgba w h in + GlTex.image2d ~level pix) + nto; id ) ) texts diff --git a/nto.ml b/nto.ml index c0d17fb..485c25b 100644 --- a/nto.ml +++ b/nto.ml @@ -31,12 +31,12 @@ let r xff sbufxff ?dim () = w, h in let mipmaps = Xff.r8 ntobuf 29 in - let _mipmaps = mipmaps lsr 4 in + let mipmaps = mipmaps lsr 4 in let swz = Xff.r8 ntobuf 31 in - if false then + if true then printf "%dx%d kind=%d mipmaps=%d swz=%d@." - w h kind _mipmaps swz + w h kind mipmaps swz ; let to_rgba swz = @@ -44,7 +44,7 @@ let r xff sbufxff ?dim () = to_rgba s (p+pixpos, p+palpos) (w, h) swz in - let rgba = + let rgba w h = match kind with | 0x00 -> (* 32 bit *) let len = w * h * 4 in @@ -65,5 +65,8 @@ let r xff sbufxff ?dim () = | _ -> Xff.sbuferr ntobuf 28 "invalid kind" in - w, h, rgba + Array.init mipmaps + (fun i -> + let w = w lsr i and h = h lsr i in + w, h, rgba w h) ;; -- 2.11.4.GIT