Class: WGPU::Sampler

Inherits:
Object
  • Object
show all
Includes:
NativeResource
Defined in:
lib/wgpu/resources/sampler.rb,
sig/wgpu.rbs

Constant Summary

Constants included from NativeResource

NativeResource::GUARDED_METHOD_EXEMPTIONS

Instance Attribute Summary collapse

Attributes included from NativeResource

#label

Instance Method Summary collapse

Methods included from NativeResource

included, #inspect, #released?, #use

Constructor Details

#initialize(device, label: nil, address_mode_u: :clamp_to_edge, address_mode_v: :clamp_to_edge, address_mode_w: :clamp_to_edge, mag_filter: :nearest, min_filter: :nearest, mipmap_filter: :nearest, lod_min_clamp: 0.0, lod_max_clamp: 32.0, compare: nil, max_anisotropy: 1) ⇒ Sampler

Creates a texture sampler with address, filter, and comparison settings.

Parameters:

  • device (Device)

    owning device

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
# File 'lib/wgpu/resources/sampler.rb', line 10

def initialize(device, label: nil, address_mode_u: :clamp_to_edge, address_mode_v: :clamp_to_edge, address_mode_w: :clamp_to_edge, mag_filter: :nearest, min_filter: :nearest, mipmap_filter: :nearest, lod_min_clamp: 0.0, lod_max_clamp: 32.0, compare: nil, max_anisotropy: 1)
  @device = device

  desc, keepalive = build_descriptor(
    label:,
    address_mode_u:,
    address_mode_v:,
    address_mode_w:,
    mag_filter:,
    min_filter:,
    mipmap_filter:,
    lod_min_clamp:,
    lod_max_clamp:,
    compare:,
    max_anisotropy:
  )
  @descriptor_keepalive = keepalive

  device.push_error_scope(:validation)
  @handle = Native.wgpuDeviceCreateSampler(device.handle, desc)
  error = device.pop_error_scope
  @descriptor_keepalive = nil

  if @handle.null? || (error[:type] && error[:type] != :no_error)
    msg = error[:message] || "Failed to create sampler"
    raise ResourceError, msg
  end
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.

Returns:

  • (Object)


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

def handle
  @handle
end

Instance Method Details

#releasevoid

This method returns an undefined value.

Releases the native sampler handle.

Calling this method more than once has no effect.



43
44
45
46
47
# File 'lib/wgpu/resources/sampler.rb', line 43

def release
  return if @handle.null?
  Native.wgpuSamplerRelease(@handle)
  @handle = FFI::Pointer::NULL
end