Class: RubyGL::IndexArray
- Inherits:
-
Object
- Object
- RubyGL::IndexArray
- Defined in:
- lib/rubygl/memory.rb
Instance Method Summary collapse
- #draw(components) ⇒ Object
-
#initialize(index_array) ⇒ IndexArray
constructor
A new instance of IndexArray.
-
#release ⇒ Object
This frees the currently allocated GPU buffer for this IndexArray and invalidates this IndexArray object.
Constructor Details
#initialize(index_array) ⇒ IndexArray
Returns a new instance of IndexArray.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rubygl/memory.rb', line 79 def initialize(index_array) buff_ptr = FFI::MemoryPointer.new(:pointer) Native.glGenBuffers(1, buff_ptr) @buffer_id = buff_ptr.get_int(0) @buffer_elements = index_array.size @buffer_valid = true if @buffer_id <= 0 then raise "Could Not Allocate A GPU Buffer For The IndexArray Object" end Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, @buffer_id) index_data = FFI::MemoryPointer.new(:uint, index_array.size) index_data.write_array_of_uint(index_array) Native.glBufferData(Native::GL_ELEMENT_ARRAY_BUFFER, index_data.size, index_data, Native::GL_STATIC_DRAW) Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, 0) end |
Instance Method Details
#draw(components) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/rubygl/memory.rb', line 101 def draw(components) raise "Call To IndexArray#draw On Frozen Object" unless @buffer_valid Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, @buffer_id) Native.glDrawElements(Native::GL_TRIANGLES, @buffer_elements, Native::GL_UNSIGNED_INT, FFI::MemoryPointer::NULL) Native.glBindBuffer(Native::GL_ELEMENT_ARRAY_BUFFER, 0) end |
#release ⇒ Object
This frees the currently allocated GPU buffer for this IndexArray and invalidates this IndexArray object. Any calls to this object after calling this method will throw a runtime error.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rubygl/memory.rb', line 114 def release() raise "Call To IndexArray#release On Invalid Object" unless @buffer_valid buff_ptr = FFI::MemoryPointer.new(:uint) buff_ptr.write_uint(@buffer_id) Native.glDeleteBuffers(1, buff_ptr) @buffer_valid = false end |