script/dom/webgl/extensions/ext/
oestexturefloat.rs1use 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, constants as webgl};
11use crate::dom::bindings::reflector::DomGlobal;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
14
15#[dom_struct]
16pub(crate) struct OESTextureFloat {
17 reflector_: Reflector,
18}
19
20impl OESTextureFloat {
21 fn new_inherited() -> OESTextureFloat {
22 Self {
23 reflector_: Reflector::new(),
24 }
25 }
26}
27
28impl WebGLExtension for OESTextureFloat {
29 type Extension = OESTextureFloat;
30 fn new(cx: &mut JSContext, ctx: &WebGLRenderingContext) -> DomRoot<OESTextureFloat> {
31 reflect_dom_object_with_cx(Box::new(Self::new_inherited()), &*ctx.global(), cx)
32 }
33
34 fn spec() -> WebGLExtensionSpec {
35 WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
36 }
37
38 fn is_supported(ext: &WebGLExtensions) -> bool {
39 ext.supports_any_gl_extension(&[
40 "GL_OES_texture_float",
41 "GL_ARB_texture_float",
42 "GL_EXT_color_buffer_float",
43 ])
44 }
45
46 fn enable(ext: &WebGLExtensions) {
47 ext.enable_tex_type(webgl::FLOAT);
48 ext.add_effective_tex_internal_format(TexFormat::RGBA, webgl::FLOAT, TexFormat::RGBA32f);
49 ext.add_effective_tex_internal_format(TexFormat::RGB, webgl::FLOAT, TexFormat::RGB32f);
50 ext.add_effective_tex_internal_format(
51 TexFormat::Luminance,
52 webgl::FLOAT,
53 TexFormat::Luminance32f,
54 );
55 ext.add_effective_tex_internal_format(TexFormat::Alpha, webgl::FLOAT, TexFormat::Alpha32f);
56 ext.add_effective_tex_internal_format(
57 TexFormat::LuminanceAlpha,
58 webgl::FLOAT,
59 TexFormat::LuminanceAlpha32f,
60 );
61 }
62
63 fn name() -> &'static str {
64 "OES_texture_float"
65 }
66}