Skip to main content

script/dom/webgl/extensions/ext/
oestexturehalffloat.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::{TexFormat, WebGLVersion};
8
9use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
10use crate::dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
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 OESTextureHalfFloat {
18    reflector_: Reflector,
19}
20
21impl OESTextureHalfFloat {
22    fn new_inherited() -> OESTextureHalfFloat {
23        Self {
24            reflector_: Reflector::new(),
25        }
26    }
27}
28
29impl WebGLExtension for OESTextureHalfFloat {
30    type Extension = OESTextureHalfFloat;
31    fn new(ctx: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<OESTextureHalfFloat> {
32        reflect_dom_object(
33            Box::new(OESTextureHalfFloat::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        ext.supports_any_gl_extension(&[
45            "GL_OES_texture_half_float",
46            "GL_ARB_half_float_pixel",
47            "GL_NV_half_float",
48            "GL_EXT_color_buffer_half_float",
49        ])
50    }
51
52    fn enable(ext: &WebGLExtensions) {
53        let hf = OESTextureHalfFloatConstants::HALF_FLOAT_OES;
54        ext.enable_tex_type(hf);
55        ext.add_effective_tex_internal_format(TexFormat::RGBA, hf, TexFormat::RGBA16f);
56        ext.add_effective_tex_internal_format(TexFormat::RGB, hf, TexFormat::RGB16f);
57        ext.add_effective_tex_internal_format(TexFormat::Luminance, hf, TexFormat::Luminance16f);
58        ext.add_effective_tex_internal_format(TexFormat::Alpha, hf, TexFormat::Alpha16f);
59        ext.add_effective_tex_internal_format(
60            TexFormat::LuminanceAlpha,
61            hf,
62            TexFormat::LuminanceAlpha16f,
63        );
64    }
65
66    fn name() -> &'static str {
67        "OES_texture_half_float"
68    }
69}