Properly set initial values for WebGL texture filters

This commit is contained in:
Anthony Ramine 2018-08-02 15:53:19 +02:00
parent a5fba3c8d6
commit 9e912be4ea

View file

@ -44,8 +44,8 @@ pub struct WebGLTexture {
face_count: Cell<u8>, face_count: Cell<u8>,
base_mipmap_level: u32, base_mipmap_level: u32,
// Store information for min and mag filters // Store information for min and mag filters
min_filter: Cell<Option<u32>>, min_filter: Cell<u32>,
mag_filter: Cell<Option<u32>>, mag_filter: Cell<u32>,
/// True if this texture is used for the DOMToTexture feature. /// True if this texture is used for the DOMToTexture feature.
attached_to_dom: Cell<bool>, attached_to_dom: Cell<bool>,
} }
@ -59,8 +59,8 @@ impl WebGLTexture {
is_deleted: Cell::new(false), is_deleted: Cell::new(false),
face_count: Cell::new(0), face_count: Cell::new(0),
base_mipmap_level: 0, base_mipmap_level: 0,
min_filter: Cell::new(None), min_filter: Cell::new(constants::NEAREST_MIPMAP_LINEAR),
mag_filter: Cell::new(None), mag_filter: Cell::new(constants::LINEAR),
image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]), image_info_array: DomRefCell::new([ImageInfo::new(); MAX_LEVEL_COUNT * MAX_FACE_COUNT]),
attached_to_dom: Cell::new(false), attached_to_dom: Cell::new(false),
} }
@ -215,6 +215,16 @@ impl WebGLTexture {
match param { match param {
TexParameter::Int(int_param) => { TexParameter::Int(int_param) => {
let update_filter = |filter: &Cell<u32>| {
if filter.get() == int_value as u32 {
return Ok(());
}
filter.set(int_value as u32);
self.upcast::<WebGLObject>()
.context()
.send_command(WebGLCommand::TexParameteri(target, int_param, int_value));
Ok(())
};
match int_param { match int_param {
TexParameterInt::TextureMinFilter => { TexParameterInt::TextureMinFilter => {
match int_value as u32 { match int_value as u32 {
@ -223,25 +233,13 @@ impl WebGLTexture {
constants::NEAREST_MIPMAP_NEAREST | constants::NEAREST_MIPMAP_NEAREST |
constants::LINEAR_MIPMAP_NEAREST | constants::LINEAR_MIPMAP_NEAREST |
constants::NEAREST_MIPMAP_LINEAR | constants::NEAREST_MIPMAP_LINEAR |
constants::LINEAR_MIPMAP_LINEAR => { constants::LINEAR_MIPMAP_LINEAR => update_filter(&self.min_filter),
self.min_filter.set(Some(int_value as u32));
self.upcast::<WebGLObject>()
.context()
.send_command(WebGLCommand::TexParameteri(target, int_param, int_value));
Ok(())
}
_ => Err(WebGLError::InvalidEnum), _ => Err(WebGLError::InvalidEnum),
} }
} }
TexParameterInt::TextureMagFilter => { TexParameterInt::TextureMagFilter => {
match int_value as u32 { match int_value as u32 {
constants::NEAREST | constants::LINEAR => { constants::NEAREST | constants::LINEAR => update_filter(&self.mag_filter),
self.mag_filter.set(Some(int_value as u32));
self.upcast::<WebGLObject>()
.context()
.send_command(WebGLCommand::TexParameteri(target, int_param, int_value));
Ok(())
}
_ => return Err(WebGLError::InvalidEnum), _ => return Err(WebGLError::InvalidEnum),
} }
} }
@ -277,10 +275,10 @@ impl WebGLTexture {
let filters = [self.min_filter.get(), self.mag_filter.get()]; let filters = [self.min_filter.get(), self.mag_filter.get()];
filters.iter().any(|filter| { filters.iter().any(|filter| {
match *filter { match *filter {
Some(constants::LINEAR) | constants::LINEAR |
Some(constants::NEAREST_MIPMAP_LINEAR) | constants::NEAREST_MIPMAP_LINEAR |
Some(constants::LINEAR_MIPMAP_NEAREST) | constants::LINEAR_MIPMAP_NEAREST |
Some(constants::LINEAR_MIPMAP_LINEAR) => true, constants::LINEAR_MIPMAP_LINEAR => true,
_=> false _=> false
} }
}) })