Line data Source code
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/. */
4 :
5 : #include "WebGLExtensions.h"
6 :
7 : #include "GLContext.h"
8 : #include "mozilla/dom/WebGLRenderingContextBinding.h"
9 : #include "WebGLContext.h"
10 : #include "WebGLFormats.h"
11 :
12 : namespace mozilla {
13 :
14 0 : WebGLExtensionTextureHalfFloat::WebGLExtensionTextureHalfFloat(WebGLContext* webgl)
15 0 : : WebGLExtensionBase(webgl)
16 : {
17 0 : auto& fua = webgl->mFormatUsage;
18 0 : gl::GLContext* gl = webgl->GL();
19 :
20 : webgl::PackingInfo pi;
21 : webgl::DriverUnpackInfo dui;
22 0 : const GLint* swizzle = nullptr;
23 :
24 0 : const auto fnAdd = [&fua, &pi, &dui, &swizzle](webgl::EffectiveFormat effFormat)
25 0 : {
26 0 : auto usage = fua->EditUsage(effFormat);
27 0 : usage->textureSwizzleRGBA = swizzle;
28 0 : fua->AddTexUnpack(usage, pi, dui);
29 :
30 0 : fua->AllowUnsizedTexFormat(pi, usage);
31 0 : };
32 :
33 0 : const bool needsSwizzle = gl->IsCoreProfile();
34 0 : MOZ_ASSERT_IF(needsSwizzle, gl->IsSupported(gl::GLFeature::texture_swizzle));
35 :
36 0 : const bool needsSizedFormat = !gl->IsGLES();
37 :
38 0 : GLenum driverUnpackType = LOCAL_GL_HALF_FLOAT;
39 0 : if (!gl->IsSupported(gl::GLFeature::texture_half_float)) {
40 0 : MOZ_ASSERT(gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float));
41 0 : driverUnpackType = LOCAL_GL_HALF_FLOAT_OES;
42 : }
43 :
44 : ////////////////
45 :
46 0 : pi = {LOCAL_GL_RGBA, LOCAL_GL_HALF_FLOAT_OES};
47 0 : dui = {pi.format, pi.format, driverUnpackType};
48 0 : swizzle = nullptr;
49 0 : if (needsSizedFormat) {
50 0 : dui.internalFormat = LOCAL_GL_RGBA16F;
51 : }
52 0 : fnAdd(webgl::EffectiveFormat::RGBA16F);
53 :
54 : //////
55 :
56 0 : pi = {LOCAL_GL_RGB, LOCAL_GL_HALF_FLOAT_OES};
57 0 : dui = {pi.format, pi.format, driverUnpackType};
58 0 : swizzle = nullptr;
59 0 : if (needsSizedFormat) {
60 0 : dui.internalFormat = LOCAL_GL_RGB16F;
61 : }
62 0 : fnAdd(webgl::EffectiveFormat::RGB16F);
63 :
64 : //////
65 :
66 0 : pi = {LOCAL_GL_LUMINANCE, LOCAL_GL_HALF_FLOAT_OES};
67 0 : dui = {pi.format, pi.format, driverUnpackType};
68 0 : swizzle = nullptr;
69 0 : if (needsSwizzle) {
70 0 : dui = {LOCAL_GL_R16F, LOCAL_GL_RED, driverUnpackType};
71 0 : swizzle = webgl::FormatUsageInfo::kLuminanceSwizzleRGBA;
72 0 : } else if (needsSizedFormat) {
73 0 : dui.internalFormat = LOCAL_GL_LUMINANCE16F_ARB;
74 : }
75 0 : fnAdd(webgl::EffectiveFormat::Luminance16F);
76 :
77 : //////
78 :
79 0 : pi = {LOCAL_GL_ALPHA, LOCAL_GL_HALF_FLOAT_OES};
80 0 : dui = {pi.format, pi.format, driverUnpackType};
81 0 : swizzle = nullptr;
82 0 : if (needsSwizzle) {
83 0 : dui = {LOCAL_GL_R16F, LOCAL_GL_RED, driverUnpackType};
84 0 : swizzle = webgl::FormatUsageInfo::kAlphaSwizzleRGBA;
85 0 : } else if (needsSizedFormat) {
86 0 : dui.internalFormat = LOCAL_GL_ALPHA16F_ARB;
87 : }
88 0 : fnAdd(webgl::EffectiveFormat::Alpha16F);
89 :
90 : //////
91 :
92 0 : pi = {LOCAL_GL_LUMINANCE_ALPHA, LOCAL_GL_HALF_FLOAT_OES};
93 0 : dui = {pi.format, pi.format, driverUnpackType};
94 0 : swizzle = nullptr;
95 0 : if (needsSwizzle) {
96 0 : dui = {LOCAL_GL_RG16F, LOCAL_GL_RG, driverUnpackType};
97 0 : swizzle = webgl::FormatUsageInfo::kLumAlphaSwizzleRGBA;
98 0 : } else if (needsSizedFormat) {
99 0 : dui.internalFormat = LOCAL_GL_LUMINANCE_ALPHA16F_ARB;
100 : }
101 0 : fnAdd(webgl::EffectiveFormat::Luminance16FAlpha16F);
102 0 : }
103 :
104 0 : WebGLExtensionTextureHalfFloat::~WebGLExtensionTextureHalfFloat()
105 : {
106 0 : }
107 :
108 : bool
109 0 : WebGLExtensionTextureHalfFloat::IsSupported(const WebGLContext* webgl)
110 : {
111 0 : gl::GLContext* gl = webgl->GL();
112 :
113 0 : if (!gl->IsSupported(gl::GLFeature::texture_half_float) &&
114 0 : !gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float))
115 : {
116 0 : return false;
117 : }
118 :
119 0 : const bool needsSwizzle = gl->IsCoreProfile();
120 0 : const bool hasSwizzle = gl->IsSupported(gl::GLFeature::texture_swizzle);
121 0 : if (needsSwizzle && !hasSwizzle)
122 0 : return false;
123 :
124 0 : return true;
125 : }
126 :
127 0 : IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureHalfFloat, OES_texture_half_float)
128 :
129 : } // namespace mozilla
|