Class: Stagecraft::Renderer::GPUContext
- Inherits:
-
Object
- Object
- Stagecraft::Renderer::GPUContext
- Defined in:
- lib/stagecraft/renderer/gpu_context.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#surface ⇒ Object
readonly
Returns the value of attribute surface.
-
#surface_format ⇒ Object
readonly
Returns the value of attribute surface_format.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #current_target ⇒ Object
- #dispose ⇒ Object
-
#initialize(window: nil, width:, height:, device: nil, queue: nil, surface: nil) ⇒ GPUContext
constructor
A new instance of GPUContext.
- #present ⇒ Object
- #resize(width, height) ⇒ Object
Constructor Details
#initialize(window: nil, width:, height:, device: nil, queue: nil, surface: nil) ⇒ GPUContext
Returns a new instance of GPUContext.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 8 def initialize(window: nil, width:, height:, device: nil, queue: nil, surface: nil) WGPUCompatibility.install! @window = window @width = Integer(width) @height = Integer(height) @owns_device = device.nil? @disposed = false if device @device = device @queue = queue || device.queue @surface = surface @adapter = device.respond_to?(:adapter) ? device.adapter : nil else initialize_wgpu end @surface_format = choose_surface_format configure_surface if @surface rescue StandardError dispose_after_failed_initialization raise end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
6 7 8 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 6 def adapter @adapter end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
6 7 8 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 6 def device @device end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 6 def height @height end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
6 7 8 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 6 def instance @instance end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
6 7 8 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 6 def queue @queue end |
#surface ⇒ Object (readonly)
Returns the value of attribute surface.
6 7 8 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 6 def surface @surface end |
#surface_format ⇒ Object (readonly)
Returns the value of attribute surface_format.
6 7 8 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 6 def surface_format @surface_format end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 6 def width @width end |
Instance Method Details
#current_target ⇒ Object
41 42 43 44 45 46 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 41 def current_target raise Error, "renderer has no surface" unless surface texture = surface.current_texture [texture, texture.create_view] end |
#dispose ⇒ Object
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 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 52 def dispose return self if @disposed @disposed = true cleanups = [ -> { surface&.unconfigure }, -> { surface&.release } ] if @owns_device cleanups.concat( [ -> { device.destroy if device.respond_to?(:destroy) }, -> { device.release if device.respond_to?(:release) }, -> { adapter.release if adapter&.respond_to?(:release) }, -> { instance.release if instance&.respond_to?(:release) } ] ) end first_error = nil cleanups.each do |cleanup| cleanup.call rescue StandardError => error first_error ||= error end raise first_error if first_error self end |
#present ⇒ Object
48 49 50 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 48 def present surface&.present end |
#resize(width, height) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/stagecraft/renderer/gpu_context.rb', line 30 def resize(width, height) next_width = [Integer(width), 1].max next_height = [Integer(height), 1].max return false if next_width == @width && next_height == @height @width = next_width @height = next_height configure_surface if surface true end |