Class: Stagecraft::Attribute

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#countObject (readonly)

Returns the value of attribute count.



20
21
22
# File 'lib/stagecraft/core/attribute.rb', line 20

def count
  @count
end

#dataObject

Returns the value of attribute data.



20
21
22
# File 'lib/stagecraft/core/attribute.rb', line 20

def data
  @data
end

#formatObject (readonly)

Returns the value of attribute format.



20
21
22
# File 'lib/stagecraft/core/attribute.rb', line 20

def format
  @format
end

#versionObject (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_strideObject



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

#componentsObject



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