Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/canvas/WebGLExtensionTextureHalfFloat.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
WebGLExtensionTextureHalfFloat::WebGLExtensionTextureHalfFloat(WebGLContext* webgl)
15
    : WebGLExtensionBase(webgl)
16
0
{
17
0
    auto& fua = webgl->mFormatUsage;
18
0
    gl::GLContext* gl = webgl->GL();
19
0
20
0
    webgl::PackingInfo pi;
21
0
    webgl::DriverUnpackInfo dui;
22
0
    const GLint* swizzle = nullptr;
23
0
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
0
30
0
        fua->AllowUnsizedTexFormat(pi, usage);
31
0
    };
32
0
33
0
    const bool needsSwizzle = gl->IsCoreProfile();
34
0
    MOZ_ASSERT_IF(needsSwizzle, gl->IsSupported(gl::GLFeature::texture_swizzle));
35
0
36
0
    const bool needsSizedFormat = !gl->IsGLES();
37
0
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
0
    }
43
0
44
0
    ////////////////
45
0
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
0
    }
52
0
    fnAdd(webgl::EffectiveFormat::RGBA16F);
53
0
54
0
    //////
55
0
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
0
    }
62
0
    fnAdd(webgl::EffectiveFormat::RGB16F);
63
0
64
0
    //////
65
0
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
0
    }
75
0
    fnAdd(webgl::EffectiveFormat::Luminance16F);
76
0
77
0
    //////
78
0
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
0
    }
88
0
    fnAdd(webgl::EffectiveFormat::Alpha16F);
89
0
90
0
    //////
91
0
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
0
    }
101
0
    fnAdd(webgl::EffectiveFormat::Luminance16FAlpha16F);
102
0
}
103
104
WebGLExtensionTextureHalfFloat::~WebGLExtensionTextureHalfFloat()
105
0
{
106
0
}
107
108
bool
109
WebGLExtensionTextureHalfFloat::IsSupported(const WebGLContext* webgl)
110
0
{
111
0
    gl::GLContext* gl = webgl->GL();
112
0
113
0
    if (!gl->IsSupported(gl::GLFeature::texture_half_float) &&
114
0
        !gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float))
115
0
    {
116
0
        return false;
117
0
    }
118
0
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
0
124
0
    return true;
125
0
}
126
127
IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionTextureHalfFloat, OES_texture_half_float)
128
129
} // namespace mozilla