aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2018-05-25 14:58:50 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2018-06-06 12:24:47 +0200
commitf1288cc6e0a52d377619f0ec9634eefd29ba15dc (patch)
treede9787bb29bf8adb2b759774bab0064c27cf44b2
parenteb1dfd07756f690dfbebae2e53447bc747c5763a (diff)
downloadservo-f1288cc6e0a52d377619f0ec9634eefd29ba15dc.tar.gz
servo-f1288cc6e0a52d377619f0ec9634eefd29ba15dc.zip
Implement EXT_texture_filter_anisotropic
-rw-r--r--Cargo.lock26
-rw-r--r--components/canvas/webgl_thread.rs19
-rw-r--r--components/canvas_traits/Cargo.toml2
-rw-r--r--components/canvas_traits/webgl.rs22
-rw-r--r--components/script/dom/webgl_extensions/ext/exttexturefilteranisotropic.rs54
-rw-r--r--components/script/dom/webgl_extensions/ext/mod.rs1
-rw-r--r--components/script/dom/webgl_extensions/extensions.rs43
-rw-r--r--components/script/dom/webglrenderingcontext.rs83
-rw-r--r--components/script/dom/webgltexture.rs121
-rw-r--r--components/script/dom/webidls/EXTTextureFilterAnisotropic.webidl13
10 files changed, 262 insertions, 122 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 16feb52cb6d..f4a083be3b5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -274,7 +274,7 @@ dependencies = [
"cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -291,7 +291,7 @@ version = "0.0.1"
dependencies = [
"cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1",
@@ -336,7 +336,7 @@ name = "cgl"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -425,7 +425,7 @@ dependencies = [
"embedder_traits 0.0.1",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1063,7 +1063,7 @@ dependencies = [
[[package]]
name = "gleam"
-version = "0.5.0"
+version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1289,7 +1289,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cgl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"leaky-cow 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1548,7 +1548,7 @@ dependencies = [
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gaol 0.0.1 (git+https://github.com/servo/gaol)",
"gfx 0.0.1",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"layout_thread 0.0.1",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2043,7 +2043,7 @@ dependencies = [
"core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2490,7 +2490,7 @@ dependencies = [
"encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"half 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"html5ever 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2712,7 +2712,7 @@ dependencies = [
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gdi32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libservo 0.0.1",
@@ -2774,7 +2774,7 @@ dependencies = [
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"expat-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glutin 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glx 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"io-surface 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3525,7 +3525,7 @@ dependencies = [
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3846,7 +3846,7 @@ dependencies = [
"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
"checksum gif 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8a80d6fe9e52f637df9afd4779449a7be17c39cc9c35b01589bb833f956ba596"
"checksum gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a795170cbd85b5a7baa58d6d7525cae6a03e486859860c220f7ebbbdd379d0a"
-"checksum gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e47b39459e47b76be4d2c82702932cdc66df09dcb8f813424167991adb8b3380"
+"checksum gleam 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "12b793fcf40a23dd372f184c228ab3eb96f88c50bb4fba8319c483aa025a4e45"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum glutin 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90de8e0391e57098acfbfe693b23065e9186255d370ebae12c933b7d77df8424"
"checksum glx 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "63a6e7c2846e12626455f45ebaff9d92161436dd0fa703d9d198012e528ca7b9"
diff --git a/components/canvas/webgl_thread.rs b/components/canvas/webgl_thread.rs
index b48b72f2bfc..7b0b120d037 100644
--- a/components/canvas/webgl_thread.rs
+++ b/components/canvas/webgl_thread.rs
@@ -761,9 +761,6 @@ impl WebGLImpl {
Self::get_framebuffer_attachment_parameter(ctx.gl(), target, attachment, pname, chan),
WebGLCommand::GetVertexAttribOffset(index, pname, ref chan) =>
Self::vertex_attrib_offset(ctx.gl(), index, pname, chan),
- WebGLCommand::GetTexParameter(target, pname, ref chan) => {
- chan.send(ctx.gl().get_tex_parameter_iv(target, pname)).unwrap();
- }
WebGLCommand::GetShaderPrecisionFormat(shader_type, precision_type, ref chan) =>
Self::shader_precision_format(ctx.gl(), shader_type, precision_type, chan),
WebGLCommand::GetExtensions(ref chan) =>
@@ -864,10 +861,6 @@ impl WebGLImpl {
WebGLCommand::TexImage2D(target, level, internal, width, height, format, data_type, ref data) =>
ctx.gl().tex_image_2d(target, level, internal, width, height,
/*border*/0, format, data_type, Some(data)),
- WebGLCommand::TexParameteri(target, name, value) =>
- ctx.gl().tex_parameter_i(target, name, value),
- WebGLCommand::TexParameterf(target, name, value) =>
- ctx.gl().tex_parameter_f(target, name, value),
WebGLCommand::TexSubImage2D(target, level, xoffset, yoffset, x, y, width, height, ref data) =>
ctx.gl().tex_sub_image_2d(target, level, xoffset, yoffset, x, y, width, height, data),
WebGLCommand::DrawingBufferWidth(ref sender) =>
@@ -1020,6 +1013,18 @@ impl WebGLImpl {
};
sender.send(result).unwrap();
}
+ WebGLCommand::GetTexParameterFloat(target, param, ref sender) => {
+ sender.send(ctx.gl().get_tex_parameter_fv(target, param as u32)).unwrap();
+ }
+ WebGLCommand::GetTexParameterInt(target, param, ref sender) => {
+ sender.send(ctx.gl().get_tex_parameter_iv(target, param as u32)).unwrap();
+ }
+ WebGLCommand::TexParameteri(target, param, value) => {
+ ctx.gl().tex_parameter_i(target, param as u32, value)
+ }
+ WebGLCommand::TexParameterf(target, param, value) => {
+ ctx.gl().tex_parameter_f(target, param as u32, value)
+ }
}
// TODO: update test expectations in order to enable debug assertions
diff --git a/components/canvas_traits/Cargo.toml b/components/canvas_traits/Cargo.toml
index 310c9e4eec7..e9012c92d96 100644
--- a/components/canvas_traits/Cargo.toml
+++ b/components/canvas_traits/Cargo.toml
@@ -13,7 +13,7 @@ path = "lib.rs"
cssparser = "0.23.0"
euclid = "0.17"
ipc-channel = "0.10"
-gleam = "0.5"
+gleam = "0.5.1"
lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
diff --git a/components/canvas_traits/webgl.rs b/components/canvas_traits/webgl.rs
index 826a1c9b851..d5c7b488d59 100644
--- a/components/canvas_traits/webgl.rs
+++ b/components/canvas_traits/webgl.rs
@@ -206,7 +206,6 @@ pub enum WebGLCommand {
FramebufferRenderbuffer(u32, u32, u32, Option<WebGLRenderbufferId>),
FramebufferTexture2D(u32, u32, u32, Option<WebGLTextureId>, i32),
GetExtensions(WebGLSender<String>),
- GetTexParameter(u32, u32, WebGLSender<i32>),
GetShaderPrecisionFormat(u32, u32, WebGLSender<(i32, i32, i32)>),
GetActiveAttrib(WebGLProgramId, u32, WebGLSender<WebGLResult<(i32, u32, String)>>),
GetActiveUniform(WebGLProgramId, u32, WebGLSender<WebGLResult<(i32, u32, String)>>),
@@ -259,8 +258,6 @@ pub enum WebGLCommand {
VertexAttribPointer2f(u32, i32, bool, i32, u32),
SetViewport(i32, i32, i32, i32),
TexImage2D(u32, i32, i32, i32, i32, u32, u32, ByteBuf),
- TexParameteri(u32, u32, i32),
- TexParameterf(u32, u32, f32),
TexSubImage2D(u32, i32, i32, i32, i32, i32, u32, u32, ByteBuf),
DrawingBufferWidth(WebGLSender<i32>),
DrawingBufferHeight(WebGLSender<i32>),
@@ -284,6 +281,10 @@ pub enum WebGLCommand {
GetVertexAttribBool(u32, VertexAttribBool, WebGLSender<WebGLResult<bool>>),
GetVertexAttribInt(u32, VertexAttribInt, WebGLSender<WebGLResult<i32>>),
GetVertexAttribFloat4(u32, VertexAttribFloat4, WebGLSender<WebGLResult<[f32; 4]>>),
+ GetTexParameterFloat(u32, TexParameterFloat, WebGLSender<f32>),
+ GetTexParameterInt(u32, TexParameterInt, WebGLSender<i32>),
+ TexParameteri(u32, TexParameterInt, i32),
+ TexParameterf(u32, TexParameterFloat, f32),
}
macro_rules! define_resource_id_struct {
@@ -510,6 +511,7 @@ parameters! {
Float(ParameterFloat {
DepthClearValue = gl::DEPTH_CLEAR_VALUE,
LineWidth = gl::LINE_WIDTH,
+ MaxTextureMaxAnisotropyExt = gl::MAX_TEXTURE_MAX_ANISOTROPY_EXT,
PolygonOffsetFactor = gl::POLYGON_OFFSET_FACTOR,
PolygonOffsetUnits = gl::POLYGON_OFFSET_UNITS,
SampleCoverageValue = gl::SAMPLE_COVERAGE_VALUE,
@@ -554,6 +556,20 @@ parameters! {
}
parameters! {
+ TexParameter {
+ Float(TexParameterFloat {
+ TextureMaxAnisotropyExt = gl::TEXTURE_MAX_ANISOTROPY_EXT,
+ }),
+ Int(TexParameterInt {
+ TextureMagFilter = gl::TEXTURE_MAG_FILTER,
+ TextureMinFilter = gl::TEXTURE_MIN_FILTER,
+ TextureWrapS = gl::TEXTURE_WRAP_S,
+ TextureWrapT = gl::TEXTURE_WRAP_T,
+ }),
+ }
+}
+
+parameters! {
VertexAttrib {
Bool(VertexAttribBool {
VertexAttribArrayEnabled = gl::VERTEX_ATTRIB_ARRAY_ENABLED,
diff --git a/components/script/dom/webgl_extensions/ext/exttexturefilteranisotropic.rs b/components/script/dom/webgl_extensions/ext/exttexturefilteranisotropic.rs
new file mode 100644
index 00000000000..203f4da6251
--- /dev/null
+++ b/components/script/dom/webgl_extensions/ext/exttexturefilteranisotropic.rs
@@ -0,0 +1,54 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use canvas_traits::webgl::WebGLVersion;
+use dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding;
+use dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants;
+use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
+use dom::bindings::root::DomRoot;
+use dom::webglrenderingcontext::WebGLRenderingContext;
+use dom_struct::dom_struct;
+use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
+
+#[dom_struct]
+pub struct EXTTextureFilterAnisotropic {
+ reflector_: Reflector,
+}
+
+impl EXTTextureFilterAnisotropic {
+ fn new_inherited() -> EXTTextureFilterAnisotropic {
+ Self {
+ reflector_: Reflector::new(),
+ }
+ }
+}
+
+impl WebGLExtension for EXTTextureFilterAnisotropic {
+ type Extension = EXTTextureFilterAnisotropic;
+
+ fn new(ctx: &WebGLRenderingContext) -> DomRoot<Self> {
+ reflect_dom_object(
+ Box::new(Self::new_inherited()),
+ &*ctx.global(),
+ EXTTextureFilterAnisotropicBinding::Wrap,
+ )
+ }
+
+ fn spec() -> WebGLExtensionSpec {
+ WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
+ }
+
+ fn is_supported(ext: &WebGLExtensions) -> bool {
+ ext.supports_gl_extension("GL_EXT_texture_filter_anisotropic")
+ }
+
+ fn enable(ext: &WebGLExtensions) {
+ ext.enable_get_tex_parameter_name(EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT);
+ ext.enable_get_parameter_name(EXTTextureFilterAnisotropicConstants::MAX_TEXTURE_MAX_ANISOTROPY_EXT);
+ }
+
+ fn name() -> &'static str {
+ "EXT_texture_filter_anisotropic"
+ }
+}
diff --git a/components/script/dom/webgl_extensions/ext/mod.rs b/components/script/dom/webgl_extensions/ext/mod.rs
index b4b58fd10e1..e0c7b1f189a 100644
--- a/components/script/dom/webgl_extensions/ext/mod.rs
+++ b/components/script/dom/webgl_extensions/ext/mod.rs
@@ -6,6 +6,7 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi
use super::{ext_constants, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
pub mod extshadertexturelod;
+pub mod exttexturefilteranisotropic;
pub mod oeselementindexuint;
pub mod oesstandardderivatives;
pub mod oestexturefloat;
diff --git a/components/script/dom/webgl_extensions/extensions.rs b/components/script/dom/webgl_extensions/extensions.rs
index 92a34bac23e..33081e4bfe1 100644
--- a/components/script/dom/webgl_extensions/extensions.rs
+++ b/components/script/dom/webgl_extensions/extensions.rs
@@ -4,6 +4,7 @@
use canvas_traits::webgl::{WebGLError, WebGLVersion};
use dom::bindings::cell::DomRefCell;
+use dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants;
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
@@ -41,8 +42,16 @@ const DEFAULT_NOT_FILTERABLE_TEX_TYPES: [GLenum; 2] = [
// Param names that are implemented for glGetParameter in a WebGL 1.0 context
// but must trigger a InvalidEnum error until the related WebGL Extensions are enabled.
// Example: https://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/
-const DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1: [GLenum; 1] = [
- OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES
+const DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1: [GLenum; 2] = [
+ EXTTextureFilterAnisotropicConstants::MAX_TEXTURE_MAX_ANISOTROPY_EXT,
+ OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES,
+];
+
+// Param names that are implemented for glGetTexParameter in a WebGL 1.0 context
+// but must trigger a InvalidEnum error until the related WebGL Extensions are enabled.
+// Example: https://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/
+const DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1: [GLenum; 1] = [
+ EXTTextureFilterAnisotropicConstants::TEXTURE_MAX_ANISOTROPY_EXT,
];
/// WebGL features that are enabled/disabled by WebGL Extensions.
@@ -57,20 +66,30 @@ struct WebGLExtensionFeatures {
hint_targets: FnvHashSet<GLenum>,
/// WebGL GetParameter() names enabled by extensions.
disabled_get_parameter_names: FnvHashSet<GLenum>,
+ /// WebGL GetTexParameter() names enabled by extensions.
+ disabled_get_tex_parameter_names: FnvHashSet<GLenum>,
/// WebGL OES_element_index_uint extension.
element_index_uint_enabled: bool,
}
impl WebGLExtensionFeatures {
fn new(webgl_version: WebGLVersion) -> Self {
- let (disabled_tex_types, disabled_get_parameter_names, element_index_uint_enabled) = match webgl_version {
+ let (
+ disabled_tex_types,
+ disabled_get_parameter_names,
+ disabled_get_tex_parameter_names,
+ element_index_uint_enabled,
+ ) = match webgl_version {
WebGLVersion::WebGL1 => {
- (DEFAULT_DISABLED_TEX_TYPES_WEBGL1.iter().cloned().collect(),
- DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
- false)
+ (
+ DEFAULT_DISABLED_TEX_TYPES_WEBGL1.iter().cloned().collect(),
+ DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
+ DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
+ false,
+ )
},
WebGLVersion::WebGL2 => {
- (Default::default(), Default::default(), true)
+ (Default::default(), Default::default(), Default::default(), true)
}
};
Self {
@@ -81,6 +100,7 @@ impl WebGLExtensionFeatures {
query_parameter_handlers: Default::default(),
hint_targets: Default::default(),
disabled_get_parameter_names,
+ disabled_get_tex_parameter_names,
element_index_uint_enabled,
}
}
@@ -236,7 +256,16 @@ impl WebGLExtensions {
!self.features.borrow().disabled_get_parameter_names.contains(&name)
}
+ pub fn enable_get_tex_parameter_name(&self, name: GLenum) {
+ self.features.borrow_mut().disabled_get_tex_parameter_names.remove(&name);
+ }
+
+ pub fn is_get_tex_parameter_name_enabled(&self, name: GLenum) -> bool {
+ !self.features.borrow().disabled_get_tex_parameter_names.contains(&name)
+ }
+
fn register_all_extensions(&self) {
+ self.register::<ext::exttexturefilteranisotropic::EXTTextureFilterAnisotropic>();
self.register::<ext::oeselementindexuint::OESElementIndexUint>();
self.register::<ext::oesstandardderivatives::OESStandardDerivatives>();
self.register::<ext::oestexturefloat::OESTextureFloat>();
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index 37638e36ee4..7beeef9261d 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -5,7 +5,7 @@
use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use canvas_traits::canvas::{byte_swap, multiply_u8_pixel};
use canvas_traits::webgl::{DOMToTextureCommand, Parameter, ProgramParameter};
-use canvas_traits::webgl::{ShaderParameter, VertexAttrib, WebGLCommand};
+use canvas_traits::webgl::{ShaderParameter, TexParameter, VertexAttrib, WebGLCommand};
use canvas_traits::webgl::{WebGLContextShareMode, WebGLError};
use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender};
use canvas_traits::webgl::{WebGLResult, WebGLSLVersion, WebGLVersion};
@@ -432,27 +432,35 @@ impl WebGLRenderingContext {
constants::TEXTURE_CUBE_MAP => self.bound_texture(target),
_ => return self.webgl_error(InvalidEnum),
};
- if let Some(texture) = texture {
- handle_potential_webgl_error!(self, texture.tex_parameter(target, name, value));
- // Validate non filterable TEXTURE_2D data_types
- if target != constants::TEXTURE_2D {
- return;
- }
+ if !self.extension_manager.is_get_tex_parameter_name_enabled(name) {
+ return self.webgl_error(InvalidEnum);
+ }
- let target = TexImageTarget::Texture2D;
- let info = texture.image_info_for_target(&target, 0);
- if info.is_initialized() {
- self.validate_filterable_texture(&texture,
- target,
- 0,
- info.internal_format().unwrap_or(TexFormat::RGBA),
- info.width(),
- info.height(),
- info.data_type().unwrap_or(TexDataType::UnsignedByte));
- }
- } else {
- self.webgl_error(InvalidOperation)
+ let param = handle_potential_webgl_error!(self, TexParameter::from_u32(name), return);
+ let texture = match texture {
+ Some(tex) => tex,
+ None => return self.webgl_error(InvalidOperation),
+ };
+ handle_potential_webgl_error!(self, texture.tex_parameter(param, value), return);
+
+ // Validate non filterable TEXTURE_2D data_types
+ if target != constants::TEXTURE_2D {
+ return;
+ }
+
+ let target = TexImageTarget::Texture2D;
+ let info = texture.image_info_for_target(&target, 0);
+ if info.is_initialized() {
+ self.validate_filterable_texture(
+ &texture,
+ target,
+ 0,
+ info.internal_format().unwrap_or(TexFormat::RGBA),
+ info.width(),
+ info.height(),
+ info.data_type().unwrap_or(TexDataType::UnsignedByte),
+ );
}
}
@@ -1437,21 +1445,16 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
#[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8
unsafe fn GetTexParameter(&self, _cx: *mut JSContext, target: u32, pname: u32) -> JSVal {
- let target_matches = match target {
+ match target {
constants::TEXTURE_2D |
- constants::TEXTURE_CUBE_MAP => true,
- _ => false,
- };
-
- let pname_matches = match pname {
- constants::TEXTURE_MAG_FILTER |
- constants::TEXTURE_MIN_FILTER |
- constants::TEXTURE_WRAP_S |
- constants::TEXTURE_WRAP_T => true,
- _ => false,
+ constants::TEXTURE_CUBE_MAP => {},
+ _ => {
+ self.webgl_error(InvalidEnum);
+ return NullValue();
+ }
};
- if !target_matches || !pname_matches {
+ if !self.extension_manager.is_get_tex_parameter_name_enabled(pname) {
self.webgl_error(InvalidEnum);
return NullValue();
}
@@ -1461,10 +1464,18 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return NullValue();
}
- let (sender, receiver) = webgl_channel().unwrap();
- self.send_command(WebGLCommand::GetTexParameter(target, pname, sender));
-
- Int32Value(receiver.recv().unwrap())
+ match handle_potential_webgl_error!(self, TexParameter::from_u32(pname), return NullValue()) {
+ TexParameter::Float(param) => {
+ let (sender, receiver) = webgl_channel().unwrap();
+ self.send_command(WebGLCommand::GetTexParameterFloat(target, param, sender));
+ DoubleValue(receiver.recv().unwrap() as f64)
+ }
+ TexParameter::Int(param) => {
+ let (sender, receiver) = webgl_channel().unwrap();
+ self.send_command(WebGLCommand::GetTexParameterInt(target, param, sender));
+ Int32Value(receiver.recv().unwrap())
+ }
+ }
}
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3
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),
+ }
}
}
diff --git a/components/script/dom/webidls/EXTTextureFilterAnisotropic.webidl b/components/script/dom/webidls/EXTTextureFilterAnisotropic.webidl
new file mode 100644
index 00000000000..1c8c1a15171
--- /dev/null
+++ b/components/script/dom/webidls/EXTTextureFilterAnisotropic.webidl
@@ -0,0 +1,13 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+/*
+ * WebGL IDL definitions from the Khronos specification:
+ * https://www.khronos.org/registry/webgl/extensions/EXT_texture_filter_anisotropic/
+ */
+
+[NoInterfaceObject]
+interface EXTTextureFilterAnisotropic {
+ const GLenum TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE;
+ const GLenum MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF;
+};