Skip to main content

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