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