Module: Stagecraft::Renderer::Shaders
- Defined in:
- lib/stagecraft/renderer/shaders.rb
Constant Summary collapse
- ROOT =
File.("shaders", __dir__)
- DIRECTIVE =
%r{\A\s*//#(if|else|endif|include)\b(?:\s+["']?([^"'\s]+)["']?)?\s*\z}
Class Method Summary collapse
Class Method Details
.clear_cache ⇒ Object
17 18 19 |
# File 'lib/stagecraft/renderer/shaders.rb', line 17 def clear_cache @cache = {} end |
.compose(name, defines: Set.new) ⇒ Object
11 12 13 14 15 |
# File 'lib/stagecraft/renderer/shaders.rb', line 11 def compose(name, defines: Set.new) @cache ||= {} key = [name.to_s, defines.to_a.map(&:to_s).sort].freeze @cache[key] ||= process(read(name), defines.map(&:to_s).to_set, [name.to_s]).freeze end |
.read(name) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/stagecraft/renderer/shaders.rb', line 21 def read(name) path = File.(name.to_s, ROOT) raise ArgumentError, "shader path escapes shader root" unless path.start_with?("#{ROOT}/") raise ArgumentError, "shader not found: #{name}" unless File.file?(path) File.read(path) end |