# 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
# 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
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.
# 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
Generated with the Darkfish Rdoc Generator 2.