Class: WGPU::TextureView
- Inherits:
-
Object
- Object
- WGPU::TextureView
- Includes:
- NativeResource
- Defined in:
- lib/wgpu/resources/texture_view.rb,
sig/wgpu.rbs
Constant Summary
Constants included from NativeResource
NativeResource::GUARDED_METHOD_EXEMPTIONS
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#texture ⇒ Texture?
readonly
Returns the value of attribute texture.
Attributes included from NativeResource
Class Method Summary collapse
-
.from_handle(handle, device: nil) ⇒ TextureView
Wraps a native texture view handle owned by the caller.
Instance Method Summary collapse
-
#initialize(texture, label: nil, format: nil, dimension: nil, base_mip_level: 0, mip_level_count: nil, base_array_layer: 0, array_layer_count: nil, aspect: :all, usage: nil) ⇒ TextureView
constructor
Creates a view selecting texture format, dimension, subresources, and aspect.
-
#release ⇒ void
Releases the native texture view handle.
-
#size ⇒ Hash?
Returns the parent texture dimensions when known.
Methods included from NativeResource
included, #inspect, #released?, #use
Constructor Details
#initialize(texture, label: nil, format: nil, dimension: nil, base_mip_level: 0, mip_level_count: nil, base_array_layer: 0, array_layer_count: nil, aspect: :all, usage: nil) ⇒ TextureView
Creates a view selecting texture format, dimension, subresources, and aspect.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/wgpu/resources/texture_view.rb', line 10 def initialize(texture, label: nil, format: nil, dimension: nil, base_mip_level: 0, mip_level_count: nil, base_array_layer: 0, array_layer_count: nil, aspect: :all, usage: nil) @texture = texture desc = Native::TextureViewDescriptor.new desc[:next_in_chain] = nil if label @label_ptr = FFI::MemoryPointer.from_string(label) desc[:label][:data] = @label_ptr desc[:label][:length] = label.bytesize else desc[:label][:data] = nil desc[:label][:length] = 0 end desc[:format] = Native::EnumHelper.coerce( Native::TextureFormat, format || :undefined, name: "texture view format" ) desc[:dimension] = Native::EnumHelper.coerce( Native::TextureViewDimension, dimension || :undefined, name: "texture view dimension" ) desc[:base_mip_level] = base_mip_level desc[:mip_level_count] = mip_level_count || 0xFFFFFFFF desc[:base_array_layer] = base_array_layer desc[:array_layer_count] = array_layer_count || 0xFFFFFFFF desc[:aspect] = Native::EnumHelper.coerce(Native::TextureAspect, aspect, name: "texture aspect") desc[:usage] = Native::EnumHelper.coerce_flags( Native::TextureUsage, usage || :none, name: "texture view usage" ) @handle = Native.wgpuTextureCreateView(texture.handle, desc) raise ResourceError, "Failed to create texture view" if @handle.null? end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
5 6 7 |
# File 'lib/wgpu/resources/texture_view.rb', line 5 def handle @handle end |
#texture ⇒ Texture? (readonly)
Returns the value of attribute texture.
5 6 7 |
# File 'lib/wgpu/resources/texture_view.rb', line 5 def texture @texture end |
Class Method Details
.from_handle(handle, device: nil) ⇒ TextureView
Wraps a native texture view handle owned by the caller.
53 54 55 56 57 58 |
# File 'lib/wgpu/resources/texture_view.rb', line 53 def self.from_handle(handle, device: nil) view = adopt_native_handle(handle) view.instance_variable_set(:@texture, nil) view.send(:attach_device_callback_lifetime, device) view end |
Instance Method Details
#release ⇒ void
This method returns an undefined value.
Releases the native texture view handle.
Calling this method more than once has no effect.
71 72 73 74 75 |
# File 'lib/wgpu/resources/texture_view.rb', line 71 def release return if @handle.null? Native.wgpuTextureViewRelease(@handle) @handle = FFI::Pointer::NULL end |
#size ⇒ Hash?
Returns the parent texture dimensions when known.
63 64 65 |
# File 'lib/wgpu/resources/texture_view.rb', line 63 def size @texture&.size end |