Class: WGPU::CanvasContext
- Inherits:
-
Object
- Object
- WGPU::CanvasContext
- Includes:
- NativeResource
- Defined in:
- lib/wgpu/core/canvas_context.rb,
sig/wgpu.rbs
Constant Summary
Constants included from NativeResource
NativeResource::GUARDED_METHOD_EXEMPTIONS
Instance Attribute Summary collapse
-
#physical_size ⇒ [Integer, Integer]
readonly
Returns the value of attribute physical_size.
Attributes included from NativeResource
Instance Method Summary collapse
-
#configure(device:, format: nil, usage: :render_attachment, view_formats: [], color_space: "srgb", tone_mapping: nil, alpha_mode: :opaque, width: nil, height: nil, present_mode: :fifo) ⇒ Hash
Configures the backing surface for presentation.
-
#get_configuration ⇒ Hash?
Returns the most recent canvas configuration.
-
#get_current_texture ⇒ Texture
Acquires the texture for the current presentation frame.
-
#get_preferred_format(adapter) ⇒ Symbol
Returns the surface format preferred by an adapter.
-
#initialize(instance, present_info = {}) ⇒ CanvasContext
constructor
Creates a canvas context for platform presentation information.
-
#present ⇒ void
Presents the current surface texture.
-
#release ⇒ void
Releases the backing surface and clears the configuration.
-
#set_physical_size(width, height) ⇒ Array<Integer>
Updates the drawable's physical pixel size.
-
#unconfigure ⇒ void
Removes the current surface configuration.
Methods included from NativeResource
included, #inspect, #released?, #use
Constructor Details
#initialize(instance, present_info = {}) ⇒ CanvasContext
Creates a canvas context for platform presentation information.
10 11 12 13 14 15 16 |
# File 'lib/wgpu/core/canvas_context.rb', line 10 def initialize(instance, present_info = {}) @instance = instance @present_info = present_info || {} @surface = @present_info[:surface] @physical_size = [0, 0] @config = nil end |
Instance Attribute Details
#physical_size ⇒ [Integer, Integer] (readonly)
Returns the value of attribute physical_size.
5 6 7 |
# File 'lib/wgpu/core/canvas_context.rb', line 5 def physical_size @physical_size end |
Instance Method Details
#configure(device:, format: nil, usage: :render_attachment, view_formats: [], color_space: "srgb", tone_mapping: nil, alpha_mode: :opaque, width: nil, height: nil, present_mode: :fifo) ⇒ Hash
Configures the backing surface for presentation.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/wgpu/core/canvas_context.rb', line 50 def configure(device:, format: nil, usage: :render_attachment, view_formats: [], color_space: "srgb", tone_mapping: nil, alpha_mode: :opaque, width: nil, height: nil, present_mode: :fifo) ensure_surface width = width || @physical_size[0] height = height || @physical_size[1] raise SurfaceError, "Surface size must be positive before configure" if width.to_i <= 0 || height.to_i <= 0 resolved_format = format || get_preferred_format(device.adapter) @surface.configure( device: device, format: resolved_format, usage: usage, width: width, height: height, present_mode: present_mode, alpha_mode: alpha_mode, view_formats: view_formats ) @config = { device: device, format: resolved_format, usage: usage, view_formats: view_formats, color_space: color_space, tone_mapping: tone_mapping, alpha_mode: alpha_mode, width: width, height: height, present_mode: present_mode } end |
#get_configuration ⇒ Hash?
Returns the most recent canvas configuration.
41 42 43 |
# File 'lib/wgpu/core/canvas_context.rb', line 41 def get_configuration @config end |
#get_current_texture ⇒ Texture
Acquires the texture for the current presentation frame.
94 95 96 97 98 |
# File 'lib/wgpu/core/canvas_context.rb', line 94 def get_current_texture raise SurfaceError, "Canvas context must be configured before get_current_texture" unless @config @surface.current_texture end |
#get_preferred_format(adapter) ⇒ Symbol
Returns the surface format preferred by an adapter.
33 34 35 36 |
# File 'lib/wgpu/core/canvas_context.rb', line 33 def get_preferred_format(adapter) ensure_surface @surface.get_preferred_format(adapter) end |
#present ⇒ void
This method returns an undefined value.
Presents the current surface texture.
102 103 104 |
# File 'lib/wgpu/core/canvas_context.rb', line 102 def present @surface&.present end |
#release ⇒ void
This method returns an undefined value.
Releases the backing surface and clears the configuration.
109 110 111 112 113 |
# File 'lib/wgpu/core/canvas_context.rb', line 109 def release @surface&.release @surface = nil @config = nil end |
#set_physical_size(width, height) ⇒ Array<Integer>
Updates the drawable's physical pixel size.
23 24 25 26 27 |
# File 'lib/wgpu/core/canvas_context.rb', line 23 def set_physical_size(width, height) raise ArgumentError, "width and height must be non-negative" if width.to_i.negative? || height.to_i.negative? @physical_size = [width.to_i, height.to_i] end |
#unconfigure ⇒ void
This method returns an undefined value.
Removes the current surface configuration.
84 85 86 87 |
# File 'lib/wgpu/core/canvas_context.rb', line 84 def unconfigure @surface&.unconfigure @config = nil end |