Implement OES_element_index_uint (fixes #20384)

This commit is contained in:
Anthony Ramine 2018-03-23 02:47:39 +01:00
parent 8061d8c3d2
commit 838d1305ca
6 changed files with 127 additions and 5 deletions

View file

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

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::OESElementIndexUintBinding;
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 OESElementIndexUint {
reflector_: Reflector,
}
impl OESElementIndexUint {
fn new_inherited() -> Self {
Self { reflector_: Reflector::new() }
}
}
impl WebGLExtension for OESElementIndexUint {
type Extension = Self;
fn new(ctx: &WebGLRenderingContext) -> DomRoot<Self> {
reflect_dom_object(
Box::new(OESElementIndexUint::new_inherited()),
&*ctx.global(),
OESElementIndexUintBinding::Wrap,
)
}
fn spec() -> WebGLExtensionSpec {
WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
}
fn is_supported(ext: &WebGLExtensions) -> bool {
ext.supports_gl_extension("GL_OES_element_index_uint")
}
fn enable(ext: &WebGLExtensions) {
ext.enable_element_index_uint();
}
fn name() -> &'static str {
"OES_element_index_uint"
}
}

View file

@ -57,17 +57,20 @@ struct WebGLExtensionFeatures {
hint_targets: FnvHashSet<GLenum>,
/// WebGL GetParameter() names enabled by extensions.
disabled_get_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) = match webgl_version {
let (disabled_tex_types, disabled_get_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())
DEFAULT_DISABLED_GET_PARAMETER_NAMES_WEBGL1.iter().cloned().collect(),
false)
},
WebGLVersion::WebGL2 => {
(Default::default(), Default::default())
(Default::default(), Default::default(), true)
}
};
Self {
@ -78,6 +81,7 @@ impl WebGLExtensionFeatures {
query_parameter_handlers: Default::default(),
hint_targets: Default::default(),
disabled_get_parameter_names,
element_index_uint_enabled,
}
}
}
@ -96,7 +100,7 @@ impl WebGLExtensions {
Self {
extensions: DomRefCell::new(HashMap::new()),
features: DomRefCell::new(WebGLExtensionFeatures::new(webgl_version)),
webgl_version
webgl_version,
}
}
@ -240,6 +244,14 @@ impl WebGLExtensions {
self.register::<ext::oestexturehalffloatlinear::OESTextureHalfFloatLinear>();
self.register::<ext::oesvertexarrayobject::OESVertexArrayObject>();
}
pub fn enable_element_index_uint(&self) {
self.features.borrow_mut().element_index_uint_enabled = true;
}
pub fn is_element_index_uint_enabled(&self) -> bool {
self.features.borrow().element_index_uint_enabled
}
}
// Helper structs