Class: Rugl::Resources::Elements

Inherits:
Base
  • Object
show all
Defined in:
lib/rugl/resources/elements.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #id

Instance Method Summary collapse

Methods inherited from Base

#destroyed?

Constructor Details

#initialize(context, source) ⇒ Elements



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rugl/resources/elements.rb', line 8

def initialize(context, source)
  super(context)
  @target = gl_const(:ELEMENT_ARRAY_BUFFER)
  @usage = :static
  @type = :uint16
  @primitive = :triangles
  @length = 0
  @count = 0
  @byte_length = 0
  @id = allocate_gl_id(:GenBuffers)

  bind
  payload, index_count, byte_size = normalize_source(source)
  upload(payload, byte_size)
  @length = index_count
  @count = index_count
  @byte_length = byte_size
end

Instance Attribute Details

#byte_lengthObject (readonly)

Returns the value of attribute byte_length.



6
7
8
# File 'lib/rugl/resources/elements.rb', line 6

def byte_length
  @byte_length
end

#countObject (readonly)

Returns the value of attribute count.



6
7
8
# File 'lib/rugl/resources/elements.rb', line 6

def count
  @count
end

#lengthObject (readonly)

Returns the value of attribute length.



6
7
8
# File 'lib/rugl/resources/elements.rb', line 6

def length
  @length
end

#primitiveObject (readonly)

Returns the value of attribute primitive.



6
7
8
# File 'lib/rugl/resources/elements.rb', line 6

def primitive
  @primitive
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/rugl/resources/elements.rb', line 6

def target
  @target
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/rugl/resources/elements.rb', line 6

def type
  @type
end

#usageObject (readonly)

Returns the value of attribute usage.



6
7
8
# File 'lib/rugl/resources/elements.rb', line 6

def usage
  @usage
end

Instance Method Details

#bindObject



27
28
29
30
31
# File 'lib/rugl/resources/elements.rb', line 27

def bind
  ensure_alive!
  gl_call(:BindBuffer, @target, @id) if gl_supports?(:BindBuffer)
  self
end

#destroyObject



54
55
56
57
58
59
60
# File 'lib/rugl/resources/elements.rb', line 54

def destroy
  return if destroyed?

  delete_gl_id(:DeleteBuffers, @id)
  mark_destroyed!
  nil
end

#gl_typeObject



62
63
64
# File 'lib/rugl/resources/elements.rb', line 62

def gl_type
  Util.to_gl_buffer_type(@type, gl: gl)
end

#subdata(data, offset: 0) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/rugl/resources/elements.rb', line 46

def subdata(data, offset: 0)
  ensure_alive!

  payload, _count, byte_size = normalize_indices(data)
  gl_call(:BufferSubData, @target, offset.to_i, byte_size, payload)
  self
end

#update(data:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rugl/resources/elements.rb', line 33

def update(data:)
  ensure_alive!
  bind

  payload, index_count, byte_size = normalize_indices(data)
  upload(payload, byte_size)
  @length = index_count
  @count = index_count
  @byte_length = byte_size

  self
end