1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use canvas_traits::gl_enums;
use serde::{Deserialize, Serialize};

use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants;

gl_enums! {
    pub enum TexImageTarget {
        Texture2D = constants::TEXTURE_2D,
        Texture2DArray = constants::TEXTURE_2D_ARRAY,
        Texture3D = constants::TEXTURE_3D,
        CubeMap = constants::TEXTURE_CUBE_MAP,
        CubeMapPositiveX = constants::TEXTURE_CUBE_MAP_POSITIVE_X,
        CubeMapNegativeX = constants::TEXTURE_CUBE_MAP_NEGATIVE_X,
        CubeMapPositiveY = constants::TEXTURE_CUBE_MAP_POSITIVE_Y,
        CubeMapNegativeY = constants::TEXTURE_CUBE_MAP_NEGATIVE_Y,
        CubeMapPositiveZ = constants::TEXTURE_CUBE_MAP_POSITIVE_Z,
        CubeMapNegativeZ = constants::TEXTURE_CUBE_MAP_NEGATIVE_Z,
    }
}

impl TexImageTarget {
    pub fn is_cubic(&self) -> bool {
        match *self {
            TexImageTarget::Texture2D => false,
            _ => true,
        }
    }

    pub fn dimensions(self) -> u8 {
        match self {
            TexImageTarget::Texture3D | TexImageTarget::Texture2DArray => 3,
            _ => 2,
        }
    }
}