Class: Rugl::Resources::Vao
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Attributes inherited from Base
Instance Method Summary collapse
- #bind ⇒ Object
- #destroy ⇒ Object
-
#initialize(context) ⇒ Vao
constructor
A new instance of Vao.
- #setup_attribute(location:, buffer:, size:, type: :float, stride: 0, offset: 0, divisor: nil, normalized: false) ⇒ Object
- #unbind ⇒ Object
Methods inherited from Base
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
#id ⇒ Object (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
#bind ⇒ Object
13 14 15 16 17 |
# File 'lib/rugl/resources/vao.rb', line 13 def bind ensure_alive! gl_call(:BindVertexArray, @id) self end |
#destroy ⇒ Object
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
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 |
#unbind ⇒ Object
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 |