Class: GL::Buffer

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target = nil, name = nil) {|_self| ... } ⇒ Buffer

Returns a new instance of Buffer

Yields:

  • (_self)

Yield Parameters:

  • _self (GL::Buffer)

    the object that the method was called on


61
62
63
64
65
# File 'lib/opengl-aux/buffer.rb', line 61

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

Class Attribute Details

.__buffer_target_getters__Object

Returns the value of attribute buffer_target_getters


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

def __buffer_target_getters__
  @__buffer_target_getters__
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


58
59
60
# File 'lib/opengl-aux/buffer.rb', line 58

def name
  @name
end

#targetObject

Returns the value of attribute target


59
60
61
# File 'lib/opengl-aux/buffer.rb', line 59

def target
  @target
end

Class Method Details

.current_binding(target) ⇒ Object


20
21
22
# File 'lib/opengl-aux/buffer.rb', line 20

def current_binding(target)
  GL.glGetInteger(__buffer_target_getters__[target])
end

.preserve_binding(target) ⇒ Object

Raises:

  • (ArgumentError)

24
25
26
27
28
29
30
31
32
# File 'lib/opengl-aux/buffer.rb', line 24

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

Instance Method Details

#bind(target = nil) ⇒ Object

Raises:

  • (ArgumentError)

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/opengl-aux/buffer.rb', line 79

def bind(target = nil)
  target ||= (@target || GL::GL_ARRAY_BUFFER)
  @target ||= target
  raise ArgumentError, "No target given and no previous target" unless target

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

    GL.glBindBuffer(target, @name)
    self
  end
end

#deleteObject


71
72
73
74
75
76
77
# File 'lib/opengl-aux/buffer.rb', line 71

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

#is_buffer?Boolean


67
68
69
# File 'lib/opengl-aux/buffer.rb', line 67

def is_buffer?
  GL::glIsBuffer(@name) != GL::GL_FALSE
end