no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / dom / canvas / test / webgl-mochitest / ensure-exts / test_implicit.html
blobe3ce1ad130deed512504e4466804eb1781c139d5
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset='utf-8'/>
5 <script src='/tests/SimpleTest/SimpleTest.js'></script>
6 <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
7 <script src='ensure-ext.js'></script>
8 </head>
9 <body>
10 <script id='g_vs' type='text/plain'>
12 void main() {
13 gl_PointSize = 1.0;
16 </script>
17 <script id='g_fs' type='text/plain'>
19 void main() {
20 gl_FragColor = vec4(0);
23 </script>
24 <script>
26 'use strict';
28 let gl = null;
30 function CheckTexFloatRenderable(rgbaInternal, type) {
31 const tex = gl.createTexture();
32 gl.bindTexture(gl.TEXTURE_2D, tex);
33 gl.texImage2D(gl.TEXTURE_2D, 0, rgbaInternal, 1, 1, 0, gl.RGBA, type, null);
35 const fb = gl.createFramebuffer();
36 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
37 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
38 return gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
41 function CheckRbFloatRenderable(format) {
42 const rb = gl.createRenderbuffer();
43 gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
44 gl.renderbufferStorage(gl.RENDERBUFFER, format, 1, 1);
46 const fb = gl.createFramebuffer();
47 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
48 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
49 return gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE;
52 function CheckBlending() {
53 function CompileShader(type, elem) {
54 const text = elem.innerHTML.trim();
55 const s = gl.createShader(type);
56 gl.shaderSource(s, text);
57 gl.compileShader(s);
58 return s;
61 const vs = CompileShader(gl.VERTEX_SHADER, g_vs);
62 const fs = CompileShader(gl.FRAGMENT_SHADER, g_fs);
63 const p = gl.createProgram();
64 gl.attachShader(p, vs);
65 gl.attachShader(p, fs);
66 gl.linkProgram(p);
67 gl.useProgram(p);
69 gl.drawArrays(gl.POINTS, 0, 1);
70 if (gl.getError()) throw new Error('Unexpected GL error,');
72 gl.enable(gl.BLEND);
73 gl.drawArrays(gl.POINTS, 0, 1);
74 return gl.getError() == 0;
77 function ResetGl(type) {
78 if (gl) {
79 const ext = gl.getExtension('WEBGL_lose_context');
80 ext.loseContext();
81 gl = null;
83 const c = document.createElement('canvas');
84 gl = c.getContext(type);
85 return !!gl;
88 function HasExt(name) {
89 return gl.getSupportedExtensions().indexOf(name) != -1;
92 ResetGl('webgl');
93 if (HasExt('EXT_color_buffer_half_float')) {
94 const ext = gl.getExtension('OES_texture_half_float');
95 const implicitEnabled = CheckTexFloatRenderable(gl.RGBA, ext.HALF_FLOAT_OES);
96 ok(implicitEnabled, 'OES_texture_half_float should implicitly enable EXT_color_buffer_half_float.');
99 ResetGl('webgl');
100 if (HasExt('WEBGL_color_buffer_float')) {
101 const ext = gl.getExtension('OES_texture_float');
102 const implicitEnabled = CheckTexFloatRenderable(gl.RGBA, gl.FLOAT);
103 ok(implicitEnabled, 'OES_texture_float should implicitly enable WEBGL_color_buffer_float.');
105 if (HasExt('EXT_float_blend')) {
106 ok(CheckBlending(), 'OES_texture_float should implicitly enable EXT_float_blend.');
110 ResetGl('webgl');
111 if (HasExt('EXT_float_blend')) {
112 const ext = gl.getExtension('WEBGL_color_buffer_float');
113 CheckRbFloatRenderable(ext.RGBA32F_EXT);
114 const implicitEnabled = CheckBlending();
115 ok(implicitEnabled, 'WEBGL_color_buffer_float should implicitly enable EXT_float_blend.');
118 if (ResetGl('webgl2')) {
119 if (HasExt('EXT_float_blend')) {
120 const ext = gl.getExtension('EXT_color_buffer_float');
121 CheckTexFloatRenderable(gl.RGBA32F, gl.FLOAT);
122 const implicitEnabled = CheckBlending();
123 ok(implicitEnabled, 'EXT_color_buffer_float should implicitly enable EXT_float_blend.');
127 </script>
128 </body>
129 </html>