Module: WGPU::TextureFormat
- Defined in:
- lib/wgpu/texture_format.rb,
sig/wgpu.rbs
Constant Summary collapse
- COPY_ALIGNMENT =
256
Class Method Summary collapse
-
.aligned_bytes_per_row(width, format, aspect: :all, alignment: COPY_ALIGNMENT) ⇒ Integer
Returns row bytes rounded up to the requested copy alignment.
-
.block_dimensions(format) ⇒ Array(Integer, Integer)
Returns a format's texel block width and height.
-
.block_info(format, aspect: :all) ⇒ Array(Integer, Integer, Integer)
Returns the copy footprint of one texel block.
-
.block_size(format, aspect: :all) ⇒ Integer
Returns the byte size of one texel block.
-
.bytes_per_row(width, format, aspect: :all) ⇒ Integer
Returns the tightly packed bytes required for one texel row.
Class Method Details
.aligned_bytes_per_row(width, format, aspect: :all, alignment: COPY_ALIGNMENT) ⇒ Integer
Returns row bytes rounded up to the requested copy alignment.
30 31 32 33 |
# File 'lib/wgpu/texture_format.rb', line 30 def aligned_bytes_per_row(width, format, aspect: :all, alignment: COPY_ALIGNMENT) row_bytes = bytes_per_row(width, format, aspect:) ((row_bytes + alignment - 1) / alignment) * alignment end |
.block_dimensions(format) ⇒ Array(Integer, Integer)
Returns a format's texel block width and height.
17 18 19 |
# File 'lib/wgpu/texture_format.rb', line 17 def block_dimensions(format) block_info(format).first(2) end |
.block_info(format, aspect: :all) ⇒ Array(Integer, Integer, Integer)
Returns the copy footprint of one texel block.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wgpu/texture_format.rb', line 41 def block_info(format, aspect: :all) name = normalize_format(format) special = depth_stencil_block_info(name, aspect) return special if special case name.to_s when /\Ar8_/ [1, 1, 1] when /\A(?:r16_|rg8_)/ [1, 1, 2] when /\A(?:r32_|rg16_|rgba8_|bgra8_|rgb10a2_|rg11b10_|rgb9e5_)/ [1, 1, 4] when /\A(?:rg32_|rgba16_)/ [1, 1, 8] when /\Argba32_/ [1, 1, 16] when /\A(?:bc(?:1|4)|etc2_rgb8|etc2_rgb8a1|eac_r11)_/ [4, 4, 8] when /\A(?:bc(?:2|3|5|6h|7)|etc2_rgba8|eac_rg11)_/ [4, 4, 16] when /\Aastc_(\d+)x(\d+)_/ [Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, 16] else raise ArgumentError, "No texel block copy footprint for #{name.inspect}" end end |
.block_size(format, aspect: :all) ⇒ Integer
Returns the byte size of one texel block.
11 12 13 |
# File 'lib/wgpu/texture_format.rb', line 11 def block_size(format, aspect: :all) block_info(format, aspect:).last end |
.bytes_per_row(width, format, aspect: :all) ⇒ Integer
Returns the tightly packed bytes required for one texel row.
23 24 25 26 |
# File 'lib/wgpu/texture_format.rb', line 23 def bytes_per_row(width, format, aspect: :all) block_width, _, bytes = block_info(format, aspect:) ((Integer(width) + block_width - 1) / block_width) * bytes end |