summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-mochitest/ensure-exts/test_implicit.html
blob: e3ce1ad130deed512504e4466804eb1781c139d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE HTML>
<html>
  <head>
    <meta charset='utf-8'/>
    <script src='/tests/SimpleTest/SimpleTest.js'></script>
    <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
    <script src='ensure-ext.js'></script>
  </head>
  <body>
    <script id='g_vs' type='text/plain'>

void main() {
    gl_PointSize = 1.0;
}

    </script>
    <script id='g_fs' type='text/plain'>

void main() {
    gl_FragColor = vec4(0);
}

    </script>
    <script>

'use strict';

let gl = null;

function CheckTexFloatRenderable(rgbaInternal, type) {
    const tex = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, tex);
    gl.texImage2D(gl.TEXTURE_2D, 0, rgbaInternal, 1, 1, 0, gl.RGBA, type, null);

    const fb = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
    return gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
}

function CheckRbFloatRenderable(format) {
    const rb = gl.createRenderbuffer();
    gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
    gl.renderbufferStorage(gl.RENDERBUFFER, format, 1, 1);

    const fb = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
    gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
    return gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
}

function CheckBlending() {
    function CompileShader(type, elem) {
        const text = elem.innerHTML.trim();
        const s = gl.createShader(type);
        gl.shaderSource(s, text);
        gl.compileShader(s);
        return s;
    }

    const vs = CompileShader(gl.VERTEX_SHADER, g_vs);
    const fs = CompileShader(gl.FRAGMENT_SHADER, g_fs);
    const p = gl.createProgram();
    gl.attachShader(p, vs);
    gl.attachShader(p, fs);
    gl.linkProgram(p);
    gl.useProgram(p);

    gl.drawArrays(gl.POINTS, 0, 1);
    if (gl.getError()) throw new Error('Unexpected GL error,');

    gl.enable(gl.BLEND);
    gl.drawArrays(gl.POINTS, 0, 1);
    return gl.getError() == 0;
}

function ResetGl(type) {
    if (gl) {
        const ext = gl.getExtension('WEBGL_lose_context');
        ext.loseContext();
        gl = null;
    }
    const c = document.createElement('canvas');
    gl = c.getContext(type);
    return !!gl;
}

function HasExt(name) {
    return gl.getSupportedExtensions().indexOf(name) != -1;
}

ResetGl('webgl');
if (HasExt('EXT_color_buffer_half_float')) {
    const ext = gl.getExtension('OES_texture_half_float');
    const implicitEnabled = CheckTexFloatRenderable(gl.RGBA, ext.HALF_FLOAT_OES);
    ok(implicitEnabled, 'OES_texture_half_float should implicitly enable EXT_color_buffer_half_float.');
}

ResetGl('webgl');
if (HasExt('WEBGL_color_buffer_float')) {
    const ext = gl.getExtension('OES_texture_float');
    const implicitEnabled = CheckTexFloatRenderable(gl.RGBA, gl.FLOAT);
    ok(implicitEnabled, 'OES_texture_float should implicitly enable WEBGL_color_buffer_float.');

    if (HasExt('EXT_float_blend')) {
        ok(CheckBlending(), 'OES_texture_float should implicitly enable EXT_float_blend.');
    }
}

ResetGl('webgl');
if (HasExt('EXT_float_blend')) {
    const ext = gl.getExtension('WEBGL_color_buffer_float');
    CheckRbFloatRenderable(ext.RGBA32F_EXT);
    const implicitEnabled = CheckBlending();
    ok(implicitEnabled, 'WEBGL_color_buffer_float should implicitly enable EXT_float_blend.');
}

if (ResetGl('webgl2')) {
    if (HasExt('EXT_float_blend')) {
        const ext = gl.getExtension('EXT_color_buffer_float');
        CheckTexFloatRenderable(gl.RGBA32F, gl.FLOAT);
        const implicitEnabled = CheckBlending();
        ok(implicitEnabled, 'EXT_color_buffer_float should implicitly enable EXT_float_blend.');
    }
}

    </script>
  </body>
</html>