script/dom/webxr/
xrwebglsubimage.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 euclid::Size2D;
7use webxr_api::Viewport;
8
9use crate::dom::bindings::codegen::Bindings::XRWebGLSubImageBinding::XRWebGLSubImage_Binding::XRWebGLSubImageMethods;
10use crate::dom::bindings::root::{Dom, DomRoot};
11use crate::dom::webgl::webgltexture::WebGLTexture;
12use crate::dom::xrsubimage::XRSubImage;
13
14#[dom_struct]
15pub(crate) struct XRWebGLSubImage {
16    xr_sub_image: XRSubImage,
17    color_texture: Dom<WebGLTexture>,
18    depth_stencil_texture: Option<Dom<WebGLTexture>>,
19    image_index: Option<u32>,
20    #[no_trace]
21    size: Size2D<u32, Viewport>,
22}
23
24impl XRWebGLSubImageMethods<crate::DomTypeHolder> for XRWebGLSubImage {
25    /// <https://immersive-web.github.io/layers/#dom-xrwebglsubimage-colortexture>
26    fn ColorTexture(&self) -> DomRoot<WebGLTexture> {
27        DomRoot::from_ref(&self.color_texture)
28    }
29
30    /// <https://immersive-web.github.io/layers/#dom-xrwebglsubimage-depthstenciltexture>
31    fn GetDepthStencilTexture(&self) -> Option<DomRoot<WebGLTexture>> {
32        self.depth_stencil_texture.as_deref().map(DomRoot::from_ref)
33    }
34
35    /// <https://immersive-web.github.io/layers/#dom-xrwebglsubimage-imageindex>
36    fn GetImageIndex(&self) -> Option<u32> {
37        self.image_index
38    }
39
40    /// <https://immersive-web.github.io/layers/#dom-xrwebglsubimage-texturewidth>
41    fn TextureWidth(&self) -> u32 {
42        self.size.width
43    }
44
45    /// <https://immersive-web.github.io/layers/#dom-xrwebglsubimage-textureheight>
46    fn TextureHeight(&self) -> u32 {
47        self.size.height
48    }
49}