Class: Rugl::Resources::Vao

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

Instance Attribute Summary collapse

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods inherited from Base

#destroyed?

Constructor Details

#initialize(context) ⇒ Vao

Returns a new instance of Vao.



8
9
10
11
# File 'lib/rugl/resources/vao.rb', line 8

def initialize(context)
  super(context)
  @id = allocate_gl_id(:GenVertexArrays)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

#bindObject



13
14
15
16
17
# File 'lib/rugl/resources/vao.rb', line 13

def bind
  ensure_alive!
  gl_call(:BindVertexArray, @id)
  self
end

#destroyObject



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

def destroy
  return if destroyed?

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

#setup_attribute(location:, buffer:, size:, type: :float, stride: 0, offset: 0, divisor: nil, normalized: false) ⇒ Object

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rugl/resources/vao.rb', line 26

def setup_attribute(location:, buffer:, size:, type: :float, stride: 0, offset: 0, divisor: nil, normalized: false)
  ensure_alive!
  raise ResourceError, "Attribute location must be >= 0" if location.to_i.negative?

  bind
  buffer.bind if buffer.respond_to?(:bind)

  gl_type = type.is_a?(Integer) ? type : Util.to_gl_buffer_type(type, gl: gl)
  normalized_flag = normalized ? gl_const(:TRUE) : gl_const(:FALSE)

  gl_call(:EnableVertexAttribArray, location.to_i)
  gl_call(
    :VertexAttribPointer,
    location.to_i,
    size.to_i,
    gl_type,
    normalized_flag,
    stride.to_i,
    offset.to_i
  )

  if !divisor.nil? && gl_supports?(:VertexAttribDivisor)
    gl_call(:VertexAttribDivisor, location.to_i, divisor.to_i)
  end

  self
end

#unbindObject



19
20
21
22
23
24
# File 'lib/rugl/resources/vao.rb', line 19

def unbind
  return unless gl_supports?(:BindVertexArray)

  gl_call(:BindVertexArray, 0)
  self
end