Skip to main content

script/dom/webgl/extensions/ext/
extcolorbufferfloat.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};
8use servo_canvas_traits::webgl::WebGLVersion;
9
10use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
11use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants;
12use crate::dom::bindings::reflector::DomGlobal;
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
15
16/// Float internal formats this extension makes color-renderable.
17pub(crate) const COLOR_RENDERABLE_FORMATS: &[u32] = &[
18    constants::R16F,
19    constants::RG16F,
20    constants::RGBA16F,
21    constants::R32F,
22    constants::RG32F,
23    constants::RGBA32F,
24    constants::R11F_G11F_B10F,
25];
26
27#[dom_struct]
28pub(crate) struct EXTColorBufferFloat {
29    reflector_: Reflector,
30}
31
32impl EXTColorBufferFloat {
33    fn new_inherited() -> EXTColorBufferFloat {
34        Self {
35            reflector_: Reflector::new(),
36        }
37    }
38}
39
40impl WebGLExtension for EXTColorBufferFloat {
41    type Extension = EXTColorBufferFloat;
42    fn new(cx: &mut JSContext, ctx: &WebGLRenderingContext) -> DomRoot<EXTColorBufferFloat> {
43        reflect_dom_object(cx, Box::new(Self::new_inherited()), &*ctx.global())
44    }
45
46    fn spec() -> WebGLExtensionSpec {
47        WebGLExtensionSpec::Specific(WebGLVersion::WebGL2)
48    }
49
50    fn is_supported(ext: &WebGLExtensions) -> bool {
51        // Core in desktop GL 3.0; GLES needs the extension.
52        !ext.is_gles() || ext.supports_gl_extension("GL_EXT_color_buffer_float")
53    }
54
55    fn enable(_ext: &WebGLExtensions) {}
56
57    fn name() -> &'static str {
58        "EXT_color_buffer_float"
59    }
60}