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

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/src/avm2/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ pub struct SystemClassDefs<'gc> {
pub graphicssolidfill: Class<'gc>,
pub graphicsshaderfill: Class<'gc>,
pub graphicsstroke: Class<'gc>,

pub cubetexture: Class<'gc>,
pub rectangletexture: Class<'gc>,
}

impl<'gc> SystemClasses<'gc> {
Expand Down Expand Up @@ -357,6 +360,9 @@ impl<'gc> SystemClassDefs<'gc> {
graphicssolidfill: object,
graphicsshaderfill: object,
graphicsstroke: object,

cubetexture: object,
rectangletexture: object,
}
}
}
Expand Down Expand Up @@ -959,6 +965,12 @@ pub fn init_native_system_classes(activation: &mut Activation<'_, '_>) {
),
("flash.display", "GraphicsSolidFill", graphicssolidfill),
("flash.display", "GraphicsStroke", graphicsstroke),
("flash.display3D.textures", "CubeTexture", cubetexture),
(
"flash.display3D.textures",
"RectangleTexture",
rectangletexture
),
]
);
}
Expand Down
37 changes: 28 additions & 9 deletions core/src/avm2/globals/flash/display3D/context_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,21 +599,40 @@ pub fn set_render_to_texture<'gc>(
let surface_selector = args.get_u32(activation, 3)?;
let color_output_index = args.get_u32(activation, 4)?;

if anti_alias != 0 {
avm2_stub_method!(
activation,
"flash.display3D.Context3D",
"setRenderToTexture",
"antiAlias != 0"
);
let mut error = None;
if texture.instance_class() == activation.avm2().class_defs().cubetexture {
if surface_selector > 5 {
error = Some((
3772,
"Error #3772: Cube textures need to have surfaceSelector [0..5].",
));
}
} else if texture.instance_class() == activation.avm2().class_defs().rectangletexture {
if surface_selector != 0 {
error = Some((
3773,
"Error #3773: Rectangle textures need to have surfaceSelector = 0.",
));
}
} else {
// normal Texture or video texture (but the latter should probably not be supported here anyway)
if surface_selector != 0 {
error = Some((
3771,
"Error #3771: 2D textures need to have surfaceSelector = 0.",
));
}
}
if let Some((code, message)) = error {
return Err(Error::AvmError(argument_error(activation, message, code)?));
}

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

Copy link
Member

Choose a reason for hiding this comment

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

I hesitated to merge myself because I wasn't sure how strongly you wanted this to be addressed.

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

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