Skip to content

Commit

Permalink
Implement surfaceSelector in Context3D.setRenderToTexture
Browse files Browse the repository at this point in the history
This still needs a test, but I'm planning to add that in a
follow-up PR
  • Loading branch information
Aaron1011 authored and torokati44 committed Jun 18, 2024
1 parent e4a37ef commit 56de39e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
9 changes: 0 additions & 9 deletions core/src/avm2/globals/flash/display3D/context_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,6 @@ pub fn set_render_to_texture<'gc>(
);
}

if surface_selector != 0 {
avm2_stub_method!(
activation,
"flash.display3D.Context3D",
"setRenderToTexture",
"surfaceSelector != 0"
);
}

if color_output_index != 0 {
avm2_stub_method!(
activation,
Expand Down
33 changes: 20 additions & 13 deletions render/wgpu/src/context3d/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use swf::{Rectangle, Twips};
use wgpu::util::StagingBelt;
use wgpu::{
BindGroup, BufferDescriptor, BufferUsages, TextureDescriptor, TextureDimension, TextureFormat,
TextureUsages, TextureView, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
TextureUsages, TextureView, TextureViewDescriptor, COPY_BUFFER_ALIGNMENT,
COPY_BYTES_PER_ROW_ALIGNMENT,
};
use wgpu::{CommandEncoder, Extent3d, RenderPass};

Expand Down Expand Up @@ -776,7 +777,7 @@ impl Context3D for WgpuContext3D {
texture,
enable_depth_and_stencil,
anti_alias,
surface_selector: _,
surface_selector,
} => {
let mut sample_count = anti_alias;
if sample_count == 0 {
Expand All @@ -799,9 +800,16 @@ impl Context3D for WgpuContext3D {
self.current_texture_size = Some(Extent3d {
width: texture_wrapper.texture.width(),
height: texture_wrapper.texture.height(),
depth_or_array_layers: 1,
depth_or_array_layers: texture_wrapper.texture.depth_or_array_layers(),
});

let view_desc = TextureViewDescriptor {
base_array_layer: surface_selector,
array_layer_count: Some(1),
dimension: Some(wgpu::TextureViewDimension::D2),
..Default::default()
};

if sample_count != 1 {
let texture_label = create_debug_label!("Render target texture MSAA");

Expand All @@ -813,28 +821,27 @@ impl Context3D for WgpuContext3D {
size: Extent3d {
width: texture_wrapper.texture.width(),
height: texture_wrapper.texture.height(),
depth_or_array_layers: 1,
depth_or_array_layers: texture_wrapper
.texture
.depth_or_array_layers(),
},
mip_level_count: 1,
sample_count,
dimension: wgpu::TextureDimension::D2,
dimension: texture_wrapper.texture.dimension(),
format: texture_wrapper.texture.format(),
view_formats: &[texture_wrapper.texture.format()],
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
});

self.current_texture_resolve_view = Some(Rc::new(
texture_wrapper.texture.create_view(&Default::default()),
));
self.current_texture_view =
Some(Rc::new(msaa_texture.create_view(&Default::default())));
self.current_texture_resolve_view =
Some(Rc::new(texture_wrapper.texture.create_view(&view_desc)));
self.current_texture_view = Some(Rc::new(msaa_texture.create_view(&view_desc)));
} else {
self.current_texture_resolve_view = None;
self.current_texture_view = Some(Rc::new(
texture_wrapper.texture.create_view(&Default::default()),
));
self.current_texture_view =
Some(Rc::new(texture_wrapper.texture.create_view(&view_desc)));
}

if enable_depth_and_stencil {
Expand Down

0 comments on commit 56de39e

Please sign in to comment.