Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement surfaceSelector in Context3D.setRenderToTexture #15495

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the same validation as FP has?

ArgumentError - for a mismatched surfaceSelector parameter. The value must be 0 for 2D textures and 0..5 for cube maps

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