local gl = honey.gl local module = {} setmetatable(module, {__index=_G}) setfenv(1, module) local cache = {} -- load an image into a gl texture local function loadImage(filename) local data, width, height = honey.image.load(filename, 4) local texture = gl.GenTextures() gl.BindTexture(gl.TEXTURE_2D, texture) gl.TexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data ) gl.GenerateMipmap(gl.TEXTURE_2D) honey.image.destroy(data) return texture end -- cached get a texture get = function(filename) if not cache[filename] then cache[filename] = loadImage(filename) end return cache[filename] end -- remove a texture from the cache forget = function(filename) local texture = cache[filename] if texture then gl.DeleteTextures(texture) end cache[filename] = nil end -- remove all textures from the cache clearCache = function(filename) for key in pairs(cache) do forget(key) end end return module