script/dom/webgl/extensions/ext/
extfragdepth.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use canvas_traits::webgl::{WebGLSLVersion, WebGLVersion};
6use dom_struct::dom_struct;
7
8use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
9use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
12use crate::script_runtime::CanGc;
13
14#[dom_struct]
15pub(crate) struct EXTFragDepth {
16    reflector_: Reflector,
17}
18
19impl EXTFragDepth {
20    fn new_inherited() -> EXTFragDepth {
21        Self {
22            reflector_: Reflector::new(),
23        }
24    }
25}
26
27impl WebGLExtension for EXTFragDepth {
28    type Extension = Self;
29
30    fn new(ctx: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<Self> {
31        reflect_dom_object(Box::new(Self::new_inherited()), &*ctx.global(), can_gc)
32    }
33
34    fn spec() -> WebGLExtensionSpec {
35        WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
36    }
37
38    fn is_supported(ext: &WebGLExtensions) -> bool {
39        let min_glsl_version = if ext.is_gles() {
40            WebGLSLVersion { major: 3, minor: 0 }
41        } else {
42            WebGLSLVersion {
43                major: 1,
44                minor: 10,
45            }
46        };
47        match (
48            ext.is_gles(),
49            ext.is_min_glsl_version_satisfied(min_glsl_version),
50        ) {
51            // ANGLE's shader translator can't translate ESSL1 exts to ESSL3. (bug
52            // 1524804)
53            (true, true) => false,
54            (true, false) => ext.supports_gl_extension("GL_EXT_frag_depth"),
55            (false, is_min_glsl_version_satisfied) => is_min_glsl_version_satisfied,
56        }
57    }
58
59    fn enable(_ext: &WebGLExtensions) {}
60
61    fn name() -> &'static str {
62        "EXT_frag_depth"
63    }
64}