Bug 1700051: part 26) Correct typo in comment of `mozInlineSpellWordUtil::BuildSoftTe...
[gecko.git] / dom / canvas / WebGLExtensions.cpp
blob0528f4f8b0206191205dc19d50e2da63e8338468
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGLExtensions.h"
8 #include "GLContext.h"
9 #include "mozilla/dom/WebGLRenderingContextBinding.h"
10 #include "mozilla/StaticPrefs_webgl.h"
11 #include "WebGLContext.h"
13 namespace mozilla {
15 WebGLExtensionBlendMinMax::WebGLExtensionBlendMinMax(WebGLContext* webgl)
16 : WebGLExtensionBase(webgl) {
17 MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
20 bool WebGLExtensionBlendMinMax::IsSupported(const WebGLContext* webgl) {
21 if (webgl->IsWebGL2()) return false;
23 return webgl->GL()->IsSupported(gl::GLFeature::blend_minmax);
26 // -
28 WebGLExtensionExplicitPresent::WebGLExtensionExplicitPresent(
29 WebGLContext* const webgl)
30 : WebGLExtensionBase(webgl) {
31 if (!IsSupported(webgl)) {
32 NS_WARNING(
33 "Constructing WebGLExtensionExplicitPresent but IsSupported() is "
34 "false!");
35 // This was previously an assert, but it seems like we get races against
36 // StaticPrefs changes/initialization?
40 bool WebGLExtensionExplicitPresent::IsSupported(
41 const WebGLContext* const webgl) {
42 return StaticPrefs::webgl_enable_draft_extensions();
45 // -
47 WebGLExtensionFloatBlend::WebGLExtensionFloatBlend(WebGLContext* const webgl)
48 : WebGLExtensionBase(webgl) {
49 MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
52 bool WebGLExtensionFloatBlend::IsSupported(const WebGLContext* const webgl) {
53 if (!WebGLExtensionColorBufferFloat::IsSupported(webgl) &&
54 !WebGLExtensionEXTColorBufferFloat::IsSupported(webgl))
55 return false;
57 const auto& gl = webgl->gl;
58 if (!gl->IsGLES() && gl->Version() >= 300) return true;
59 if (gl->IsGLES() && gl->Version() >= 320) return true;
60 return gl->IsExtensionSupported(gl::GLContext::EXT_float_blend);
63 // -
65 WebGLExtensionFBORenderMipmap::WebGLExtensionFBORenderMipmap(
66 WebGLContext* const webgl)
67 : WebGLExtensionBase(webgl) {
68 MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
71 bool WebGLExtensionFBORenderMipmap::IsSupported(
72 const WebGLContext* const webgl) {
73 if (webgl->IsWebGL2()) return false;
75 const auto& gl = webgl->gl;
76 if (!gl->IsGLES()) return true;
77 if (gl->Version() >= 300) return true;
78 return gl->IsExtensionSupported(gl::GLContext::OES_fbo_render_mipmap);
81 // -
83 WebGLExtensionMultiview::WebGLExtensionMultiview(WebGLContext* const webgl)
84 : WebGLExtensionBase(webgl) {
85 MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
88 bool WebGLExtensionMultiview::IsSupported(const WebGLContext* const webgl) {
89 if (!webgl->IsWebGL2()) return false;
91 const auto& gl = webgl->gl;
92 return gl->IsSupported(gl::GLFeature::multiview);
95 // -
97 bool WebGLExtensionTextureNorm16::IsSupported(const WebGLContext* const webgl) {
98 if (!StaticPrefs::webgl_enable_draft_extensions()) return false;
99 if (!webgl->IsWebGL2()) return false;
101 const auto& gl = webgl->gl;
103 // ANGLE's support is broken in our checkout.
104 if (gl->IsANGLE()) return false;
106 return gl->IsSupported(gl::GLFeature::texture_norm16);
109 WebGLExtensionTextureNorm16::WebGLExtensionTextureNorm16(WebGLContext* webgl)
110 : WebGLExtensionBase(webgl) {
111 if (!IsSupported(webgl)) {
112 NS_WARNING(
113 "Constructing WebGLExtensionTextureNorm16 but IsSupported() is "
114 "false!");
115 // This was previously an assert, but it seems like we get races against
116 // StaticPrefs changes/initialization?
119 auto& fua = *webgl->mFormatUsage;
121 const auto fnAdd = [&](webgl::EffectiveFormat effFormat,
122 const bool renderable, const webgl::PackingInfo& pi) {
123 auto& usage = *fua.EditUsage(effFormat);
124 const auto& format = *usage.format;
126 const auto dui =
127 webgl::DriverUnpackInfo{format.sizedFormat, pi.format, pi.type};
128 fua.AddTexUnpack(&usage, pi, dui);
130 fua.AllowSizedTexFormat(format.sizedFormat, &usage);
131 fua.AllowUnsizedTexFormat(pi, &usage);
133 if (renderable) {
134 usage.SetRenderable();
135 fua.AllowRBFormat(format.sizedFormat, &usage);
139 fnAdd(webgl::EffectiveFormat::R16, true,
140 {LOCAL_GL_RED, LOCAL_GL_UNSIGNED_SHORT});
141 fnAdd(webgl::EffectiveFormat::RG16, true,
142 {LOCAL_GL_RG, LOCAL_GL_UNSIGNED_SHORT});
143 fnAdd(webgl::EffectiveFormat::RGB16, false,
144 {LOCAL_GL_RGB, LOCAL_GL_UNSIGNED_SHORT});
145 fnAdd(webgl::EffectiveFormat::RGBA16, true,
146 {LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_SHORT});
148 fnAdd(webgl::EffectiveFormat::R16_SNORM, false,
149 {LOCAL_GL_RED, LOCAL_GL_SHORT});
150 fnAdd(webgl::EffectiveFormat::RG16_SNORM, false,
151 {LOCAL_GL_RG, LOCAL_GL_SHORT});
152 fnAdd(webgl::EffectiveFormat::RGB16_SNORM, false,
153 {LOCAL_GL_RGB, LOCAL_GL_SHORT});
154 fnAdd(webgl::EffectiveFormat::RGBA16_SNORM, false,
155 {LOCAL_GL_RGBA, LOCAL_GL_SHORT});
158 } // namespace mozilla