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 : WebGLExtensionTextureFloat::WebGLExtensionTextureFloat(WebGLContext* webgl)
15 0 : : WebGLExtensionBase(webgl)
16 : {
17 0 : MOZ_ASSERT(IsSupported(webgl));
18 :
19 0 : auto& fua = webgl->mFormatUsage;
20 0 : gl::GLContext* gl = webgl->GL();
21 :
22 : webgl::PackingInfo pi;
23 : webgl::DriverUnpackInfo dui;
24 0 : const GLint* swizzle = nullptr;
25 :
26 0 : const auto fnAdd = [&fua, &pi, &dui, &swizzle](webgl::EffectiveFormat effFormat)
27 0 : {
28 0 : auto usage = fua->EditUsage(effFormat);
29 0 : usage->textureSwizzleRGBA = swizzle;
30 0 : fua->AddTexUnpack(usage, pi, dui);
31 :
32 0 : fua->AllowUnsizedTexFormat(pi, usage);
33 0 : };
34 :
35 0 : const bool needsSwizzle = gl->IsCoreProfile();
36 0 : MOZ_ASSERT_IF(needsSwizzle, gl->IsSupported(gl::GLFeature::texture_swizzle));
37 :
38 0 : const bool needsSizedFormat = !gl->IsGLES();
39 :
40 : ////////////////
41 :
42 0 : pi = {LOCAL_GL_RGBA, LOCAL_GL_FLOAT};
43 0 : dui = {pi.format, pi.format, pi.type};
44 0 : swizzle = nullptr;
45 0 : if (needsSizedFormat) {
46 0 : dui.internalFormat = LOCAL_GL_RGBA32F;
47 : }
48 0 : fnAdd(webgl::EffectiveFormat::RGBA32F);
49 :
50 : //////
51 :
52 0 : pi = {LOCAL_GL_RGB, LOCAL_GL_FLOAT};
53 0 : dui = {pi.format, pi.format, pi.type};
54 0 : swizzle = nullptr;
55 0 : if (needsSizedFormat) {
56 0 : dui.internalFormat = LOCAL_GL_RGB32F;
57 : }
58 0 : fnAdd(webgl::EffectiveFormat::RGB32F);
59 :
60 : //////
61 :
62 0 : pi = {LOCAL_GL_LUMINANCE, LOCAL_GL_FLOAT};
63 0 : dui = {pi.format, pi.format, pi.type};
64 0 : swizzle = nullptr;
65 0 : if (needsSwizzle) {
66 0 : dui = {LOCAL_GL_R32F, LOCAL_GL_RED, LOCAL_GL_FLOAT};
67 0 : swizzle = webgl::FormatUsageInfo::kLuminanceSwizzleRGBA;
68 0 : } else if (needsSizedFormat) {
69 0 : dui.internalFormat = LOCAL_GL_LUMINANCE32F_ARB;
70 : }
71 0 : fnAdd(webgl::EffectiveFormat::Luminance32F);
72 :
73 : //////
74 :
75 0 : pi = {LOCAL_GL_ALPHA, LOCAL_GL_FLOAT};
76 0 : dui = {pi.format, pi.format, pi.type};
77 0 : swizzle = nullptr;
78 0 : if (needsSwizzle) {
79 0 : dui = {LOCAL_GL_R32F, LOCAL_GL_RED, LOCAL_GL_FLOAT};
80 0 : swizzle = webgl::FormatUsageInfo::kAlphaSwizzleRGBA;
81 0 : } else if (needsSizedFormat) {
82 0 : dui.internalFormat = LOCAL_GL_ALPHA32F_ARB;
83 : }
84 0 : fnAdd(webgl::EffectiveFormat::Alpha32F);
85 :
86 : //////
87 :
88 0 : pi = {LOCAL_GL_LUMINANCE_ALPHA, LOCAL_GL_FLOAT};
89 0 : dui = {pi.format, pi.format, pi.type};
90 0 : swizzle = nullptr;
91 0 : if (needsSwizzle) {
92 0 : dui = {LOCAL_GL_RG32F, LOCAL_GL_RG, LOCAL_GL_FLOAT};
93 0 : swizzle = webgl::FormatUsageInfo::kLumAlphaSwizzleRGBA;
94 0 : } else if (needsSizedFormat) {
95 0 : dui.internalFormat = LOCAL_GL_LUMINANCE_ALPHA32F_ARB;
96 : }
97 0 : fnAdd(webgl::EffectiveFormat::Luminance32FAlpha32F);
98 0 : }
99 :
100 0 : WebGLExtensionTextureFloat::~WebGLExtensionTextureFloat()
101 : {
102 0 : }
103 :
104 : bool
105 0 : WebGLExtensionTextureFloat::IsSupported(const WebGLContext* webgl)
106 : {
107 0 : gl::GLContext* gl = webgl->GL();
108 :
109 0 : if (!gl->IsSupported(gl::GLFeature::texture_float))
110 0 : return false;
111 :
112 0 : const bool needsSwizzle = gl->IsCoreProfile();
113 0 : const bool hasSwizzle = gl->IsSupported(gl::GLFeature::texture_swizzle);
114 0 : if (needsSwizzle && !hasSwizzle)
115 0 : return false;
116 :
117 0 : return true;
118 : }
119 :
120 0 : IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureFloat, OES_texture_float)
121 :
122 : } // namespace mozilla
|