Class: Stagecraft::Renderer::FrameResources
- Inherits:
-
Object
- Object
- Stagecraft::Renderer::FrameResources
- Defined in:
- lib/stagecraft/renderer/frame_resources.rb
Defined Under Namespace
Classes: SkinBinding
Constant Summary collapse
- OBJECT_SLOT_SIZE =
256- OBJECT_DATA_SIZE =
144- FRAMES_IN_FLIGHT =
3- LIGHT_SIZE =
80- GUARANTEED_SAMPLE_COUNTS =
[1, 4].freeze
Instance Attribute Summary collapse
-
#depth_texture ⇒ Object
readonly
Returns the value of attribute depth_texture.
-
#depth_view ⇒ Object
readonly
Returns the value of attribute depth_view.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#empty_group ⇒ Object
readonly
Returns the value of attribute empty_group.
-
#empty_layout ⇒ Object
readonly
Returns the value of attribute empty_layout.
-
#fallback_black ⇒ Object
readonly
Returns the value of attribute fallback_black.
-
#fallback_normal ⇒ Object
readonly
Returns the value of attribute fallback_normal.
-
#fallback_white ⇒ Object
readonly
Returns the value of attribute fallback_white.
-
#frame_group ⇒ Object
readonly
Returns the value of attribute frame_group.
-
#frame_layout ⇒ Object
readonly
Returns the value of attribute frame_layout.
-
#hdr_texture ⇒ Object
readonly
Returns the value of attribute hdr_texture.
-
#hdr_view ⇒ Object
readonly
Returns the value of attribute hdr_view.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#object_group ⇒ Object
readonly
Returns the value of attribute object_group.
-
#object_layout ⇒ Object
readonly
Returns the value of attribute object_layout.
-
#output_texture ⇒ Object
readonly
Returns the value of attribute output_texture.
-
#output_view ⇒ Object
readonly
Returns the value of attribute output_view.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#sample_count ⇒ Object
readonly
Returns the value of attribute sample_count.
-
#shadow_frame_group ⇒ Object
readonly
Returns the value of attribute shadow_frame_group.
-
#shadow_frame_layout ⇒ Object
readonly
Returns the value of attribute shadow_frame_layout.
-
#shadow_texture ⇒ Object
readonly
Returns the value of attribute shadow_texture.
-
#shadow_view ⇒ Object
readonly
Returns the value of attribute shadow_view.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #begin_frame(items, camera:, ambient:, lights:, light_vp:, time:) ⇒ Object
- #dispose ⇒ Object
- #frame_target ⇒ Object
-
#initialize(context:, stats:, sample_count:) ⇒ FrameResources
constructor
A new instance of FrameResources.
- #main_color_attachment ⇒ Object
- #object_group_for(mesh) ⇒ Object
- #object_offset(index) ⇒ Object
- #resize(width, height) ⇒ Object
- #resize_shadow(map_size) ⇒ Object
Constructor Details
#initialize(context:, stats:, sample_count:) ⇒ FrameResources
Returns a new instance of FrameResources.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 25 def initialize(context:, stats:, sample_count:) @context = context @device = context.device @queue = context.queue @stats = stats @sample_count = self.class.guaranteed_sample_count(sample_count) @frame_number = 0 @object_capacity = 1 @light_capacity = 1 @skin_bindings = {} create_layouts create_buffers create_shadow_resources create_fallback_textures resize(context.width, context.height) rescue StandardError dispose_after_failed_initialization raise end |
Instance Attribute Details
#depth_texture ⇒ Object (readonly)
Returns the value of attribute depth_texture.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def depth_texture @depth_texture end |
#depth_view ⇒ Object (readonly)
Returns the value of attribute depth_view.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def depth_view @depth_view end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def device @device end |
#empty_group ⇒ Object (readonly)
Returns the value of attribute empty_group.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def empty_group @empty_group end |
#empty_layout ⇒ Object (readonly)
Returns the value of attribute empty_layout.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def empty_layout @empty_layout end |
#fallback_black ⇒ Object (readonly)
Returns the value of attribute fallback_black.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def fallback_black @fallback_black end |
#fallback_normal ⇒ Object (readonly)
Returns the value of attribute fallback_normal.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def fallback_normal @fallback_normal end |
#fallback_white ⇒ Object (readonly)
Returns the value of attribute fallback_white.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def fallback_white @fallback_white end |
#frame_group ⇒ Object (readonly)
Returns the value of attribute frame_group.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def frame_group @frame_group end |
#frame_layout ⇒ Object (readonly)
Returns the value of attribute frame_layout.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def frame_layout @frame_layout end |
#hdr_texture ⇒ Object (readonly)
Returns the value of attribute hdr_texture.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def hdr_texture @hdr_texture end |
#hdr_view ⇒ Object (readonly)
Returns the value of attribute hdr_view.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def hdr_view @hdr_view end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def height @height end |
#object_group ⇒ Object (readonly)
Returns the value of attribute object_group.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def object_group @object_group end |
#object_layout ⇒ Object (readonly)
Returns the value of attribute object_layout.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def object_layout @object_layout end |
#output_texture ⇒ Object (readonly)
Returns the value of attribute output_texture.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def output_texture @output_texture end |
#output_view ⇒ Object (readonly)
Returns the value of attribute output_view.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def output_view @output_view end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def queue @queue end |
#sample_count ⇒ Object (readonly)
Returns the value of attribute sample_count.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def sample_count @sample_count end |
#shadow_frame_group ⇒ Object (readonly)
Returns the value of attribute shadow_frame_group.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def shadow_frame_group @shadow_frame_group end |
#shadow_frame_layout ⇒ Object (readonly)
Returns the value of attribute shadow_frame_layout.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def shadow_frame_layout @shadow_frame_layout end |
#shadow_texture ⇒ Object (readonly)
Returns the value of attribute shadow_texture.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def shadow_texture @shadow_texture end |
#shadow_view ⇒ Object (readonly)
Returns the value of attribute shadow_view.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def shadow_view @shadow_view end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def stats @stats end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
13 14 15 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 13 def width @width end |
Class Method Details
.guaranteed_sample_count(requested) ⇒ Object
19 20 21 22 23 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 19 def self.guaranteed_sample_count(requested) value = Integer(requested) GUARANTEED_SAMPLE_COUNTS.reverse.find { |count| count <= value } || GUARANTEED_SAMPLE_COUNTS.first end |
Instance Method Details
#begin_frame(items, camera:, ambient:, lights:, light_vp:, time:) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 54 def begin_frame(items, camera:, ambient:, lights:, light_vp:, time:) ensure_object_capacity(items.length) ensure_light_capacity(lights.length) write_frame(camera:, ambient:, lights:, light_vp:, time:) write_objects(items) write_skins(items) @frame_number += 1 self end |
#dispose ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 103 def dispose release_resource(@shadow_sampler, @shadow_view) destroy_texture(@shadow_texture) [fallback_white, fallback_black, fallback_normal].compact.each do |resource| release_gpu_texture(resource) end release_resource(@frame_group, @shadow_frame_group, @object_group, @empty_group) @skin_bindings.each_value do |binding| release_resource(binding.bind_group) destroy_buffer(binding.buffer) end @skin_bindings.clear [@frame_buffer, @lights_buffer, @object_buffer, @joint_buffer].compact.each do |buffer| destroy_buffer(buffer) end release_resource(frame_layout, object_layout, empty_layout, shadow_frame_layout) end |
#frame_target ⇒ Object
97 98 99 100 101 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 97 def frame_target return [output_texture, output_view] unless @context.surface @context.current_target end |
#main_color_attachment ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 84 def if sample_count > 1 { view: @hdr_msaa_view, resolve_target: hdr_view, load_op: :clear, store_op: :discard } else { view: hdr_view, load_op: :clear, store_op: :store } end end |
#object_group_for(mesh) ⇒ Object
69 70 71 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 69 def object_group_for(mesh) mesh.skin ? @skin_bindings.fetch(mesh.object_id).bind_group : object_group end |
#object_offset(index) ⇒ Object
64 65 66 67 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 64 def object_offset(index) frame_slot = (@frame_number - 1) % FRAMES_IN_FLIGHT (frame_slot * @object_capacity * OBJECT_SLOT_SIZE) + (index * OBJECT_SLOT_SIZE) end |
#resize(width, height) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 45 def resize(width, height) @width = Integer(width) @height = Integer(height) unless @context.surface self end |
#resize_shadow(map_size) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/stagecraft/renderer/frame_resources.rb', line 73 def resize_shadow(map_size) next_size = Integer(map_size) return self if next_size == @shadow_size release_resource(@shadow_view) destroy_texture(@shadow_texture) create_shadow_texture(next_size) recreate_frame_groups self end |