Skip to main content

script/dom/webgl/extensions/ext/
webglcompressedtextures3tc.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 WEBGLCompressedTextureS3TC {
18    reflector_: Reflector,
19}
20
21impl WEBGLCompressedTextureS3TC {
22    fn new_inherited() -> WEBGLCompressedTextureS3TC {
23        Self {
24            reflector_: Reflector::new(),
25        }
26    }
27}
28
29impl WebGLExtension for WEBGLCompressedTextureS3TC {
30    type Extension = WEBGLCompressedTextureS3TC;
31    fn new(ctx: &WebGLRenderingContext, can_gc: CanGc) -> DomRoot<WEBGLCompressedTextureS3TC> {
32        reflect_dom_object(
33            Box::new(WEBGLCompressedTextureS3TC::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_EXT_texture_compression_s3tc") ||
45            ext.supports_all_gl_extension(&[
46                "GL_EXT_texture_compression_dxt1",
47                "GL_ANGLE_texture_compression_dxt3",
48                "GL_ANGLE_texture_compression_dxt5",
49            ])
50    }
51
52    fn enable(ext: &WebGLExtensions) {
53        ext.add_tex_compression_formats(&[
54            TexCompression {
55                format: TexFormat::CompressedRgbS3tcDxt1,
56                bytes_per_block: 8,
57                block_width: 4,
58                block_height: 4,
59                validation: TexCompressionValidation::S3TC,
60            },
61            TexCompression {
62                format: TexFormat::CompressedRgbaS3tcDxt1,
63                bytes_per_block: 8,
64                block_width: 4,
65                block_height: 4,
66                validation: TexCompressionValidation::S3TC,
67            },
68            TexCompression {
69                format: TexFormat::CompressedRgbaS3tcDxt3,
70                bytes_per_block: 16,
71                block_width: 4,
72                block_height: 4,
73                validation: TexCompressionValidation::S3TC,
74            },
75            TexCompression {
76                format: TexFormat::CompressedRgbaS3tcDxt5,
77                bytes_per_block: 16,
78                block_width: 4,
79                block_height: 4,
80                validation: TexCompressionValidation::S3TC,
81            },
82        ]);
83    }
84
85    fn name() -> &'static str {
86        "WEBGL_compressed_texture_s3tc"
87    }
88}