Class: RBGL::Engine::VertexAttribute
- Inherits:
-
Object
- Object
- RBGL::Engine::VertexAttribute
- Defined in:
- lib/rbgl/engine/buffer.rb
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #deserialize(values) ⇒ Object
-
#initialize(name, size, offset = 0, kind: nil) ⇒ VertexAttribute
constructor
A new instance of VertexAttribute.
- #serialize(value) ⇒ Object
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
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
6 7 8 |
# File 'lib/rbgl/engine/buffer.rb', line 6 def kind @kind end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rbgl/engine/buffer.rb', line 6 def name @name end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
6 7 8 |
# File 'lib/rbgl/engine/buffer.rb', line 6 def offset @offset end |
#size ⇒ Object (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.}" end |