Class: Jax::Shader

Inherits:
Object
  • Object
show all
Defined in:
lib/jax/shader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, name = File.basename(path)) ⇒ Shader

Returns a new instance of Shader.



5
6
7
8
9
10
11
# File 'lib/jax/shader.rb', line 5

def initialize(path, name = File.basename(path))
  @exports = {}
  @name = name
  @path = path
  
  detect_sources
end

Instance Attribute Details

#exportsObject

attr_reader :common, :fragment, :vertex



3
4
5
# File 'lib/jax/shader.rb', line 3

def exports
  @exports
end

#manifestObject

attr_reader :common, :fragment, :vertex



3
4
5
# File 'lib/jax/shader.rb', line 3

def manifest
  @manifest
end

#nameObject

attr_reader :common, :fragment, :vertex



3
4
5
# File 'lib/jax/shader.rb', line 3

def name
  @name
end

#pathObject

attr_reader :common, :fragment, :vertex



3
4
5
# File 'lib/jax/shader.rb', line 3

def path
  @path
end

Class Method Details

.from(path) ⇒ Object

Raises:

  • (ArgumentError)


48
49
50
51
# File 'lib/jax/shader.rb', line 48

def from(path)
  raise ArgumentError, "Expected path to be a directory" unless File.directory? path
  new(path)
end

Instance Method Details

#commonObject



13
14
15
16
# File 'lib/jax/shader.rb', line 13

def common
  detect_sources # force reloads the latest sources
  @common
end

#common=(str) ⇒ Object



54
55
56
# File 'lib/jax/shader.rb', line 54

def common=(str)
  @common = preprocess(str).inspect
end

#default_optionsObject



36
37
38
# File 'lib/jax/shader.rb', line 36

def default_options
  manifest && manifest['options'] || {}
end

#descriptionObject



28
29
30
# File 'lib/jax/shader.rb', line 28

def description
  manifest && manifest['description']
end

#fragmentObject



18
19
20
21
# File 'lib/jax/shader.rb', line 18

def fragment
  detect_sources # force reloads the latest sources
  @fragment
end

#fragment=(str) ⇒ Object



58
59
60
# File 'lib/jax/shader.rb', line 58

def fragment=(str)
  @fragment = preprocess(str).inspect
end

#preprocess(str) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/jax/shader.rb', line 66

def preprocess(str)
  include_dependencies str
  intercept_export_directives str
#    intercept_import_directives str
#    prepend_export_definitions str
  
  str
end

#save_to(file_or_filename) ⇒ Object



40
41
42
43
44
45
# File 'lib/jax/shader.rb', line 40

def save_to(file_or_filename)
  if file_or_filename.kind_of?(String)
    File.open(filename, "w") { |f| f.puts to_s }
  else file_or_filename.puts to_s
  end
end

#to_sObject



32
33
34
# File 'lib/jax/shader.rb', line 32

def to_s
  "Jax.shaders['#{name}'] = new Jax.Shader(#{js_options.gsub(/<%/, '<%')});"
end

#vertexObject



23
24
25
26
# File 'lib/jax/shader.rb', line 23

def vertex
  detect_sources # force reloads the latest sources
  @vertex
end

#vertex=(str) ⇒ Object



62
63
64
# File 'lib/jax/shader.rb', line 62

def vertex=(str)
  @vertex = preprocess(str).inspect
end