Skip to main content

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 dom_struct::dom_struct;
6use script_bindings::reflector::{Reflector, reflect_dom_object};
7use servo_canvas_traits::webgl::{WebGLSLVersion, WebGLVersion};
8
9use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
10use crate::dom::bindings::reflector::DomGlobal;
11use crate::dom::bindings::root::DomRoot;
12use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
13use crate::script_runtime::CanGc;
14
15#[dom_struct]
16pub(crate) struct EXTFragDepth {
17    reflector_: Reflector,
18}
19
20impl EXTFragDepth {
21    fn new_inherited() -> EXTFragDepth {
22        Self {
23            reflector_: Reflector::new(),
24        }
25    }
26}
27
28impl WebGLExtension for EXTFragDepth {
29    type Extension = Self;
30
31    fn new(ctx: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<Self> {
32        reflect_dom_object(Box::new(Self::new_inherited()), &*ctx.global(), can_gc)
33    }
34
35    fn spec() -> WebGLExtensionSpec {
36        WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
37    }
38
39    fn is_supported(ext: &WebGLExtensions) -> bool {
40        let min_glsl_version = if ext.is_gles() {
41            WebGLSLVersion { major: 3, minor: 0 }
42        } else {
43            WebGLSLVersion {
44                major: 1,
45                minor: 10,
46            }
47        };
48        match (
49            ext.is_gles(),
50            ext.is_min_glsl_version_satisfied(min_glsl_version),
51        ) {
52            // ANGLE's shader translator can't translate ESSL1 exts to ESSL3. (bug
53            // 1524804)
54            (true, true) => false,
55            (true, false) => ext.supports_gl_extension("GL_EXT_frag_depth"),
56            (false, is_min_glsl_version_satisfied) => is_min_glsl_version_satisfied,
57        }
58    }
59
60    fn enable(_ext: &WebGLExtensions) {}
61
62    fn name() -> &'static str {
63        "EXT_frag_depth"
64    }
65}