Class: RLSL::MSL::UniformBufferPacker

Inherits:
Object
  • Object
show all
Defined in:
lib/rlsl/msl/uniform_buffer_packer.rb

Instance Method Summary collapse

Constructor Details

#initialize(shader_name, uniform_types, uniform_names) ⇒ UniformBufferPacker

Returns a new instance of UniformBufferPacker.



6
7
8
9
10
# File 'lib/rlsl/msl/uniform_buffer_packer.rb', line 6

def initialize(shader_name, uniform_types, uniform_names)
  @shader_name = shader_name
  @uniform_types = uniform_types
  @uniform_names = uniform_names
end

Instance Method Details

#pack(width, height, uniforms) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rlsl/msl/uniform_buffer_packer.rb', line 12

def pack(width, height, uniforms)
  normalized_uniforms = UniformTypes.normalize_values(@uniform_types, uniforms, shader_name: @shader_name)
  data = [width.to_f, height.to_f].pack("ff")
  current_offset = 8

  @uniform_names.each do |name|
    value = normalized_uniforms[name]
    spec = UniformTypes.metal_spec(@uniform_types[name])
    current_offset, data = append_padding(data, current_offset, spec.metal_alignment)
    data << pack_uniform_value(spec, value)
    current_offset += spec.metal_size
  end

  data.ljust(256, "\x00")
end