blob: 6eaca1f2a025176da453b500128a36f1136b815d [file] [log] [blame]
commit-queue@webkit.org6128e132018-05-09 20:24:23 +00001/*
2 * Copyright (C) 2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "WebGLCompressedTextureASTC.h"
28
29#if ENABLE(WEBGL)
30
dino@apple.com92f99162020-01-06 18:52:42 +000031#include "ExtensionsGL.h"
commit-queue@webkit.org6128e132018-05-09 20:24:23 +000032#include "RuntimeEnabledFeatures.h"
33#include "WebGLRenderingContextBase.h"
aperez@igalia.come2a465d2020-09-16 15:09:28 +000034#include <wtf/IsoMallocInlines.h>
commit-queue@webkit.org6128e132018-05-09 20:24:23 +000035
36namespace WebCore {
dino@apple.combcd2bd42020-09-10 02:47:05 +000037
38WTF_MAKE_ISO_ALLOCATED_IMPL(WebGLCompressedTextureASTC);
39
commit-queue@webkit.org6128e132018-05-09 20:24:23 +000040WebGLCompressedTextureASTC::WebGLCompressedTextureASTC(WebGLRenderingContextBase& context)
41 : WebGLExtension(context)
dino@apple.com92f99162020-01-06 18:52:42 +000042 , m_isHDRSupported(context.graphicsContextGL()->getExtensions().supports("GL_KHR_texture_compression_astc_hdr"_s))
43 , m_isLDRSupported(context.graphicsContextGL()->getExtensions().supports("GL_KHR_texture_compression_astc_ldr"_s))
commit-queue@webkit.org6128e132018-05-09 20:24:23 +000044{
dino@apple.com92f99162020-01-06 18:52:42 +000045 context.graphicsContextGL()->getExtensions().ensureEnabled("GL_KHR_texture_compression_astc_hdr"_s);
46 context.graphicsContextGL()->getExtensions().ensureEnabled("GL_KHR_texture_compression_astc_ldr"_s);
commit-queue@webkit.org885f3982019-08-28 20:34:19 +000047
dino@apple.com92f99162020-01-06 18:52:42 +000048 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_4x4_KHR);
49 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_5x4_KHR);
50 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_5x5_KHR);
51 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_6x5_KHR);
52 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_6x6_KHR);
53 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_8x5_KHR);
54 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_8x6_KHR);
55 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_8x8_KHR);
56 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_10x5_KHR);
57 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_10x6_KHR);
58 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_10x8_KHR);
59 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_10x10_KHR);
60 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_12x10_KHR);
61 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_RGBA_ASTC_12x12_KHR);
commit-queue@webkit.org6128e132018-05-09 20:24:23 +000062
dino@apple.com92f99162020-01-06 18:52:42 +000063 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR);
64 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR);
65 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR);
66 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR);
67 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR);
68 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR);
69 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR);
70 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR);
71 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR);
72 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR);
73 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR);
74 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR);
75 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR);
76 context.addCompressedTextureFormat(ExtensionsGL::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR);
commit-queue@webkit.org6128e132018-05-09 20:24:23 +000077}
78
79WebGLCompressedTextureASTC::~WebGLCompressedTextureASTC() = default;
80
81WebGLExtension::ExtensionName WebGLCompressedTextureASTC::getName() const
82{
83 return WebGLCompressedTextureASTCName;
84}
85
86Vector<String> WebGLCompressedTextureASTC::getSupportedProfiles()
87{
88 Vector<String> result;
89
90 if (m_isHDRSupported)
utatane.tea@gmail.com84077632018-06-23 08:39:34 +000091 result.append("hdr"_s);
commit-queue@webkit.org6128e132018-05-09 20:24:23 +000092 if (m_isLDRSupported)
utatane.tea@gmail.com84077632018-06-23 08:39:34 +000093 result.append("ldr"_s);
commit-queue@webkit.org6128e132018-05-09 20:24:23 +000094
95 return result;
96}
97
98bool WebGLCompressedTextureASTC::supported(const WebGLRenderingContextBase& context)
99{
dino@apple.com92f99162020-01-06 18:52:42 +0000100 return context.graphicsContextGL()->getExtensions().supports("GL_KHR_texture_compression_astc_hdr"_s)
101 || context.graphicsContextGL()->getExtensions().supports("GL_KHR_texture_compression_astc_ldr"_s);
commit-queue@webkit.org6128e132018-05-09 20:24:23 +0000102}
103
104} // namespace WebCore
105
106#endif // ENABLE(WEBGL)