Class: WGPU::Texture
- Inherits:
-
Object
- Object
- WGPU::Texture
- 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
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#surface_status ⇒ Symbol?
readonly
Returns the value of attribute surface_status.
Attributes included from NativeResource
Class Method Summary collapse
-
.from_handle(handle, surface_status: nil, device: nil) ⇒ Texture
Wraps a native texture handle, such as a surface-acquired texture.
Instance Method Summary collapse
-
#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.
-
#depth_or_array_layers ⇒ Integer
Returns the texture depth or array layer count.
-
#destroy ⇒ void
Destroys the texture's storage.
-
#dimension ⇒ Symbol, Integer
Returns the texture dimension.
-
#format ⇒ Symbol, Integer
Returns the texture format.
-
#height ⇒ Integer
Returns the texture height in texels.
-
#initialize(device, label: nil, size:, format:, usage:, dimension: :d2, mip_level_count: 1, sample_count: 1, view_formats: []) ⇒ Texture
constructor
Creates a GPU texture.
-
#mip_level_count ⇒ Integer
Returns the number of mip levels.
-
#release ⇒ void
Releases the native texture handle.
-
#sample_count ⇒ Integer
Returns the multisample count.
-
#size ⇒ Hash{Symbol => Integer}
Returns the texture extent.
-
#usage ⇒ Integer
Returns the texture usage flags.
-
#width ⇒ Integer
Returns the texture width in texels.
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.
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
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
5 6 7 |
# File 'lib/wgpu/resources/texture.rb', line 5 def handle @handle end |
#surface_status ⇒ Symbol? (readonly)
Returns the value of attribute surface_status.
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.
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.
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_layers ⇒ Integer
Returns the texture depth or array layer count.
93 94 95 |
# File 'lib/wgpu/resources/texture.rb', line 93 def depth_or_array_layers Native.wgpuTextureGetDepthOrArrayLayers(@handle) end |
#destroy ⇒ void
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 |
#dimension ⇒ Symbol, Integer
Returns the texture dimension.
111 112 113 |
# File 'lib/wgpu/resources/texture.rb', line 111 def dimension Native.wgpuTextureGetDimension(@handle) end |
#format ⇒ Symbol, Integer
Returns the texture format.
117 118 119 |
# File 'lib/wgpu/resources/texture.rb', line 117 def format Native.wgpuTextureGetFormat(@handle) end |
#height ⇒ Integer
Returns the texture height in texels.
87 88 89 |
# File 'lib/wgpu/resources/texture.rb', line 87 def height Native.wgpuTextureGetHeight(@handle) end |
#mip_level_count ⇒ Integer
Returns the number of mip levels.
99 100 101 |
# File 'lib/wgpu/resources/texture.rb', line 99 def mip_level_count Native.wgpuTextureGetMipLevelCount(@handle) end |
#release ⇒ void
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_count ⇒ Integer
Returns the multisample count.
105 106 107 |
# File 'lib/wgpu/resources/texture.rb', line 105 def sample_count Native.wgpuTextureGetSampleCount(@handle) end |
#size ⇒ Hash{Symbol => Integer}
Returns the texture extent.
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 |
#usage ⇒ Integer
Returns the texture usage flags.
123 124 125 |
# File 'lib/wgpu/resources/texture.rb', line 123 def usage Native.wgpuTextureGetUsage(@handle) end |
#width ⇒ Integer
Returns the texture width in texels.
71 72 73 |
# File 'lib/wgpu/resources/texture.rb', line 71 def width Native.wgpuTextureGetWidth(@handle) end |