mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Use the DOM cache for gl.getTexParameter(gl.TEXTURE_*_FILTER)
Part of #20596.
This commit is contained in:
parent
9e912be4ea
commit
f7124886bc
3 changed files with 78 additions and 66 deletions
|
@ -276,8 +276,8 @@ pub enum WebGLCommand {
|
||||||
GetCurrentVertexAttrib(u32, WebGLSender<[f32; 4]>),
|
GetCurrentVertexAttrib(u32, WebGLSender<[f32; 4]>),
|
||||||
GetTexParameterFloat(u32, TexParameterFloat, WebGLSender<f32>),
|
GetTexParameterFloat(u32, TexParameterFloat, WebGLSender<f32>),
|
||||||
GetTexParameterInt(u32, TexParameterInt, WebGLSender<i32>),
|
GetTexParameterInt(u32, TexParameterInt, WebGLSender<i32>),
|
||||||
TexParameteri(u32, TexParameterInt, i32),
|
TexParameteri(u32, u32, i32),
|
||||||
TexParameterf(u32, TexParameterFloat, f32),
|
TexParameterf(u32, u32, f32),
|
||||||
DrawArraysInstanced { mode: u32, first: i32, count: i32, primcount: i32 },
|
DrawArraysInstanced { mode: u32, first: i32, count: i32, primcount: i32 },
|
||||||
DrawElementsInstanced { mode: u32, count: i32, type_: u32, offset: u32, primcount: i32 },
|
DrawElementsInstanced { mode: u32, count: i32, type_: u32, offset: u32, primcount: i32 },
|
||||||
VertexAttribDivisor { index: u32, divisor: u32 },
|
VertexAttribDivisor { index: u32, divisor: u32 },
|
||||||
|
@ -587,8 +587,6 @@ parameters! {
|
||||||
TextureMaxAnisotropyExt = gl::TEXTURE_MAX_ANISOTROPY_EXT,
|
TextureMaxAnisotropyExt = gl::TEXTURE_MAX_ANISOTROPY_EXT,
|
||||||
}),
|
}),
|
||||||
Int(TexParameterInt {
|
Int(TexParameterInt {
|
||||||
TextureMagFilter = gl::TEXTURE_MAG_FILTER,
|
|
||||||
TextureMinFilter = gl::TEXTURE_MIN_FILTER,
|
|
||||||
TextureWrapS = gl::TEXTURE_WRAP_S,
|
TextureWrapS = gl::TEXTURE_WRAP_S,
|
||||||
TextureWrapT = gl::TEXTURE_WRAP_T,
|
TextureWrapT = gl::TEXTURE_WRAP_T,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -440,22 +440,22 @@ impl WebGLRenderingContext {
|
||||||
handle_potential_webgl_error!(self, f(location));
|
handle_potential_webgl_error!(self, f(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tex_parameter(&self, target: u32, name: u32, value: TexParameterValue) {
|
fn tex_parameter(&self, target: u32, param: u32, value: TexParameterValue) {
|
||||||
let texture = match target {
|
let texture = match target {
|
||||||
constants::TEXTURE_2D |
|
constants::TEXTURE_2D |
|
||||||
constants::TEXTURE_CUBE_MAP => self.bound_texture(target),
|
constants::TEXTURE_CUBE_MAP => self.bound_texture(target),
|
||||||
_ => return self.webgl_error(InvalidEnum),
|
_ => return self.webgl_error(InvalidEnum),
|
||||||
};
|
};
|
||||||
|
|
||||||
if !self.extension_manager.is_get_tex_parameter_name_enabled(name) {
|
|
||||||
return self.webgl_error(InvalidEnum);
|
|
||||||
}
|
|
||||||
|
|
||||||
let param = handle_potential_webgl_error!(self, TexParameter::from_u32(name), return);
|
|
||||||
let texture = match texture {
|
let texture = match texture {
|
||||||
Some(tex) => tex,
|
Some(tex) => tex,
|
||||||
None => return self.webgl_error(InvalidOperation),
|
None => return self.webgl_error(InvalidOperation),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if !self.extension_manager.is_get_tex_parameter_name_enabled(param) {
|
||||||
|
return self.webgl_error(InvalidEnum);
|
||||||
|
}
|
||||||
|
|
||||||
handle_potential_webgl_error!(self, texture.tex_parameter(param, value), return);
|
handle_potential_webgl_error!(self, texture.tex_parameter(param, value), return);
|
||||||
|
|
||||||
// Validate non filterable TEXTURE_2D data_types
|
// Validate non filterable TEXTURE_2D data_types
|
||||||
|
@ -1658,9 +1658,18 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
return NullValue();
|
return NullValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.bound_texture(target).is_none() {
|
let texture = match self.bound_texture(target) {
|
||||||
self.webgl_error(InvalidOperation);
|
Some(texture) => texture,
|
||||||
return NullValue();
|
None => {
|
||||||
|
self.webgl_error(InvalidOperation);
|
||||||
|
return NullValue();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match pname {
|
||||||
|
constants::TEXTURE_MAG_FILTER => return UInt32Value(texture.mag_filter()),
|
||||||
|
constants::TEXTURE_MIN_FILTER => return UInt32Value(texture.min_filter()),
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
match handle_potential_webgl_error!(self, TexParameter::from_u32(pname), return NullValue()) {
|
match handle_potential_webgl_error!(self, TexParameter::from_u32(pname), return NullValue()) {
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
|
||||||
|
|
||||||
use canvas_traits::webgl::{DOMToTextureCommand, TexParameter, TexParameterFloat};
|
use canvas_traits::webgl::{DOMToTextureCommand, WebGLCommand, WebGLError};
|
||||||
use canvas_traits::webgl::{TexParameterInt, WebGLCommand, WebGLError};
|
|
||||||
use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel};
|
use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel};
|
||||||
use dom::bindings::cell::DomRefCell;
|
use dom::bindings::cell::DomRefCell;
|
||||||
|
use dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||||
use dom::bindings::codegen::Bindings::WebGLTextureBinding;
|
use dom::bindings::codegen::Bindings::WebGLTextureBinding;
|
||||||
use dom::bindings::inheritance::Castable;
|
use dom::bindings::inheritance::Castable;
|
||||||
|
@ -203,7 +203,7 @@ impl WebGLTexture {
|
||||||
///
|
///
|
||||||
pub fn tex_parameter(
|
pub fn tex_parameter(
|
||||||
&self,
|
&self,
|
||||||
param: TexParameter,
|
param: u32,
|
||||||
value: TexParameterValue,
|
value: TexParameterValue,
|
||||||
) -> WebGLResult<()> {
|
) -> WebGLResult<()> {
|
||||||
let target = self.target().unwrap();
|
let target = self.target().unwrap();
|
||||||
|
@ -213,64 +213,69 @@ impl WebGLTexture {
|
||||||
TexParameterValue::Float(float_value) => (float_value as i32, float_value),
|
TexParameterValue::Float(float_value) => (float_value as i32, float_value),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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, param, int_value));
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
match param {
|
match param {
|
||||||
TexParameter::Int(int_param) => {
|
constants::TEXTURE_MIN_FILTER => {
|
||||||
let update_filter = |filter: &Cell<u32>| {
|
match int_value as u32 {
|
||||||
if filter.get() == int_value as u32 {
|
constants::NEAREST |
|
||||||
return Ok(());
|
constants::LINEAR |
|
||||||
}
|
constants::NEAREST_MIPMAP_NEAREST |
|
||||||
filter.set(int_value as u32);
|
constants::LINEAR_MIPMAP_NEAREST |
|
||||||
self.upcast::<WebGLObject>()
|
constants::NEAREST_MIPMAP_LINEAR |
|
||||||
.context()
|
constants::LINEAR_MIPMAP_LINEAR => update_filter(&self.min_filter),
|
||||||
.send_command(WebGLCommand::TexParameteri(target, int_param, int_value));
|
_ => Err(WebGLError::InvalidEnum),
|
||||||
Ok(())
|
|
||||||
};
|
|
||||||
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 => update_filter(&self.min_filter),
|
|
||||||
_ => Err(WebGLError::InvalidEnum),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TexParameterInt::TextureMagFilter => {
|
|
||||||
match int_value as u32 {
|
|
||||||
constants::NEAREST | constants::LINEAR => update_filter(&self.mag_filter),
|
|
||||||
_ => return Err(WebGLError::InvalidEnum),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TexParameterInt::TextureWrapS | TexParameterInt::TextureWrapT => {
|
|
||||||
match int_value as u32 {
|
|
||||||
constants::CLAMP_TO_EDGE |
|
|
||||||
constants::MIRRORED_REPEAT |
|
|
||||||
constants::REPEAT => {
|
|
||||||
self.upcast::<WebGLObject>()
|
|
||||||
.context()
|
|
||||||
.send_command(WebGLCommand::TexParameteri(target, int_param, int_value));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
_ => Err(WebGLError::InvalidEnum),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TexParameter::Float(float_param @ TexParameterFloat::TextureMaxAnisotropyExt) => {
|
constants::TEXTURE_MAG_FILTER => {
|
||||||
if float_value >= 1. {
|
match int_value as u32 {
|
||||||
self.upcast::<WebGLObject>()
|
constants::NEAREST | constants::LINEAR => update_filter(&self.mag_filter),
|
||||||
.context()
|
_ => return Err(WebGLError::InvalidEnum),
|
||||||
.send_command(WebGLCommand::TexParameterf(target, float_param, float_value));
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(WebGLError::InvalidValue)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
constants::TEXTURE_WRAP_S | constants::TEXTURE_WRAP_T => {
|
||||||
|
match int_value as u32 {
|
||||||
|
constants::CLAMP_TO_EDGE |
|
||||||
|
constants::MIRRORED_REPEAT |
|
||||||
|
constants::REPEAT => {
|
||||||
|
self.upcast::<WebGLObject>()
|
||||||
|
.context()
|
||||||
|
.send_command(WebGLCommand::TexParameteri(target, param, int_value));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(WebGLError::InvalidEnum),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT => {
|
||||||
|
// NaN is not less than 1., what a time to be alive.
|
||||||
|
if !(float_value >= 1.) {
|
||||||
|
return Err(WebGLError::InvalidValue);
|
||||||
|
}
|
||||||
|
self.upcast::<WebGLObject>()
|
||||||
|
.context()
|
||||||
|
.send_command(WebGLCommand::TexParameterf(target, param, float_value));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(WebGLError::InvalidEnum),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn min_filter(&self) -> u32 {
|
||||||
|
self.min_filter.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mag_filter(&self) -> u32 {
|
||||||
|
self.mag_filter.get()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_using_linear_filtering(&self) -> bool {
|
pub fn is_using_linear_filtering(&self) -> bool {
|
||||||
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| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue