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