Class: Rugl::Resources::Buffer
- Defined in:
- lib/rugl/resources/buffer.rb
Instance Attribute Summary collapse
-
#byte_length ⇒ Object
readonly
Returns the value of attribute byte_length.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Attributes inherited from Base
Instance Method Summary collapse
- #bind ⇒ Object
- #destroy ⇒ Object
- #gl_type ⇒ Object
-
#initialize(context, source) ⇒ Buffer
constructor
A new instance of Buffer.
- #subdata(data, offset: 0) ⇒ Object
- #update(data:) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(context, source) ⇒ Buffer
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rugl/resources/buffer.rb', line 8 def initialize(context, source) super(context) @target = gl_const(:ARRAY_BUFFER) @usage = :static @type = :float @length = 0 @byte_length = 0 @id = allocate_gl_id(:GenBuffers) bind normalized = normalize_source(source) upload_payload(*normalized) end |
Instance Attribute Details
#byte_length ⇒ Object (readonly)
Returns the value of attribute byte_length.
6 7 8 |
# File 'lib/rugl/resources/buffer.rb', line 6 def byte_length @byte_length end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/rugl/resources/buffer.rb', line 6 def length @length end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'lib/rugl/resources/buffer.rb', line 6 def target @target end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/rugl/resources/buffer.rb', line 6 def type @type end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
6 7 8 |
# File 'lib/rugl/resources/buffer.rb', line 6 def usage @usage end |
Instance Method Details
#bind ⇒ Object
22 23 24 25 26 |
# File 'lib/rugl/resources/buffer.rb', line 22 def bind ensure_alive! gl_call(:BindBuffer, @target, @id) if gl_supports?(:BindBuffer) self end |
#destroy ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/rugl/resources/buffer.rb', line 58 def destroy return if destroyed? delete_gl_id(:DeleteBuffers, @id) mark_destroyed! nil end |
#gl_type ⇒ Object
66 67 68 |
# File 'lib/rugl/resources/buffer.rb', line 66 def gl_type Util.to_gl_buffer_type(@type, gl: gl) end |
#subdata(data, offset: 0) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rugl/resources/buffer.rb', line 40 def subdata(data, offset: 0) ensure_alive! raise ResourceError, "Buffer subdata requires data" if data.nil? bind payload, _count, bytes = normalize_data(data, type: @type) if gl_supports?(:BufferSubData) gl_call(:BufferSubData, @target, offset.to_i, bytes, payload) elsif gl_supports?(:NamedBufferSubData) gl_call(:NamedBufferSubData, @id, offset.to_i, bytes, payload) else raise ResourceError, "OpenGL backend does not support BufferSubData" end self end |
#update(data:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rugl/resources/buffer.rb', line 28 def update(data:) ensure_alive! bind payload, count, bytes = normalize_data(data, type: @type) upload(payload, bytes) @length = count @byte_length = bytes self end |