render: Implement Bitmap smoothing property
This commit is contained in:
parent
4d4cf3c025
commit
369c5bda56
|
@ -239,6 +239,17 @@ fn attach_bitmap<'gc>(
|
|||
.write(activation.context.gc_context)
|
||||
.bitmap_handle(activation.context.renderer);
|
||||
|
||||
// TODO: Implement pixel snapping
|
||||
let _pixel_snapping = args
|
||||
.get(2)
|
||||
.unwrap_or(&Value::Undefined)
|
||||
.as_bool(activation.current_swf_version());
|
||||
|
||||
let smoothing = args
|
||||
.get(3)
|
||||
.unwrap_or(&Value::Undefined)
|
||||
.as_bool(activation.current_swf_version());
|
||||
|
||||
if let Some(bitmap_handle) = bitmap_handle {
|
||||
//TODO: do attached BitmapDatas have character ids?
|
||||
let display_object = Bitmap::new_with_bitmap_data(
|
||||
|
@ -248,6 +259,7 @@ fn attach_bitmap<'gc>(
|
|||
bitmap_data.read().width() as u16,
|
||||
bitmap_data.read().height() as u16,
|
||||
Some(bitmap_data),
|
||||
smoothing,
|
||||
);
|
||||
movie_clip.replace_at_depth(
|
||||
&mut activation.context,
|
||||
|
|
|
@ -34,7 +34,7 @@ pub trait RenderBackend: Downcast {
|
|||
) -> Result<BitmapInfo, Error>;
|
||||
|
||||
fn begin_frame(&mut self, clear: Color);
|
||||
fn render_bitmap(&mut self, bitmap: BitmapHandle, transform: &Transform);
|
||||
fn render_bitmap(&mut self, bitmap: BitmapHandle, transform: &Transform, smoothing: bool);
|
||||
fn render_shape(&mut self, shape: ShapeHandle, transform: &Transform);
|
||||
fn draw_rect(&mut self, color: Color, matrix: &Matrix);
|
||||
fn end_frame(&mut self);
|
||||
|
@ -155,7 +155,7 @@ impl RenderBackend for NullRenderer {
|
|||
}
|
||||
fn begin_frame(&mut self, _clear: Color) {}
|
||||
fn end_frame(&mut self) {}
|
||||
fn render_bitmap(&mut self, _bitmap: BitmapHandle, _transform: &Transform) {}
|
||||
fn render_bitmap(&mut self, _bitmap: BitmapHandle, _transform: &Transform, _smoothing: bool) {}
|
||||
fn render_shape(&mut self, _shape: ShapeHandle, _transform: &Transform) {}
|
||||
fn draw_rect(&mut self, _color: Color, _matrix: &Matrix) {}
|
||||
fn draw_letterbox(&mut self, _letterbox: Letterbox) {}
|
||||
|
|
|
@ -23,6 +23,7 @@ pub struct BitmapData<'gc> {
|
|||
base: DisplayObjectBase<'gc>,
|
||||
static_data: Gc<'gc, BitmapStatic>,
|
||||
bitmap_data: Option<GcCell<'gc, crate::avm1::object::bitmap_data::BitmapData>>,
|
||||
smoothing: bool,
|
||||
}
|
||||
|
||||
impl<'gc> Bitmap<'gc> {
|
||||
|
@ -33,6 +34,7 @@ impl<'gc> Bitmap<'gc> {
|
|||
width: u16,
|
||||
height: u16,
|
||||
bitmap_data: Option<GcCell<'gc, crate::avm1::object::bitmap_data::BitmapData>>,
|
||||
smoothing: bool,
|
||||
) -> Self {
|
||||
Bitmap(GcCell::allocate(
|
||||
context.gc_context,
|
||||
|
@ -48,6 +50,7 @@ impl<'gc> Bitmap<'gc> {
|
|||
},
|
||||
),
|
||||
bitmap_data,
|
||||
smoothing,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -59,7 +62,7 @@ impl<'gc> Bitmap<'gc> {
|
|||
width: u16,
|
||||
height: u16,
|
||||
) -> Self {
|
||||
Self::new_with_bitmap_data(context, id, bitmap_handle, width, height, None)
|
||||
Self::new_with_bitmap_data(context, id, bitmap_handle, width, height, None, true)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -117,9 +120,11 @@ impl<'gc> TDisplayObject<'gc> for Bitmap<'gc> {
|
|||
|
||||
context.transform_stack.push(&*self.transform());
|
||||
|
||||
let bitmap_data = self.0.read();
|
||||
context.renderer.render_bitmap(
|
||||
self.0.read().static_data.bitmap_handle,
|
||||
bitmap_data.static_data.bitmap_handle,
|
||||
context.transform_stack.transform(),
|
||||
bitmap_data.smoothing,
|
||||
);
|
||||
|
||||
context.transform_stack.pop();
|
||||
|
|
|
@ -564,7 +564,7 @@ impl RenderBackend for WebCanvasRenderBackend {
|
|||
// Noop
|
||||
}
|
||||
|
||||
fn render_bitmap(&mut self, bitmap: BitmapHandle, transform: &Transform) {
|
||||
fn render_bitmap(&mut self, bitmap: BitmapHandle, transform: &Transform, _smoothing: bool) {
|
||||
if self.deactivating_mask {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -932,7 +932,7 @@ impl RenderBackend for WebGlRenderBackend {
|
|||
}
|
||||
}
|
||||
|
||||
fn render_bitmap(&mut self, bitmap: BitmapHandle, transform: &Transform) {
|
||||
fn render_bitmap(&mut self, bitmap: BitmapHandle, transform: &Transform, smoothing: bool) {
|
||||
self.set_stencil_state();
|
||||
if let Some((_, bitmap)) = self.textures.get(bitmap.0) {
|
||||
let texture = &bitmap.texture;
|
||||
|
@ -1023,7 +1023,11 @@ impl RenderBackend for WebGlRenderBackend {
|
|||
program.uniform1i(&self.gl, ShaderUniform::BitmapTexture, 0);
|
||||
|
||||
// Set texture parameters.
|
||||
let filter = Gl::LINEAR as i32;
|
||||
let filter = if smoothing {
|
||||
Gl::LINEAR as i32
|
||||
} else {
|
||||
Gl::NEAREST as i32
|
||||
};
|
||||
self.gl
|
||||
.tex_parameteri(Gl::TEXTURE_2D, Gl::TEXTURE_MAG_FILTER, filter);
|
||||
self.gl
|
||||
|
|
|
@ -928,7 +928,7 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn render_bitmap(&mut self, bitmap: BitmapHandle, transform: &Transform) {
|
||||
fn render_bitmap(&mut self, bitmap: BitmapHandle, transform: &Transform, smoothing: bool) {
|
||||
if let Some((_id, texture)) = self.textures.get(bitmap.0) {
|
||||
let (frame_output, encoder) =
|
||||
if let Some((frame_output, encoder)) = &mut self.current_frame {
|
||||
|
@ -1070,7 +1070,9 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
|
|||
render_pass.set_bind_group(2, &bitmap_bind_group, &[]);
|
||||
render_pass.set_bind_group(
|
||||
3,
|
||||
self.descriptors.bitmap_samplers.get_bind_group(false, true),
|
||||
self.descriptors
|
||||
.bitmap_samplers
|
||||
.get_bind_group(false, smoothing),
|
||||
&[],
|
||||
);
|
||||
render_pass.set_vertex_buffer(0, self.quad_vbo.slice(..));
|
||||
|
|
Loading…
Reference in New Issue