Class: WGPU::TextureView

Inherits:
Object
  • Object
show all
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

Attributes included from NativeResource

#label

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • texture (Texture)

    parent texture

Raises:



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

#handleObject (readonly)

Returns the value of attribute handle.

Returns:

  • (Object)


5
6
7
# File 'lib/wgpu/resources/texture_view.rb', line 5

def handle
  @handle
end

#textureTexture? (readonly)

Returns the value of attribute texture.

Returns:



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.

Parameters:

  • handle (FFI::Pointer)

    native texture view handle

  • device (Device, nil) (defaults to: nil)

    device whose callbacks the view may use

  • (Object)
  • device: (Device, nil) (defaults to: nil)

Returns:

  • (TextureView)

    adopted wrapper without a parent texture



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

#releasevoid

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

#sizeHash?

Returns the parent texture dimensions when known.

Returns:

  • (Hash, nil)

    texture extent, or nil for an adopted standalone view



63
64
65
# File 'lib/wgpu/resources/texture_view.rb', line 63

def size
  @texture&.size
end