diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2018-05-25 14:58:50 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2018-06-06 12:24:47 +0200 |
commit | f1288cc6e0a52d377619f0ec9634eefd29ba15dc (patch) | |
tree | de9787bb29bf8adb2b759774bab0064c27cf44b2 /components/script/dom/webgltexture.rs | |
parent | eb1dfd07756f690dfbebae2e53447bc747c5763a (diff) | |
download | servo-f1288cc6e0a52d377619f0ec9634eefd29ba15dc.tar.gz servo-f1288cc6e0a52d377619f0ec9634eefd29ba15dc.zip |
Implement EXT_texture_filter_anisotropic
Diffstat (limited to 'components/script/dom/webgltexture.rs')
-rw-r--r-- | components/script/dom/webgltexture.rs | 121 |
1 files changed, 66 insertions, 55 deletions
diff --git a/components/script/dom/webgltexture.rs b/components/script/dom/webgltexture.rs index 45b26997bc3..9fe77197825 100644 --- a/components/script/dom/webgltexture.rs +++ b/components/script/dom/webgltexture.rs @@ -4,8 +4,9 @@ // https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl -use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId}; -use canvas_traits::webgl::DOMToTextureCommand; +use canvas_traits::webgl::{DOMToTextureCommand, TexParameter, TexParameterFloat}; +use canvas_traits::webgl::{TexParameterInt, WebGLCommand, WebGLError, WebGLMsgSender}; +use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel}; use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLTextureBinding; @@ -202,65 +203,75 @@ impl WebGLTexture { /// We have to follow the conversion rules for GLES 2.0. See: /// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html /// - pub fn tex_parameter(&self, - target: u32, - name: u32, - value: TexParameterValue) -> WebGLResult<()> { - let (int_value, _float_value) = match value { + pub fn tex_parameter( + &self, + param: TexParameter, + value: TexParameterValue, + ) -> WebGLResult<()> { + let target = self.target().unwrap(); + + let (int_value, float_value) = match value { TexParameterValue::Int(int_value) => (int_value, int_value as f32), TexParameterValue::Float(float_value) => (float_value as i32, float_value), }; - match name { - constants::TEXTURE_MIN_FILTER => { - match int_value as u32 { - constants::NEAREST | - constants::LINEAR | - constants::NEAREST_MIPMAP_NEAREST | - constants::LINEAR_MIPMAP_NEAREST | - constants::NEAREST_MIPMAP_LINEAR | - constants::LINEAR_MIPMAP_LINEAR => { - self.min_filter.set(Some(int_value as u32)); - self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) - .unwrap(); - Ok(()) - }, - - _ => Err(WebGLError::InvalidEnum), + match param { + TexParameter::Int(int_param) => { + match int_param { + TexParameterInt::TextureMinFilter => { + match int_value as u32 { + constants::NEAREST | + constants::LINEAR | + constants::NEAREST_MIPMAP_NEAREST | + constants::LINEAR_MIPMAP_NEAREST | + constants::NEAREST_MIPMAP_LINEAR | + constants::LINEAR_MIPMAP_LINEAR => { + self.min_filter.set(Some(int_value as u32)); + self.renderer + .send(WebGLCommand::TexParameteri(target, int_param, int_value)) + .unwrap(); + Ok(()) + } + _ => Err(WebGLError::InvalidEnum), + } + } + TexParameterInt::TextureMagFilter => { + match int_value as u32 { + constants::NEAREST | constants::LINEAR => { + self.mag_filter.set(Some(int_value as u32)); + self.renderer + .send(WebGLCommand::TexParameteri(target, int_param, int_value)) + .unwrap(); + Ok(()) + } + _ => return Err(WebGLError::InvalidEnum), + } + } + TexParameterInt::TextureWrapS | TexParameterInt::TextureWrapT => { + match int_value as u32 { + constants::CLAMP_TO_EDGE | + constants::MIRRORED_REPEAT | + constants::REPEAT => { + self.renderer + .send(WebGLCommand::TexParameteri(target, int_param, int_value)) + .unwrap(); + Ok(()) + } + _ => Err(WebGLError::InvalidEnum), + } + } } - }, - constants::TEXTURE_MAG_FILTER => { - match int_value as u32 { - constants::NEAREST | - constants::LINEAR => { - self.mag_filter.set(Some(int_value as u32)); - self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) - .unwrap(); - Ok(()) - }, - - _ => Err(WebGLError::InvalidEnum), - } - }, - constants::TEXTURE_WRAP_S | - constants::TEXTURE_WRAP_T => { - match int_value as u32 { - constants::CLAMP_TO_EDGE | - constants::MIRRORED_REPEAT | - constants::REPEAT => { - self.renderer - .send(WebGLCommand::TexParameteri(target, name, int_value)) - .unwrap(); - Ok(()) - }, - - _ => Err(WebGLError::InvalidEnum), + } + TexParameter::Float(float_param @ TexParameterFloat::TextureMaxAnisotropyExt) => { + if float_value >= 1. { + self.renderer + .send(WebGLCommand::TexParameterf(target, float_param, float_value)) + .unwrap(); + Ok(()) + } else { + Err(WebGLError::InvalidValue) } - }, - - _ => Err(WebGLError::InvalidEnum), + } } } |