Skip to main content

script/dom/webgl/extensions/ext/
oesstandardderivatives.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::WebGLVersion;
8
9use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
10use crate::dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
11use crate::dom::bindings::reflector::DomGlobal;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
14use crate::script_runtime::CanGc;
15
16#[dom_struct]
17pub(crate) struct OESStandardDerivatives {
18    reflector_: Reflector,
19}
20
21impl OESStandardDerivatives {
22    fn new_inherited() -> OESStandardDerivatives {
23        Self {
24            reflector_: Reflector::new(),
25        }
26    }
27}
28
29impl WebGLExtension for OESStandardDerivatives {
30    type Extension = OESStandardDerivatives;
31    fn new(ctx: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<OESStandardDerivatives> {
32        reflect_dom_object(
33            Box::new(OESStandardDerivatives::new_inherited()),
34            &*ctx.global(),
35            can_gc,
36        )
37    }
38
39    fn spec() -> WebGLExtensionSpec {
40        WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
41    }
42
43    fn is_supported(ext: &WebGLExtensions) -> bool {
44        // The standard derivatives are always available in desktop OpenGL.
45        !ext.is_gles() || ext.supports_any_gl_extension(&["GL_OES_standard_derivatives"])
46    }
47
48    fn enable(ext: &WebGLExtensions) {
49        ext.enable_hint_target(
50            OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES,
51        );
52        ext.enable_get_parameter_name(
53            OESStandardDerivativesConstants::FRAGMENT_SHADER_DERIVATIVE_HINT_OES,
54        );
55    }
56
57    fn name() -> &'static str {
58        "OES_standard_derivatives"
59    }
60}