Class: GL::VertexArray

Inherits:
Object
  • Object
show all
Defined in:
lib/opengl-aux/vertex_array.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) {|_self| ... } ⇒ VertexArray

Returns a new instance of VertexArray

Yields:

  • (_self)

Yield Parameters:


37
38
39
40
# File 'lib/opengl-aux/vertex_array.rb', line 37

def initialize(name = nil)
  @name = name || 0
  yield self if block_given?
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


35
36
37
# File 'lib/opengl-aux/vertex_array.rb', line 35

def name
  @name
end

Class Method Details

.current_bindingObject


18
19
20
# File 'lib/opengl-aux/vertex_array.rb', line 18

def current_binding
  GL.glGetInteger(GL::GL_VERTEX_ARRAY_BINDING)
end

.preserve_bindingObject

Raises:

  • (ArgumentError)

22
23
24
25
26
27
28
29
30
# File 'lib/opengl-aux/vertex_array.rb', line 22

def preserve_binding
  raise ArgumentError, "No block given" unless block_given?
  binding = current_binding
  begin
    yield
  ensure
    GL.glBindVertexArray(binding)
  end
end

Instance Method Details

#bindObject


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/opengl-aux/vertex_array.rb', line 54

def bind
  if block_given?
    self.class.preserve_binding do
      bind
      yield self
    end
  else
    if @name == 0
      @name = GL.glGenVertexArrays(1)
      if @name == 0
        raise GL::GLCreateError, "Unable to allocate vertex array object"
      end
    end

    GL.glBindVertexArray(@name)
    self
  end
end

#deleteObject


42
43
44
45
46
47
48
# File 'lib/opengl-aux/vertex_array.rb', line 42

def delete
  if @name != 0
    GL.glDeleteVertexArrays(@name)
    @name = 0
  end
  self
end

#is_vertex_array?Boolean


50
51
52
# File 'lib/opengl-aux/vertex_array.rb', line 50

def is_vertex_array?
  GL::glIsVertexArray(@name) != GL::GL_FALSE
end