Class: Stagecraft::Attribute
- Inherits:
-
Object
- Object
- Stagecraft::Attribute
- Defined in:
- lib/stagecraft/core/attribute.rb
Constant Summary collapse
- FORMAT_COMPONENTS =
{ float32: 1, float32x2: 2, float32x3: 3, float32x4: 4, uint16: 1, uint16x2: 2, uint16x4: 4, sint16x2: 2, sint16x4: 4, snorm16x2: 2, snorm16x4: 4, unorm16x2: 2, unorm16x4: 4, uint32: 1, uint32x2: 2, uint32x3: 3, uint32x4: 4, unorm8x2: 2, unorm8x4: 4, uint8x2: 2, uint8x4: 4, sint8x2: 2, sint8x4: 4, snorm8x2: 2, snorm8x4: 4 }.freeze
- FORMAT_WIDTHS =
{ float32: 4, uint32: 4, uint16: 2, uint8: 1, unorm8: 1, sint8: 1, snorm8: 1, sint16: 2, snorm16: 2, unorm16: 2 }.freeze
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#data ⇒ Object
Returns the value of attribute data.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #byte_stride ⇒ Object
- #components ⇒ Object
-
#initialize(data:, format:, count:, &on_change) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(data:, format:, count:, &on_change) ⇒ Attribute
Returns a new instance of Attribute.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stagecraft/core/attribute.rb', line 22 def initialize(data:, format:, count:, &on_change) @format = format.to_sym @count = Integer(count) @version = 0 @on_change = on_change @initialized = false validate! self.data = data @initialized = true end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
20 21 22 |
# File 'lib/stagecraft/core/attribute.rb', line 20 def count @count end |
#data ⇒ Object
Returns the value of attribute data.
20 21 22 |
# File 'lib/stagecraft/core/attribute.rb', line 20 def data @data end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
20 21 22 |
# File 'lib/stagecraft/core/attribute.rb', line 20 def format @format end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
20 21 22 |
# File 'lib/stagecraft/core/attribute.rb', line 20 def version @version end |
Instance Method Details
#byte_stride ⇒ Object
50 51 52 53 |
# File 'lib/stagecraft/core/attribute.rb', line 50 def byte_stride prefix = FORMAT_WIDTHS.keys.find { |candidate| format.to_s.start_with?(candidate.to_s) } FORMAT_WIDTHS.fetch(prefix) * components end |
#components ⇒ Object
46 47 48 |
# File 'lib/stagecraft/core/attribute.rb', line 46 def components FORMAT_COMPONENTS.fetch(format) { raise ArgumentError, "unsupported vertex format #{format.inspect}" } end |