Implement EXT_blend_minmax

This commit is contained in:
Anthony Ramine 2018-06-22 11:30:10 +02:00
parent 6a4bd8d3fa
commit 02b8766e75
6 changed files with 99 additions and 65 deletions

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

View file

@ -5,6 +5,7 @@
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use super::{ext_constants, WebGLExtension, WebGLExtensions, WebGLExtensionSpec};
pub mod extblendminmax;
pub mod extshadertexturelod;
pub mod exttexturefilteranisotropic;
pub mod oeselementindexuint;

View file

@ -70,6 +70,8 @@ struct WebGLExtensionFeatures {
disabled_get_tex_parameter_names: FnvHashSet<GLenum>,
/// WebGL OES_element_index_uint extension.
element_index_uint_enabled: bool,
/// WebGL EXT_blend_minmax extension.
blend_minmax_enabled: bool,
}
impl WebGLExtensionFeatures {
@ -79,6 +81,7 @@ impl WebGLExtensionFeatures {
disabled_get_parameter_names,
disabled_get_tex_parameter_names,
element_index_uint_enabled,
blend_minmax_enabled,
) = match webgl_version {
WebGLVersion::WebGL1 => {
(
@ -86,10 +89,11 @@ impl WebGLExtensionFeatures {
DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
DEFAULT_DISABLED_GET_TEX_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
false,
false,
)
},
WebGLVersion::WebGL2 => {
(Default::default(), Default::default(), Default::default(), true)
(Default::default(), Default::default(), Default::default(), true, true)
}
};
Self {
@ -102,6 +106,7 @@ impl WebGLExtensionFeatures {
disabled_get_parameter_names,
disabled_get_tex_parameter_names,
element_index_uint_enabled,
blend_minmax_enabled,
}
}
}
@ -265,6 +270,7 @@ impl WebGLExtensions {
}
fn register_all_extensions(&self) {
self.register::<ext::extblendminmax::EXTBlendMinmax>();
self.register::<ext::extshadertexturelod::EXTShaderTextureLod>();
self.register::<ext::exttexturefilteranisotropic::EXTTextureFilterAnisotropic>();
self.register::<ext::oeselementindexuint::OESElementIndexUint>();
@ -283,6 +289,14 @@ impl WebGLExtensions {
pub fn is_element_index_uint_enabled(&self) -> bool {
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