diff --git a/src/hottub/resource.clj b/src/hottub/resource.clj index 1cc21a4..17acc52 100644 --- a/src/hottub/resource.clj +++ b/src/hottub/resource.clj @@ -1,12 +1,15 @@ (ns hottub.resource (:use hottub.util) - (:import [org.newdawn.slick Image])) + (:import [org.newdawn.slick Image] + [org.newdawn.slick.opengl.shader ShaderProgram])) (def resource-cache (atom {})) (def garbage-resources (atom #{})) (defn last-modified [filename] - (.lastModified (java.io.File. filename))) + (if (string? filename) + (.lastModified (java.io.File. filename)) + (apply max (for [f filename] (last-modified f))))) (defn cached-resource [filename] (:resource (get @resource-cache filename))) @@ -45,6 +48,11 @@ (defn get-image [filename] (get-resource filename #(Image. %) #(.destroy %))) +(defn get-shader [filename & [filenameFrag]] + (let [filenameVert (if filenameFrag filename (str filename ".vert")) + filenameFrag (or filenameFrag (str filename ".frag"))] + (get-resource [filenameVert filenameFrag] #(ShaderProgram/loadProgram (first %) (second %)) #(.release %)))) + (defn gc-expired-resources [] (doseq [filename (reset-returning-old! garbage-resources #{})] (expire-resource-impl filename)))