Implement EXT_texture_filter_anisotropic

This commit is contained in:
Anthony Ramine 2018-05-25 14:58:50 +02:00
parent eb1dfd0775
commit f1288cc6e0
10 changed files with 262 additions and 122 deletions

26
Cargo.lock generated
View file

@ -274,7 +274,7 @@ dependencies = [
"cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "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)", "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
@ -291,7 +291,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"malloc_size_of 0.0.1", "malloc_size_of 0.0.1",
@ -336,7 +336,7 @@ name = "cgl"
version = "0.2.2" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ 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)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -425,7 +425,7 @@ dependencies = [
"embedder_traits 0.0.1", "embedder_traits 0.0.1",
"euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gfx_traits 0.0.1", "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)", "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)", "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)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1063,7 +1063,7 @@ dependencies = [
[[package]] [[package]]
name = "gleam" name = "gleam"
version = "0.5.0" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"gl_generator 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "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 = [ dependencies = [
"cgl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gaol 0.0.1 (git+https://github.com/servo/gaol)", "gaol 0.0.1 (git+https://github.com/servo/gaol)",
"gfx 0.0.1", "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)", "ipc-channel 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"layout_thread 0.0.1", "layout_thread 0.0.1",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libservo 0.0.1", "libservo 0.0.1",
@ -2774,7 +2774,7 @@ dependencies = [
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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)", "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 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 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 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 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 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" "checksum glx 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "63a6e7c2846e12626455f45ebaff9d92161436dd0fa703d9d198012e528ca7b9"

View file

@ -761,9 +761,6 @@ impl WebGLImpl {
Self::get_framebuffer_attachment_parameter(ctx.gl(), target, attachment, pname, chan), Self::get_framebuffer_attachment_parameter(ctx.gl(), target, attachment, pname, chan),
WebGLCommand::GetVertexAttribOffset(index, pname, ref chan) => WebGLCommand::GetVertexAttribOffset(index, pname, ref chan) =>
Self::vertex_attrib_offset(ctx.gl(), index, pname, 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) => WebGLCommand::GetShaderPrecisionFormat(shader_type, precision_type, ref chan) =>
Self::shader_precision_format(ctx.gl(), shader_type, precision_type, chan), Self::shader_precision_format(ctx.gl(), shader_type, precision_type, chan),
WebGLCommand::GetExtensions(ref chan) => WebGLCommand::GetExtensions(ref chan) =>
@ -864,10 +861,6 @@ impl WebGLImpl {
WebGLCommand::TexImage2D(target, level, internal, width, height, format, data_type, ref data) => WebGLCommand::TexImage2D(target, level, internal, width, height, format, data_type, ref data) =>
ctx.gl().tex_image_2d(target, level, internal, width, height, ctx.gl().tex_image_2d(target, level, internal, width, height,
/*border*/0, format, data_type, Some(data)), /*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) => 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), ctx.gl().tex_sub_image_2d(target, level, xoffset, yoffset, x, y, width, height, data),
WebGLCommand::DrawingBufferWidth(ref sender) => WebGLCommand::DrawingBufferWidth(ref sender) =>
@ -1020,6 +1013,18 @@ impl WebGLImpl {
}; };
sender.send(result).unwrap(); 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 // TODO: update test expectations in order to enable debug assertions

View file

@ -13,7 +13,7 @@ path = "lib.rs"
cssparser = "0.23.0" cssparser = "0.23.0"
euclid = "0.17" euclid = "0.17"
ipc-channel = "0.10" ipc-channel = "0.10"
gleam = "0.5" gleam = "0.5.1"
lazy_static = "1" lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" } malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" } malloc_size_of_derive = { path = "../malloc_size_of_derive" }

View file

@ -206,7 +206,6 @@ pub enum WebGLCommand {
FramebufferRenderbuffer(u32, u32, u32, Option<WebGLRenderbufferId>), FramebufferRenderbuffer(u32, u32, u32, Option<WebGLRenderbufferId>),
FramebufferTexture2D(u32, u32, u32, Option<WebGLTextureId>, i32), FramebufferTexture2D(u32, u32, u32, Option<WebGLTextureId>, i32),
GetExtensions(WebGLSender<String>), GetExtensions(WebGLSender<String>),
GetTexParameter(u32, u32, WebGLSender<i32>),
GetShaderPrecisionFormat(u32, u32, WebGLSender<(i32, i32, i32)>), GetShaderPrecisionFormat(u32, u32, WebGLSender<(i32, i32, i32)>),
GetActiveAttrib(WebGLProgramId, u32, WebGLSender<WebGLResult<(i32, u32, String)>>), GetActiveAttrib(WebGLProgramId, u32, WebGLSender<WebGLResult<(i32, u32, String)>>),
GetActiveUniform(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), VertexAttribPointer2f(u32, i32, bool, i32, u32),
SetViewport(i32, i32, i32, i32), SetViewport(i32, i32, i32, i32),
TexImage2D(u32, i32, i32, i32, i32, u32, u32, ByteBuf), 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), TexSubImage2D(u32, i32, i32, i32, i32, i32, u32, u32, ByteBuf),
DrawingBufferWidth(WebGLSender<i32>), DrawingBufferWidth(WebGLSender<i32>),
DrawingBufferHeight(WebGLSender<i32>), DrawingBufferHeight(WebGLSender<i32>),
@ -284,6 +281,10 @@ pub enum WebGLCommand {
GetVertexAttribBool(u32, VertexAttribBool, WebGLSender<WebGLResult<bool>>), GetVertexAttribBool(u32, VertexAttribBool, WebGLSender<WebGLResult<bool>>),
GetVertexAttribInt(u32, VertexAttribInt, WebGLSender<WebGLResult<i32>>), GetVertexAttribInt(u32, VertexAttribInt, WebGLSender<WebGLResult<i32>>),
GetVertexAttribFloat4(u32, VertexAttribFloat4, WebGLSender<WebGLResult<[f32; 4]>>), 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 { macro_rules! define_resource_id_struct {
@ -510,6 +511,7 @@ parameters! {
Float(ParameterFloat { Float(ParameterFloat {
DepthClearValue = gl::DEPTH_CLEAR_VALUE, DepthClearValue = gl::DEPTH_CLEAR_VALUE,
LineWidth = gl::LINE_WIDTH, LineWidth = gl::LINE_WIDTH,
MaxTextureMaxAnisotropyExt = gl::MAX_TEXTURE_MAX_ANISOTROPY_EXT,
PolygonOffsetFactor = gl::POLYGON_OFFSET_FACTOR, PolygonOffsetFactor = gl::POLYGON_OFFSET_FACTOR,
PolygonOffsetUnits = gl::POLYGON_OFFSET_UNITS, PolygonOffsetUnits = gl::POLYGON_OFFSET_UNITS,
SampleCoverageValue = gl::SAMPLE_COVERAGE_VALUE, SampleCoverageValue = gl::SAMPLE_COVERAGE_VALUE,
@ -553,6 +555,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! { parameters! {
VertexAttrib { VertexAttrib {
Bool(VertexAttribBool { Bool(VertexAttribBool {

View file

@ -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"
}
}

View file

@ -6,6 +6,7 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderi
use super::{ext_constants, WebGLExtension, WebGLExtensions, WebGLExtensionSpec}; use super::{ext_constants, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
pub mod extshadertexturelod; pub mod extshadertexturelod;
pub mod exttexturefilteranisotropic;
pub mod oeselementindexuint; pub mod oeselementindexuint;
pub mod oesstandardderivatives; pub mod oesstandardderivatives;
pub mod oestexturefloat; pub mod oestexturefloat;

View file

@ -4,6 +4,7 @@
use canvas_traits::webgl::{WebGLError, WebGLVersion}; use canvas_traits::webgl::{WebGLError, WebGLVersion};
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::EXTTextureFilterAnisotropicBinding::EXTTextureFilterAnisotropicConstants;
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants; use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants; use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; 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 // 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. // but must trigger a InvalidEnum error until the related WebGL Extensions are enabled.
// Example: https://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/ // Example: https://www.khronos.org/registry/webgl/extensions/OES_standard_derivatives/
const DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1: [GLenum; 1] = [ const DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1: [GLenum; 2] = [
OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES 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. /// WebGL features that are enabled/disabled by WebGL Extensions.
@ -57,20 +66,30 @@ struct WebGLExtensionFeatures {
hint_targets: FnvHashSet<GLenum>, hint_targets: FnvHashSet<GLenum>,
/// WebGL GetParameter() names enabled by extensions. /// WebGL GetParameter() names enabled by extensions.
disabled_get_parameter_names: FnvHashSet<GLenum>, 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. /// WebGL OES_element_index_uint extension.
element_index_uint_enabled: bool, element_index_uint_enabled: bool,
} }
impl WebGLExtensionFeatures { impl WebGLExtensionFeatures {
fn new(webgl_version: WebGLVersion) -> Self { 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 => { WebGLVersion::WebGL1 => {
(DEFAULT_DISABLED_TEX_TYPES_WEBGL1.iter().cloned().collect(), (
DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(), DEFAULT_DISABLED_TEX_TYPES_WEBGL1.iter().cloned().collect(),
false) DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
false,
)
}, },
WebGLVersion::WebGL2 => { WebGLVersion::WebGL2 => {
(Default::default(), Default::default(), true) (Default::default(), Default::default(), Default::default(), true)
} }
}; };
Self { Self {
@ -81,6 +100,7 @@ impl WebGLExtensionFeatures {
query_parameter_handlers: Default::default(), query_parameter_handlers: Default::default(),
hint_targets: Default::default(), hint_targets: Default::default(),
disabled_get_parameter_names, disabled_get_parameter_names,
disabled_get_tex_parameter_names,
element_index_uint_enabled, element_index_uint_enabled,
} }
} }
@ -236,7 +256,16 @@ impl WebGLExtensions {
!self.features.borrow().disabled_get_parameter_names.contains(&name) !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) { fn register_all_extensions(&self) {
self.register::<ext::exttexturefilteranisotropic::EXTTextureFilterAnisotropic>();
self.register::<ext::oeselementindexuint::OESElementIndexUint>(); self.register::<ext::oeselementindexuint::OESElementIndexUint>();
self.register::<ext::oesstandardderivatives::OESStandardDerivatives>(); self.register::<ext::oesstandardderivatives::OESStandardDerivatives>();
self.register::<ext::oestexturefloat::OESTextureFloat>(); self.register::<ext::oestexturefloat::OESTextureFloat>();

View file

@ -5,7 +5,7 @@
use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use canvas_traits::canvas::{byte_swap, multiply_u8_pixel}; use canvas_traits::canvas::{byte_swap, multiply_u8_pixel};
use canvas_traits::webgl::{DOMToTextureCommand, Parameter, ProgramParameter}; 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::{WebGLContextShareMode, WebGLError};
use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender}; use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender};
use canvas_traits::webgl::{WebGLResult, WebGLSLVersion, WebGLVersion}; use canvas_traits::webgl::{WebGLResult, WebGLSLVersion, WebGLVersion};
@ -432,27 +432,35 @@ impl WebGLRenderingContext {
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 let Some(texture) = texture {
handle_potential_webgl_error!(self, texture.tex_parameter(target, name, value));
// Validate non filterable TEXTURE_2D data_types if !self.extension_manager.is_get_tex_parameter_name_enabled(name) {
if target != constants::TEXTURE_2D { return self.webgl_error(InvalidEnum);
return; }
}
let target = TexImageTarget::Texture2D; let param = handle_potential_webgl_error!(self, TexParameter::from_u32(name), return);
let info = texture.image_info_for_target(&target, 0); let texture = match texture {
if info.is_initialized() { Some(tex) => tex,
self.validate_filterable_texture(&texture, None => return self.webgl_error(InvalidOperation),
target, };
0, handle_potential_webgl_error!(self, texture.tex_parameter(param, value), return);
info.internal_format().unwrap_or(TexFormat::RGBA),
info.width(), // Validate non filterable TEXTURE_2D data_types
info.height(), if target != constants::TEXTURE_2D {
info.data_type().unwrap_or(TexDataType::UnsignedByte)); return;
} }
} else {
self.webgl_error(InvalidOperation) 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)] #[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.8 // 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 { unsafe fn GetTexParameter(&self, _cx: *mut JSContext, target: u32, pname: u32) -> JSVal {
let target_matches = match target { match target {
constants::TEXTURE_2D | constants::TEXTURE_2D |
constants::TEXTURE_CUBE_MAP => true, constants::TEXTURE_CUBE_MAP => {},
_ => false, _ => {
self.webgl_error(InvalidEnum);
return NullValue();
}
}; };
let pname_matches = match pname { if !self.extension_manager.is_get_tex_parameter_name_enabled(pname) {
constants::TEXTURE_MAG_FILTER |
constants::TEXTURE_MIN_FILTER |
constants::TEXTURE_WRAP_S |
constants::TEXTURE_WRAP_T => true,
_ => false,
};
if !target_matches || !pname_matches {
self.webgl_error(InvalidEnum); self.webgl_error(InvalidEnum);
return NullValue(); return NullValue();
} }
@ -1461,10 +1464,18 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
return NullValue(); return NullValue();
} }
let (sender, receiver) = webgl_channel().unwrap(); match handle_potential_webgl_error!(self, TexParameter::from_u32(pname), return NullValue()) {
self.send_command(WebGLCommand::GetTexParameter(target, pname, sender)); TexParameter::Float(param) => {
let (sender, receiver) = webgl_channel().unwrap();
Int32Value(receiver.recv().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 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.3

View file

@ -4,8 +4,9 @@
// 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::{webgl_channel, WebGLCommand, WebGLError, WebGLMsgSender, WebGLResult, WebGLTextureId}; use canvas_traits::webgl::{DOMToTextureCommand, TexParameter, TexParameterFloat};
use canvas_traits::webgl::DOMToTextureCommand; use canvas_traits::webgl::{TexParameterInt, WebGLCommand, WebGLError, WebGLMsgSender};
use canvas_traits::webgl::{WebGLResult, WebGLTextureId, webgl_channel};
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
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;
@ -202,65 +203,75 @@ impl WebGLTexture {
/// We have to follow the conversion rules for GLES 2.0. See: /// We have to follow the conversion rules for GLES 2.0. See:
/// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html /// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html
/// ///
pub fn tex_parameter(&self, pub fn tex_parameter(
target: u32, &self,
name: u32, param: TexParameter,
value: TexParameterValue) -> WebGLResult<()> { value: TexParameterValue,
let (int_value, _float_value) = match value { ) -> WebGLResult<()> {
let target = self.target().unwrap();
let (int_value, float_value) = match value {
TexParameterValue::Int(int_value) => (int_value, int_value as f32), TexParameterValue::Int(int_value) => (int_value, int_value as f32),
TexParameterValue::Float(float_value) => (float_value as i32, float_value), TexParameterValue::Float(float_value) => (float_value as i32, float_value),
}; };
match name { match param {
constants::TEXTURE_MIN_FILTER => { TexParameter::Int(int_param) => {
match int_value as u32 { match int_param {
constants::NEAREST | TexParameterInt::TextureMinFilter => {
constants::LINEAR | match int_value as u32 {
constants::NEAREST_MIPMAP_NEAREST | constants::NEAREST |
constants::LINEAR_MIPMAP_NEAREST | constants::LINEAR |
constants::NEAREST_MIPMAP_LINEAR | constants::NEAREST_MIPMAP_NEAREST |
constants::LINEAR_MIPMAP_LINEAR => { constants::LINEAR_MIPMAP_NEAREST |
self.min_filter.set(Some(int_value as u32)); constants::NEAREST_MIPMAP_LINEAR |
self.renderer constants::LINEAR_MIPMAP_LINEAR => {
.send(WebGLCommand::TexParameteri(target, name, int_value)) self.min_filter.set(Some(int_value as u32));
.unwrap(); self.renderer
Ok(()) .send(WebGLCommand::TexParameteri(target, int_param, int_value))
}, .unwrap();
Ok(())
_ => Err(WebGLError::InvalidEnum), }
_ => 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 => { TexParameter::Float(float_param @ TexParameterFloat::TextureMaxAnisotropyExt) => {
match int_value as u32 { if float_value >= 1. {
constants::NEAREST | self.renderer
constants::LINEAR => { .send(WebGLCommand::TexParameterf(target, float_param, float_value))
self.mag_filter.set(Some(int_value as u32)); .unwrap();
self.renderer Ok(())
.send(WebGLCommand::TexParameteri(target, name, int_value)) } else {
.unwrap(); Err(WebGLError::InvalidValue)
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),
}
},
_ => Err(WebGLError::InvalidEnum),
} }
} }

View file

@ -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;
};