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 js::context::JSContext;
7use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
8use servo_canvas_traits::webgl::{TexFormat, WebGLVersion};
9
10use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
11use crate::dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
12use crate::dom::bindings::reflector::DomGlobal;
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
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(cx: &mut JSContext, ctx: &WebGLRenderingContext) -> DomRoot<OESTextureHalfFloat> {
32        reflect_dom_object_with_cx(Box::new(Self::new_inherited()), &*ctx.global(), cx)
33    }
34
35    fn spec() -> WebGLExtensionSpec {
36        WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
37    }
38
39    fn is_supported(ext: &WebGLExtensions) -> bool {
40        ext.supports_any_gl_extension(&[
41            "GL_OES_texture_half_float",
42            "GL_ARB_half_float_pixel",
43            "GL_NV_half_float",
44            "GL_EXT_color_buffer_half_float",
45        ])
46    }
47
48    fn enable(ext: &WebGLExtensions) {
49        let hf = OESTextureHalfFloatConstants::HALF_FLOAT_OES;
50        ext.enable_tex_type(hf);
51        ext.add_effective_tex_internal_format(TexFormat::RGBA, hf, TexFormat::RGBA16f);
52        ext.add_effective_tex_internal_format(TexFormat::RGB, hf, TexFormat::RGB16f);
53        ext.add_effective_tex_internal_format(TexFormat::Luminance, hf, TexFormat::Luminance16f);
54        ext.add_effective_tex_internal_format(TexFormat::Alpha, hf, TexFormat::Alpha16f);
55        ext.add_effective_tex_internal_format(
56            TexFormat::LuminanceAlpha,
57            hf,
58            TexFormat::LuminanceAlpha16f,
59        );
60    }
61
62    fn name() -> &'static str {
63        "OES_texture_half_float"
64    }
65}