Class: WGPU::BufferMappedRange
- Inherits:
-
Object
- Object
- WGPU::BufferMappedRange
- Defined in:
- lib/wgpu/resources/buffer.rb,
sig/wgpu.rbs
Instance Method Summary collapse
-
#initialize(pointer, size) ⇒ BufferMappedRange
constructor
Wraps a native mapped memory range.
-
#read(type: :f32, count: nil) ⇒ Array
Decodes typed values from the mapped range.
-
#read_bytes ⇒ String
Returns all bytes in the mapped range.
-
#read_float64s(count = nil) ⇒ Array<Float>
Reads 64-bit floating-point values from the mapped range.
-
#read_floats(count = nil) ⇒ Array<Float>
Reads 32-bit floating-point values from the mapped range.
-
#read_int32s(count = nil) ⇒ Array<Integer>
Reads signed 32-bit integers from the mapped range.
-
#read_uint16s(count = nil) ⇒ Array<Integer>
Reads unsigned 16-bit integers from the mapped range.
-
#read_uint32s(count = nil) ⇒ Array<Integer>
Reads unsigned 32-bit integers from the mapped range.
-
#read_uint8s(count = nil) ⇒ Array<Integer>
Reads unsigned 8-bit integers from the mapped range.
-
#write(data, type: :f32) ⇒ void
Encodes typed values into the mapped range.
-
#write_bytes(data) ⇒ void
Writes bytes at the start of the mapped range.
-
#write_float64s(data) ⇒ void
Writes 64-bit floating-point values into the mapped range.
-
#write_floats(data) ⇒ void
Writes 32-bit floating-point values into the mapped range.
-
#write_int32s(data) ⇒ void
Writes signed 32-bit integers into the mapped range.
-
#write_uint16s(data) ⇒ void
Writes unsigned 16-bit integers into the mapped range.
-
#write_uint32s(data) ⇒ void
Writes unsigned 32-bit integers into the mapped range.
-
#write_uint8s(data) ⇒ void
Writes unsigned 8-bit integers into the mapped range.
Constructor Details
#initialize(pointer, size) ⇒ BufferMappedRange
Wraps a native mapped memory range.
382 383 384 385 |
# File 'lib/wgpu/resources/buffer.rb', line 382 def initialize(pointer, size) @pointer = pointer @size = size end |
Instance Method Details
#read(type: :f32, count: nil) ⇒ Array
Decodes typed values from the mapped range.
493 494 495 496 497 498 499 500 501 502 |
# File 'lib/wgpu/resources/buffer.rb', line 493 def read(type: :f32, count: nil) byte_size = DataTypes.byte_size(type) count ||= @size / byte_size count = Integer(count) raise ArgumentError, "count must be non-negative" if count.negative? bytes_to_read = count * byte_size validate_byte_length!(bytes_to_read) DataTypes.unpack(@pointer.read_bytes(bytes_to_read), type:) end |
#read_bytes ⇒ String
Returns all bytes in the mapped range.
518 519 520 |
# File 'lib/wgpu/resources/buffer.rb', line 518 def read_bytes @pointer.read_bytes(@size) end |
#read_float64s(count = nil) ⇒ Array<Float>
Reads 64-bit floating-point values from the mapped range.
442 443 444 |
# File 'lib/wgpu/resources/buffer.rb', line 442 def read_float64s(count = nil) read(type: :f64, count:) end |
#read_floats(count = nil) ⇒ Array<Float>
Reads 32-bit floating-point values from the mapped range.
391 392 393 |
# File 'lib/wgpu/resources/buffer.rb', line 391 def read_floats(count = nil) read(type: :f32, count:) end |
#read_int32s(count = nil) ⇒ Array<Integer>
Reads signed 32-bit integers from the mapped range.
425 426 427 |
# File 'lib/wgpu/resources/buffer.rb', line 425 def read_int32s(count = nil) read(type: :i32, count:) end |
#read_uint16s(count = nil) ⇒ Array<Integer>
Reads unsigned 16-bit integers from the mapped range.
459 460 461 |
# File 'lib/wgpu/resources/buffer.rb', line 459 def read_uint16s(count = nil) read(type: :u16, count:) end |
#read_uint32s(count = nil) ⇒ Array<Integer>
Reads unsigned 32-bit integers from the mapped range.
408 409 410 |
# File 'lib/wgpu/resources/buffer.rb', line 408 def read_uint32s(count = nil) read(type: :u32, count:) end |
#read_uint8s(count = nil) ⇒ Array<Integer>
Reads unsigned 8-bit integers from the mapped range.
476 477 478 |
# File 'lib/wgpu/resources/buffer.rb', line 476 def read_uint8s(count = nil) read(type: :u8, count:) end |
#write(data, type: :f32) ⇒ void
This method returns an undefined value.
Encodes typed values into the mapped range.
509 510 511 512 513 514 |
# File 'lib/wgpu/resources/buffer.rb', line 509 def write(data, type: :f32) bytes = data.is_a?(String) ? data : DataTypes.pack(data, type:) raise ArgumentError, "data exceeds mapped range" if bytes.bytesize > @size @pointer.put_bytes(0, bytes) end |
#write_bytes(data) ⇒ void
This method returns an undefined value.
Writes bytes at the start of the mapped range.
525 526 527 528 |
# File 'lib/wgpu/resources/buffer.rb', line 525 def write_bytes(data) validate_byte_length!(data.bytesize) @pointer.put_bytes(0, data) end |
#write_float64s(data) ⇒ void
This method returns an undefined value.
Writes 64-bit floating-point values into the mapped range.
451 452 453 |
# File 'lib/wgpu/resources/buffer.rb', line 451 def write_float64s(data) write(data, type: :f64) end |
#write_floats(data) ⇒ void
This method returns an undefined value.
Writes 32-bit floating-point values into the mapped range.
400 401 402 |
# File 'lib/wgpu/resources/buffer.rb', line 400 def write_floats(data) write(data, type: :f32) end |
#write_int32s(data) ⇒ void
This method returns an undefined value.
Writes signed 32-bit integers into the mapped range.
434 435 436 |
# File 'lib/wgpu/resources/buffer.rb', line 434 def write_int32s(data) write(data, type: :i32) end |
#write_uint16s(data) ⇒ void
This method returns an undefined value.
Writes unsigned 16-bit integers into the mapped range.
468 469 470 |
# File 'lib/wgpu/resources/buffer.rb', line 468 def write_uint16s(data) write(data, type: :u16) end |
#write_uint32s(data) ⇒ void
This method returns an undefined value.
Writes unsigned 32-bit integers into the mapped range.
417 418 419 |
# File 'lib/wgpu/resources/buffer.rb', line 417 def write_uint32s(data) write(data, type: :u32) end |
#write_uint8s(data) ⇒ void
This method returns an undefined value.
Writes unsigned 8-bit integers into the mapped range.
485 486 487 |
# File 'lib/wgpu/resources/buffer.rb', line 485 def write_uint8s(data) write(data, type: :u8) end |