Class: RBGL::Engine::VertexAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/rbgl/engine/buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, size, offset = 0, kind: nil) ⇒ VertexAttribute

Returns a new instance of VertexAttribute.



8
9
10
11
12
13
14
# File 'lib/rbgl/engine/buffer.rb', line 8

def initialize(name, size, offset = 0, kind: nil)
  @name = name.to_sym
  @size = size
  @offset = offset
  @kind = (kind || infer_kind).to_sym
  validate_kind!
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



6
7
8
# File 'lib/rbgl/engine/buffer.rb', line 6

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rbgl/engine/buffer.rb', line 6

def name
  @name
end

#offsetObject (readonly)

Returns the value of attribute offset.



6
7
8
# File 'lib/rbgl/engine/buffer.rb', line 6

def offset
  @offset
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/rbgl/engine/buffer.rb', line 6

def size
  @size
end

Instance Method Details

#deserialize(values) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rbgl/engine/buffer.rb', line 24

def deserialize(values)
  case @kind
  when :scalar
    values[0]
  when :vec2
    Larb::Vec2.new(*values)
  when :vec3
    Larb::Vec3.new(*values)
  when :vec4
    Larb::Vec4.new(*values)
  when :color
    Larb::Color.new(*values)
  when :array
    values.dup
  end
end

#serialize(value) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rbgl/engine/buffer.rb', line 16

def serialize(value)
  values = extract_values(value)
  validate_value_size!(values)
  values.first(@size).map { |component| Float(component) }
rescue ArgumentError, TypeError => e
  raise ArgumentError, "Invalid value for attribute #{name}: #{e.message}"
end