/src/mozilla-central/dom/canvas/WebGLExtensionTextureFloat.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | WebGLExtensionTextureFloat::WebGLExtensionTextureFloat(WebGLContext* webgl) |
15 | | : WebGLExtensionBase(webgl) |
16 | 0 | { |
17 | 0 | MOZ_ASSERT(IsSupported(webgl)); |
18 | 0 |
|
19 | 0 | auto& fua = webgl->mFormatUsage; |
20 | 0 | gl::GLContext* gl = webgl->GL(); |
21 | 0 |
|
22 | 0 | webgl::PackingInfo pi; |
23 | 0 | webgl::DriverUnpackInfo dui; |
24 | 0 | const GLint* swizzle = nullptr; |
25 | 0 |
|
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 | 0 |
|
32 | 0 | fua->AllowUnsizedTexFormat(pi, usage); |
33 | 0 | }; |
34 | 0 |
|
35 | 0 | const bool needsSwizzle = gl->IsCoreProfile(); |
36 | 0 | MOZ_ASSERT_IF(needsSwizzle, gl->IsSupported(gl::GLFeature::texture_swizzle)); |
37 | 0 |
|
38 | 0 | const bool needsSizedFormat = !gl->IsGLES(); |
39 | 0 |
|
40 | 0 | //////////////// |
41 | 0 |
|
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 | 0 | } |
48 | 0 | fnAdd(webgl::EffectiveFormat::RGBA32F); |
49 | 0 |
|
50 | 0 | ////// |
51 | 0 |
|
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 | 0 | } |
58 | 0 | fnAdd(webgl::EffectiveFormat::RGB32F); |
59 | 0 |
|
60 | 0 | ////// |
61 | 0 |
|
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 | 0 | } |
71 | 0 | fnAdd(webgl::EffectiveFormat::Luminance32F); |
72 | 0 |
|
73 | 0 | ////// |
74 | 0 |
|
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 | 0 | } |
84 | 0 | fnAdd(webgl::EffectiveFormat::Alpha32F); |
85 | 0 |
|
86 | 0 | ////// |
87 | 0 |
|
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 | 0 | } |
97 | 0 | fnAdd(webgl::EffectiveFormat::Luminance32FAlpha32F); |
98 | 0 | } |
99 | | |
100 | | WebGLExtensionTextureFloat::~WebGLExtensionTextureFloat() |
101 | 0 | { |
102 | 0 | } |
103 | | |
104 | | bool |
105 | | WebGLExtensionTextureFloat::IsSupported(const WebGLContext* webgl) |
106 | 0 | { |
107 | 0 | gl::GLContext* gl = webgl->GL(); |
108 | 0 |
|
109 | 0 | if (!gl->IsSupported(gl::GLFeature::texture_float)) |
110 | 0 | return false; |
111 | 0 | |
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 | 0 | |
117 | 0 | return true; |
118 | 0 | } |
119 | | |
120 | | IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureFloat, OES_texture_float) |
121 | | |
122 | | } // namespace mozilla |