Bug 1700051: part 26) Correct typo in comment of `mozInlineSpellWordUtil::BuildSoftTe...
[gecko.git] / dom / canvas / WebGLExtensionTextureHalfFloat.cpp
blob6e4d965ad70453c8adb48f3a6f7a1c609c1f4b62
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 file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "WebGLExtensions.h"
7 #include "GLContext.h"
8 #include "mozilla/dom/WebGLRenderingContextBinding.h"
9 #include "WebGLContext.h"
10 #include "WebGLFormats.h"
12 namespace mozilla {
14 WebGLExtensionTextureHalfFloat::WebGLExtensionTextureHalfFloat(
15 WebGLContext* webgl)
16 : WebGLExtensionBase(webgl) {
17 auto& fua = webgl->mFormatUsage;
18 gl::GLContext* gl = webgl->GL();
20 webgl::PackingInfo pi;
21 webgl::DriverUnpackInfo dui;
22 const GLint* swizzle = nullptr;
24 const auto fnAdd = [&](webgl::EffectiveFormat effFormat) {
25 MOZ_ASSERT_IF(swizzle, gl->IsSupported(gl::GLFeature::texture_swizzle));
27 auto usage = fua->EditUsage(effFormat);
28 usage->textureSwizzleRGBA = swizzle;
29 fua->AddTexUnpack(usage, pi, dui);
31 fua->AllowUnsizedTexFormat(pi, usage);
34 bool useSizedFormats = true;
35 const bool hasSizedLegacyFormats = gl->IsCompatibilityProfile();
36 if (gl->IsGLES() && gl->Version() < 300) {
37 useSizedFormats = false;
40 GLenum driverUnpackType = LOCAL_GL_HALF_FLOAT;
41 if (!gl->IsSupported(gl::GLFeature::texture_half_float)) {
42 MOZ_ASSERT(gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float));
43 driverUnpackType = LOCAL_GL_HALF_FLOAT_OES;
46 ////////////////
48 pi = {LOCAL_GL_RGBA, LOCAL_GL_HALF_FLOAT_OES};
49 dui = {pi.format, pi.format, driverUnpackType};
50 swizzle = nullptr;
51 if (useSizedFormats) {
52 dui.internalFormat = LOCAL_GL_RGBA16F;
54 fnAdd(webgl::EffectiveFormat::RGBA16F);
56 //////
58 pi = {LOCAL_GL_RGB, LOCAL_GL_HALF_FLOAT_OES};
59 dui = {pi.format, pi.format, driverUnpackType};
60 swizzle = nullptr;
61 if (useSizedFormats) {
62 dui.internalFormat = LOCAL_GL_RGB16F;
64 fnAdd(webgl::EffectiveFormat::RGB16F);
66 //////
68 pi = {LOCAL_GL_LUMINANCE, LOCAL_GL_HALF_FLOAT_OES};
69 dui = {pi.format, pi.format, driverUnpackType};
70 swizzle = nullptr;
71 if (useSizedFormats) {
72 if (hasSizedLegacyFormats) {
73 dui.internalFormat = LOCAL_GL_LUMINANCE16F_ARB;
74 } else {
75 dui.internalFormat = LOCAL_GL_R16F;
76 dui.unpackFormat = LOCAL_GL_RED;
77 swizzle = webgl::FormatUsageInfo::kLuminanceSwizzleRGBA;
80 fnAdd(webgl::EffectiveFormat::Luminance16F);
82 //////
84 pi = {LOCAL_GL_ALPHA, LOCAL_GL_HALF_FLOAT_OES};
85 dui = {pi.format, pi.format, driverUnpackType};
86 swizzle = nullptr;
87 if (useSizedFormats) {
88 if (hasSizedLegacyFormats) {
89 dui.internalFormat = LOCAL_GL_ALPHA16F_ARB;
90 } else {
91 dui.internalFormat = LOCAL_GL_R16F;
92 dui.unpackFormat = LOCAL_GL_RED;
93 swizzle = webgl::FormatUsageInfo::kAlphaSwizzleRGBA;
96 fnAdd(webgl::EffectiveFormat::Alpha16F);
98 //////
100 pi = {LOCAL_GL_LUMINANCE_ALPHA, LOCAL_GL_HALF_FLOAT_OES};
101 dui = {pi.format, pi.format, driverUnpackType};
102 swizzle = nullptr;
103 if (useSizedFormats) {
104 if (hasSizedLegacyFormats) {
105 dui.internalFormat = LOCAL_GL_LUMINANCE_ALPHA16F_ARB;
106 } else {
107 dui.internalFormat = LOCAL_GL_RG16F;
108 dui.unpackFormat = LOCAL_GL_RG;
109 swizzle = webgl::FormatUsageInfo::kLumAlphaSwizzleRGBA;
112 fnAdd(webgl::EffectiveFormat::Luminance16FAlpha16F);
115 bool WebGLExtensionTextureHalfFloat::IsSupported(const WebGLContext* webgl) {
116 if (webgl->IsWebGL2()) return false;
118 gl::GLContext* gl = webgl->GL();
119 if (!gl->IsSupported(gl::GLFeature::texture_half_float) &&
120 !gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float)) {
121 return false;
124 const bool needsSwizzle = gl->IsCoreProfile();
125 const bool hasSwizzle = gl->IsSupported(gl::GLFeature::texture_swizzle);
126 if (needsSwizzle && !hasSwizzle) return false;
128 return true;
131 } // namespace mozilla