Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / rendering / vertex-texture-fetch.html
blob7b014e1d66cafff3b0a748faf4974a9e7861999f
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL Vertex Texture Fetch.</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"> </script>
15 </head>
16 <body>
17 <canvas id="example" width="1" height="1" style="width: 40px; height: 40px;"></canvas>
18 <div id="description"></div>
19 <div id="console"></div>
20 <script id="vs" type="text/something-not-javascript">
21 attribute vec4 a_position;
22 attribute vec2 a_texCoord;
23 uniform sampler2D u_texture;
24 varying vec4 color;
25 void main() {
26 gl_Position = a_position;
27 color = texture2D(u_texture, a_texCoord);
29 </script>
30 <script id="fs" type="text/something-not-javascript">
31 precision mediump float;
32 varying vec4 color;
33 void main() {
34 gl_FragColor = color;
36 </script>
37 <script>
38 "use strict";
39 description("checks that vertex texture fetch, if supported, operates correctly.");
40 var wtu = WebGLTestUtils;
41 var gl = wtu.create3DContext("example");
42 if (!gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS)) {
43 testPassed("No vertex texture image units (vertex texture fetch not supported) -- this is legal");
44 } else {
45 var texture = gl.createTexture();
46 gl.bindTexture(gl.TEXTURE_2D, texture);
47 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE,
48 new Uint8Array([
49 255, 0, 0, 255,
50 0, 255, 0, 255,
51 0, 0, 255, 255,
52 255, 255, 0, 255]));
53 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
54 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
55 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
56 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
57 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture");
59 var program = wtu.setupProgram(gl, ["vs", "fs"], ["vPosition", "vTexCoord"]);
60 gl.uniform1i(gl.getUniformLocation(program, "u_texture"), 0);
61 gl.disable(gl.BLEND);
62 gl.disable(gl.DEPTH_TEST);
63 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initWebGL");
64 var bufferObjects = wtu.setupUnitQuad(gl, 0);
65 gl.disableVertexAttribArray(1);
67 gl.vertexAttrib2f(1, 0, 0);
68 wtu.clearAndDrawUnitQuad(gl);
69 wtu.checkCanvas(gl, [255, 0, 0, 255], "Should be red.");
71 gl.vertexAttrib2f(1, 1, 0);
72 wtu.clearAndDrawUnitQuad(gl);
73 wtu.checkCanvas(gl, [0, 255, 0, 255], "Should be green.");
75 gl.vertexAttrib2f(1, 0, 1);
76 wtu.clearAndDrawUnitQuad(gl);
77 wtu.checkCanvas(gl, [0, 0, 255, 255], "Should be blue.");
79 gl.vertexAttrib2f(1, 1, 1);
80 wtu.clearAndDrawUnitQuad(gl);
81 wtu.checkCanvas(gl, [255, 255, 0, 255], "Should be yellow.");
83 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");
86 var successfullyParsed = true;
87 </script>
88 <script src="../../js/js-test-post.js"></script>
90 </body>
91 </html>