Shader resource support
This commit is contained in:
parent
7119f1ef86
commit
35373a45bb
|
@ -1,12 +1,15 @@
|
||||||
(ns hottub.resource
|
(ns hottub.resource
|
||||||
(:use hottub.util)
|
(:use hottub.util)
|
||||||
(:import [org.newdawn.slick Image]))
|
(:import [org.newdawn.slick Image]
|
||||||
|
[org.newdawn.slick.opengl.shader ShaderProgram]))
|
||||||
|
|
||||||
(def resource-cache (atom {}))
|
(def resource-cache (atom {}))
|
||||||
(def garbage-resources (atom #{}))
|
(def garbage-resources (atom #{}))
|
||||||
|
|
||||||
(defn last-modified [filename]
|
(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]
|
(defn cached-resource [filename]
|
||||||
(:resource (get @resource-cache filename)))
|
(:resource (get @resource-cache filename)))
|
||||||
|
@ -45,6 +48,11 @@
|
||||||
|
|
||||||
(defn get-image [filename] (get-resource filename #(Image. %) #(.destroy %)))
|
(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 []
|
(defn gc-expired-resources []
|
||||||
(doseq [filename (reset-returning-old! garbage-resources #{})]
|
(doseq [filename (reset-returning-old! garbage-resources #{})]
|
||||||
(expire-resource-impl filename)))
|
(expire-resource-impl filename)))
|
||||||
|
|
Loading…
Reference in a new issue