Skip to main content

script/dom/webgl/validations/
types.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 serde::{Deserialize, Serialize};
6use servo_canvas_traits::gl_enums;
7
8use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants;
9
10gl_enums! {
11    pub enum TexImageTarget {
12        Texture2D = constants::TEXTURE_2D,
13        Texture2DArray = constants::TEXTURE_2D_ARRAY,
14        Texture3D = constants::TEXTURE_3D,
15        CubeMap = constants::TEXTURE_CUBE_MAP,
16        CubeMapPositiveX = constants::TEXTURE_CUBE_MAP_POSITIVE_X,
17        CubeMapNegativeX = constants::TEXTURE_CUBE_MAP_NEGATIVE_X,
18        CubeMapPositiveY = constants::TEXTURE_CUBE_MAP_POSITIVE_Y,
19        CubeMapNegativeY = constants::TEXTURE_CUBE_MAP_NEGATIVE_Y,
20        CubeMapPositiveZ = constants::TEXTURE_CUBE_MAP_POSITIVE_Z,
21        CubeMapNegativeZ = constants::TEXTURE_CUBE_MAP_NEGATIVE_Z,
22    }
23}
24
25impl TexImageTarget {
26    pub(crate) fn is_cubic(&self) -> bool {
27        match self {
28            TexImageTarget::CubeMap |
29            TexImageTarget::CubeMapPositiveX |
30            TexImageTarget::CubeMapNegativeX |
31            TexImageTarget::CubeMapPositiveY |
32            TexImageTarget::CubeMapNegativeY |
33            TexImageTarget::CubeMapPositiveZ |
34            TexImageTarget::CubeMapNegativeZ => true,
35            TexImageTarget::Texture2D |
36            TexImageTarget::Texture2DArray |
37            TexImageTarget::Texture3D => false,
38        }
39    }
40
41    pub(crate) fn dimensions(self) -> u8 {
42        match self {
43            TexImageTarget::Texture3D | TexImageTarget::Texture2DArray => 3,
44            _ => 2,
45        }
46    }
47}