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 canvas_traits::gl_enums;
6use serde::{Deserialize, Serialize};
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        !matches!(*self, TexImageTarget::Texture2D)
28    }
29
30    pub(crate) fn dimensions(self) -> u8 {
31        match self {
32            TexImageTarget::Texture3D | TexImageTarget::Texture2DArray => 3,
33            _ => 2,
34        }
35    }
36}