Class: RLSL::MSL::Shader

Inherits:
RuntimeShader show all
Defined in:
lib/rlsl/msl/shader.rb

Instance Attribute Summary collapse

Attributes inherited from RuntimeShader

#uniform_names, #uniform_types

Instance Method Summary collapse

Constructor Details

#initialize(name, uniforms, msl_source) ⇒ Shader

Returns a new instance of Shader.



15
16
17
18
19
20
# File 'lib/rlsl/msl/shader.rb', line 15

def initialize(name, uniforms, msl_source)
  super(name, uniforms)
  @msl_source = msl_source
  @compiled_handles = {}
  @uniform_buffer_packer = UniformBufferPacker.new(@name, @uniform_types, @uniform_names)
end

Instance Attribute Details

#msl_sourceObject (readonly)

Returns the value of attribute msl_source.



13
14
15
# File 'lib/rlsl/msl/shader.rb', line 13

def msl_source
  @msl_source
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/rlsl/msl/shader.rb', line 13

def name
  @name
end

Instance Method Details

#metal?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rlsl/msl/shader.rb', line 22

def metal?
  true
end

#render(handle, width, height, uniforms = {}) ⇒ Object



26
27
28
# File 'lib/rlsl/msl/shader.rb', line 26

def render(handle, width, height, uniforms = {})
  render_metal(handle, width, height, uniforms)
end

#render_metal(handle, width, height, uniforms = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rlsl/msl/shader.rb', line 30

def render_metal(handle, width, height, uniforms = {})
  unless METACO_AVAILABLE
    raise LoadError, "metaco gem is required for Metal rendering. Install it with: gem install metaco"
  end

  unless @compiled_handles[handle]
    Metaco.compile_compute_shader(handle, @msl_source)
    @compiled_handles[handle] = true
  end

  uniform_data = pack_uniforms(uniforms, width, height)

  Metaco.dispatch_compute(handle, uniform_data)
  Metaco.present_compute(handle)
end