Class: Stagecraft::Renderer::Frame
- Inherits:
-
Object
- Object
- Stagecraft::Renderer::Frame
- Defined in:
- lib/stagecraft/renderer/frame.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#texture ⇒ Object
readonly
Returns the value of attribute texture.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(texture:, width:, height:, device:, queue:, readable:) ⇒ Frame
constructor
A new instance of Frame.
- #read_pixels ⇒ Object
Constructor Details
#initialize(texture:, width:, height:, device:, queue:, readable:) ⇒ Frame
Returns a new instance of Frame.
8 9 10 11 12 13 14 15 |
# File 'lib/stagecraft/renderer/frame.rb', line 8 def initialize(texture:, width:, height:, device:, queue:, readable:) @texture = texture @width = width @height = height @device = device @queue = queue @readable = readable end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
6 7 8 |
# File 'lib/stagecraft/renderer/frame.rb', line 6 def height @height end |
#texture ⇒ Object (readonly)
Returns the value of attribute texture.
6 7 8 |
# File 'lib/stagecraft/renderer/frame.rb', line 6 def texture @texture end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/stagecraft/renderer/frame.rb', line 6 def width @width end |
Instance Method Details
#read_pixels ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/stagecraft/renderer/frame.rb', line 17 def read_pixels raise Error, "surface frames cannot be read after presentation; use Renderer.offscreen" unless @readable require "texel" bytes_per_row = align(width * 4, 256) padded = @queue.read_texture( source: { texture: }, data_layout: { bytes_per_row:, rows_per_image: height }, size: { width:, height:, depth_or_array_layers: 1 }, device: @device ) pixels = if bytes_per_row == width * 4 padded else height.times.map { |row| padded.byteslice(row * bytes_per_row, width * 4) }.join end Texel::Image.new( width:, height:, channels: 4, dtype: :u8, color_space: :srgb, data: pixels ) end |