Shader resource support

This commit is contained in:
Jeremy Penner 2013-03-26 23:56:00 -04:00
parent 7119f1ef86
commit 35373a45bb

View file

@ -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)))