Class: WGPU::Texture

Inherits:
Object
  • Object
show all
Includes:
NativeResource
Defined in:
lib/wgpu/resources/texture.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(device, label: nil, size:, format:, usage:, dimension: :d2, mip_level_count: 1, sample_count: 1, view_formats: []) ⇒ Texture

Creates a GPU texture.

Parameters:

  • device (Device)

    owning device

  • size (Hash, Array)

    texture extent

  • format (Symbol, Integer)

    texel format

  • usage (Symbol, Array<Symbol>, Integer)

    usage flags

Raises:



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/texture.rb', line 13

def initialize(device, label: nil, size:, format:, usage:, dimension: :d2, mip_level_count: 1, sample_count: 1, view_formats: [])
  @device = device

  desc, keepalive = build_descriptor(
    label:,
    size:,
    format:,
    usage:,
    dimension:,
    mip_level_count:,
    sample_count:,
    view_formats:
  )
  @descriptor_keepalive = keepalive

  device.push_error_scope(:validation)
  @handle = Native.wgpuDeviceCreateTexture(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 texture"
    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/texture.rb', line 5

def handle
  @handle
end

#surface_statusSymbol? (readonly)

Returns the value of attribute surface_status.

Returns:

  • (Symbol, nil)


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

def surface_status
  @surface_status
end

Class Method Details

.from_handle(handle, surface_status: nil, device: nil) ⇒ Texture

Wraps a native texture handle, such as a surface-acquired texture.

Parameters:

  • handle (FFI::Pointer)

    native texture handle

  • surface_status (Symbol, nil) (defaults to: nil)

    acquisition status associated with the texture

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

    device whose callbacks the texture may use

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

Returns:



45
46
47
48
49
50
51
# File 'lib/wgpu/resources/texture.rb', line 45

def self.from_handle(handle, surface_status: nil, device: nil)
  texture = adopt_native_handle(handle)
  texture.instance_variable_set(:@device, device)
  texture.instance_variable_set(:@surface_status, surface_status)
  texture.send(:attach_device_callback_lifetime, device)
  texture
end

Instance Method Details

#create_view(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 into this texture.

Parameters:

  • (Object)

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/wgpu/resources/texture.rb', line 55

def create_view(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.new(self,
    label: label,
    format: format,
    dimension: dimension,
    base_mip_level: base_mip_level,
    mip_level_count: mip_level_count,
    base_array_layer: base_array_layer,
    array_layer_count: array_layer_count,
    aspect: aspect,
    usage: usage
  )
end

#depth_or_array_layersInteger

Returns the texture depth or array layer count.

Returns:

  • (Integer)


93
94
95
# File 'lib/wgpu/resources/texture.rb', line 93

def depth_or_array_layers
  Native.wgpuTextureGetDepthOrArrayLayers(@handle)
end

#destroyvoid

This method returns an undefined value.

Destroys the texture's storage.



129
130
131
# File 'lib/wgpu/resources/texture.rb', line 129

def destroy
  Native.wgpuTextureDestroy(@handle)
end

#dimensionSymbol, Integer

Returns the texture dimension.

Returns:

  • (Symbol, Integer)


111
112
113
# File 'lib/wgpu/resources/texture.rb', line 111

def dimension
  Native.wgpuTextureGetDimension(@handle)
end

#formatSymbol, Integer

Returns the texture format.

Returns:

  • (Symbol, Integer)


117
118
119
# File 'lib/wgpu/resources/texture.rb', line 117

def format
  Native.wgpuTextureGetFormat(@handle)
end

#heightInteger

Returns the texture height in texels.

Returns:

  • (Integer)


87
88
89
# File 'lib/wgpu/resources/texture.rb', line 87

def height
  Native.wgpuTextureGetHeight(@handle)
end

#mip_level_countInteger

Returns the number of mip levels.

Returns:

  • (Integer)


99
100
101
# File 'lib/wgpu/resources/texture.rb', line 99

def mip_level_count
  Native.wgpuTextureGetMipLevelCount(@handle)
end

#releasevoid

This method returns an undefined value.

Releases the native texture handle.

Calling this method more than once has no effect.



137
138
139
140
141
# File 'lib/wgpu/resources/texture.rb', line 137

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

#sample_countInteger

Returns the multisample count.

Returns:

  • (Integer)


105
106
107
# File 'lib/wgpu/resources/texture.rb', line 105

def sample_count
  Native.wgpuTextureGetSampleCount(@handle)
end

#sizeHash{Symbol => Integer}

Returns the texture extent.

Returns:

  • (Hash{Symbol => Integer})


77
78
79
80
81
82
83
# File 'lib/wgpu/resources/texture.rb', line 77

def size
  {
    width: width,
    height: height,
    depth_or_array_layers: depth_or_array_layers
  }
end

#usageInteger

Returns the texture usage flags.

Returns:

  • (Integer)


123
124
125
# File 'lib/wgpu/resources/texture.rb', line 123

def usage
  Native.wgpuTextureGetUsage(@handle)
end

#widthInteger

Returns the texture width in texels.

Returns:

  • (Integer)


71
72
73
# File 'lib/wgpu/resources/texture.rb', line 71

def width
  Native.wgpuTextureGetWidth(@handle)
end