mirror of
https://github.com/servo/servo.git
synced 2025-07-19 21:33:49 +01:00
Implement EXT_blend_minmax
This commit is contained in:
parent
6a4bd8d3fa
commit
02b8766e75
6 changed files with 99 additions and 65 deletions
50
components/script/dom/webgl_extensions/ext/extblendminmax.rs
Normal file
50
components/script/dom/webgl_extensions/ext/extblendminmax.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/* 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::EXTBlendMinmaxBinding;
|
||||||
|
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 EXTBlendMinmax {
|
||||||
|
reflector_: Reflector,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EXTBlendMinmax {
|
||||||
|
fn new_inherited() -> Self {
|
||||||
|
Self { reflector_: Reflector::new() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WebGLExtension for EXTBlendMinmax {
|
||||||
|
type Extension = Self;
|
||||||
|
|
||||||
|
fn new(ctx: &WebGLRenderingContext) -> DomRoot<Self> {
|
||||||
|
reflect_dom_object(
|
||||||
|
Box::new(Self::new_inherited()),
|
||||||
|
&*ctx.global(),
|
||||||
|
EXTBlendMinmaxBinding::Wrap,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spec() -> WebGLExtensionSpec {
|
||||||
|
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_supported(ext: &WebGLExtensions) -> bool {
|
||||||
|
ext.supports_gl_extension("GL_EXT_blend_minmax")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enable(ext: &WebGLExtensions) {
|
||||||
|
ext.enable_blend_minmax();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn name() -> &'static str {
|
||||||
|
"EXT_blend_minmax"
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||||
use super::{ext_constants, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
use super::{ext_constants, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
|
||||||
|
|
||||||
|
pub mod extblendminmax;
|
||||||
pub mod extshadertexturelod;
|
pub mod extshadertexturelod;
|
||||||
pub mod exttexturefilteranisotropic;
|
pub mod exttexturefilteranisotropic;
|
||||||
pub mod oeselementindexuint;
|
pub mod oeselementindexuint;
|
||||||
|
|
|
@ -70,6 +70,8 @@ struct WebGLExtensionFeatures {
|
||||||
disabled_get_tex_parameter_names: FnvHashSet<GLenum>,
|
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,
|
||||||
|
/// WebGL EXT_blend_minmax extension.
|
||||||
|
blend_minmax_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebGLExtensionFeatures {
|
impl WebGLExtensionFeatures {
|
||||||
|
@ -79,6 +81,7 @@ impl WebGLExtensionFeatures {
|
||||||
disabled_get_parameter_names,
|
disabled_get_parameter_names,
|
||||||
disabled_get_tex_parameter_names,
|
disabled_get_tex_parameter_names,
|
||||||
element_index_uint_enabled,
|
element_index_uint_enabled,
|
||||||
|
blend_minmax_enabled,
|
||||||
) = match webgl_version {
|
) = match webgl_version {
|
||||||
WebGLVersion::WebGL1 => {
|
WebGLVersion::WebGL1 => {
|
||||||
(
|
(
|
||||||
|
@ -86,10 +89,11 @@ impl WebGLExtensionFeatures {
|
||||||
DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
|
DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
|
||||||
DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
|
DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
WebGLVersion::WebGL2 => {
|
WebGLVersion::WebGL2 => {
|
||||||
(Default::default(), Default::default(), Default::default(), true)
|
(Default::default(), Default::default(), Default::default(), true, true)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
|
@ -102,6 +106,7 @@ impl WebGLExtensionFeatures {
|
||||||
disabled_get_parameter_names,
|
disabled_get_parameter_names,
|
||||||
disabled_get_tex_parameter_names,
|
disabled_get_tex_parameter_names,
|
||||||
element_index_uint_enabled,
|
element_index_uint_enabled,
|
||||||
|
blend_minmax_enabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,6 +270,7 @@ impl WebGLExtensions {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_all_extensions(&self) {
|
fn register_all_extensions(&self) {
|
||||||
|
self.register::<ext::extblendminmax::EXTBlendMinmax>();
|
||||||
self.register::<ext::extshadertexturelod::EXTShaderTextureLod>();
|
self.register::<ext::extshadertexturelod::EXTShaderTextureLod>();
|
||||||
self.register::<ext::exttexturefilteranisotropic::EXTTextureFilterAnisotropic>();
|
self.register::<ext::exttexturefilteranisotropic::EXTTextureFilterAnisotropic>();
|
||||||
self.register::<ext::oeselementindexuint::OESElementIndexUint>();
|
self.register::<ext::oeselementindexuint::OESElementIndexUint>();
|
||||||
|
@ -283,6 +289,14 @@ impl WebGLExtensions {
|
||||||
pub fn is_element_index_uint_enabled(&self) -> bool {
|
pub fn is_element_index_uint_enabled(&self) -> bool {
|
||||||
self.features.borrow().element_index_uint_enabled
|
self.features.borrow().element_index_uint_enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn enable_blend_minmax(&self) {
|
||||||
|
self.features.borrow_mut().blend_minmax_enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_blend_minmax_enabled(&self) -> bool {
|
||||||
|
self.features.borrow().blend_minmax_enabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper structs
|
// Helper structs
|
||||||
|
|
|
@ -12,6 +12,7 @@ use canvas_traits::webgl::{WebGLResult, WebGLSLVersion, WebGLVersion};
|
||||||
use canvas_traits::webgl::{WebVRCommand, webgl_channel};
|
use canvas_traits::webgl::{WebVRCommand, webgl_channel};
|
||||||
use canvas_traits::webgl::WebGLError::*;
|
use canvas_traits::webgl::WebGLError::*;
|
||||||
use dom::bindings::cell::DomRefCell;
|
use dom::bindings::cell::DomRefCell;
|
||||||
|
use dom::bindings::codegen::Bindings::EXTBlendMinmaxBinding::EXTBlendMinmaxConstants;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
|
||||||
|
@ -1193,6 +1194,21 @@ impl WebGLRenderingContext {
|
||||||
_ => Err(WebGLError::InvalidEnum),
|
_ => Err(WebGLError::InvalidEnum),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn validate_blend_mode(&self, mode: u32) -> WebGLResult<()> {
|
||||||
|
match mode {
|
||||||
|
constants::FUNC_ADD |
|
||||||
|
constants::FUNC_SUBTRACT |
|
||||||
|
constants::FUNC_REVERSE_SUBTRACT => {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
EXTBlendMinmaxConstants::MIN_EXT |
|
||||||
|
EXTBlendMinmaxConstants::MAX_EXT if self.extension_manager.is_blend_minmax_enabled() => {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(InvalidEnum),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for WebGLRenderingContext {
|
impl Drop for WebGLRenderingContext {
|
||||||
|
@ -1547,30 +1563,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
|
|
||||||
// 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
|
||||||
fn BlendEquation(&self, mode: u32) {
|
fn BlendEquation(&self, mode: u32) {
|
||||||
match mode {
|
handle_potential_webgl_error!(self, self.validate_blend_mode(mode), return);
|
||||||
constants::FUNC_ADD |
|
self.send_command(WebGLCommand::BlendEquation(mode))
|
||||||
constants::FUNC_SUBTRACT |
|
|
||||||
constants::FUNC_REVERSE_SUBTRACT => {
|
|
||||||
self.send_command(WebGLCommand::BlendEquation(mode))
|
|
||||||
}
|
|
||||||
_ => self.webgl_error(InvalidEnum),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
fn BlendEquationSeparate(&self, mode_rgb: u32, mode_alpha: u32) {
|
fn BlendEquationSeparate(&self, mode_rgb: u32, mode_alpha: u32) {
|
||||||
match mode_rgb {
|
handle_potential_webgl_error!(self, self.validate_blend_mode(mode_rgb), return);
|
||||||
constants::FUNC_ADD |
|
handle_potential_webgl_error!(self, self.validate_blend_mode(mode_alpha), return);
|
||||||
constants::FUNC_SUBTRACT |
|
|
||||||
constants::FUNC_REVERSE_SUBTRACT => {},
|
|
||||||
_ => return self.webgl_error(InvalidEnum),
|
|
||||||
}
|
|
||||||
match mode_alpha {
|
|
||||||
constants::FUNC_ADD |
|
|
||||||
constants::FUNC_SUBTRACT |
|
|
||||||
constants::FUNC_REVERSE_SUBTRACT => {},
|
|
||||||
_ => return self.webgl_error(InvalidEnum),
|
|
||||||
}
|
|
||||||
self.send_command(WebGLCommand::BlendEquationSeparate(mode_rgb, mode_alpha));
|
self.send_command(WebGLCommand::BlendEquationSeparate(mode_rgb, mode_alpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
components/script/dom/webidls/EXTBlendMinmax.webidl
Normal file
13
components/script/dom/webidls/EXTBlendMinmax.webidl
Normal 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 scraped from the Khronos specification:
|
||||||
|
* https://www.khronos.org/registry/webgl/extensions/EXT_blend_minmax/
|
||||||
|
*/
|
||||||
|
|
||||||
|
[NoInterfaceObject]
|
||||||
|
interface EXTBlendMinmax {
|
||||||
|
const GLenum MIN_EXT = 0x8007;
|
||||||
|
const GLenum MAX_EXT = 0x8008;
|
||||||
|
};
|
|
@ -1,44 +0,0 @@
|
||||||
[ext-blend-minmax.html]
|
|
||||||
type: testharness
|
|
||||||
[WebGL test #1: getError expected: INVALID_ENUM. Was NO_ERROR : after evaluating: gl.blendEquation(MIN_EXT)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #2: gl.getParameter(gl.BLEND_EQUATION) should be 32774. Was 32775.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #3: getError expected: INVALID_ENUM. Was NO_ERROR : after evaluating: gl.blendEquation(MAX_EXT)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #4: gl.getParameter(gl.BLEND_EQUATION) should be 32774. Was 32776.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #5: getError expected: INVALID_ENUM. Was NO_ERROR : after evaluating: gl.blendEquationSeparate(MIN_EXT, gl.FUNC_ADD)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #6: gl.getParameter(gl.BLEND_EQUATION_RGB) should be 32774. Was 32775.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #7: getError expected: INVALID_ENUM. Was NO_ERROR : after evaluating: gl.blendEquationSeparate(gl.FUNC_ADD, MIN_EXT)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #8: gl.getParameter(gl.BLEND_EQUATION_ALPHA) should be 32774. Was 32775.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #9: getError expected: INVALID_ENUM. Was NO_ERROR : after evaluating: gl.blendEquationSeparate(MAX_EXT, gl.FUNC_ADD)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #10: gl.getParameter(gl.BLEND_EQUATION_RGB) should be 32774. Was 32776.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #11: getError expected: INVALID_ENUM. Was NO_ERROR : after evaluating: gl.blendEquationSeparate(gl.FUNC_ADD, MAX_EXT)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #12: gl.getParameter(gl.BLEND_EQUATION_ALPHA) should be 32774. Was 32776.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #0: Unable to fetch WebGL rendering context for Canvas]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[WebGL test #1: WebGL context does not exist]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue