script/dom/webgl/extensions/ext/
webglcompressedtextureetc1.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::webgl::{TexFormat, WebGLVersion};
6use dom_struct::dom_struct;
7
8use super::{WebGLExtension, WebGLExtensionSpec, WebGLExtensions};
9use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::webgl::webglrenderingcontext::WebGLRenderingContext;
12use crate::dom::webgl::webgltexture::{TexCompression, TexCompressionValidation};
13use crate::script_runtime::CanGc;
14
15#[dom_struct]
16pub(crate) struct WEBGLCompressedTextureETC1 {
17    reflector_: Reflector,
18}
19
20impl WEBGLCompressedTextureETC1 {
21    fn new_inherited() -> WEBGLCompressedTextureETC1 {
22        Self {
23            reflector_: Reflector::new(),
24        }
25    }
26}
27
28impl WebGLExtension for WEBGLCompressedTextureETC1 {
29    type Extension = WEBGLCompressedTextureETC1;
30    fn new(ctx: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<WEBGLCompressedTextureETC1> {
31        reflect_dom_object(
32            Box::new(WEBGLCompressedTextureETC1::new_inherited()),
33            &*ctx.global(),
34            can_gc,
35        )
36    }
37
38    fn spec() -> WebGLExtensionSpec {
39        WebGLExtensionSpec::Specific(WebGLVersion::WebGL1)
40    }
41
42    fn is_supported(ext: &WebGLExtensions) -> bool {
43        ext.supports_gl_extension("GL_OES_compressed_ETC1_RGB8_texture")
44    }
45
46    fn enable(ext: &WebGLExtensions) {
47        ext.add_tex_compression_formats(&[TexCompression {
48            format: TexFormat::CompressedRgbEtc1,
49            bytes_per_block: 8,
50            block_width: 4,
51            block_height: 4,
52            validation: TexCompressionValidation::None,
53        }]);
54    }
55
56    fn name() -> &'static str {
57        "WEBGL_compressed_texture_etc1"
58    }
59}