4 ** Copyright (c) 2012 The Khronos Group Inc.
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 <meta charset="utf-8">
32 <title>GLSL function nodes Test</title>
33 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
34 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/>
35 <script src="../../../resources/js-test-pre.js"></script>
36 <script src="../../resources/webgl-test-utils.js"> </script>
38 <script id="vshaderNoBranch" type="x-shader/x-vertex">
39 attribute vec3 aPosition;
40 uniform float redIntensity;
44 float MADBug(float paramValue) {
46 return 0.25 * ceil(localVar) + paramValue;
50 gl_Position = vec4(aPosition, 1.0);
51 vColor = vec4(MADBug(redIntensity), 0., 0., 1.);
55 <script id="vshaderBranch" type="x-shader/x-vertex">
56 attribute vec3 aPosition;
57 uniform float redIntensity;
61 float MADBug(float paramValue) {
63 return 0.25 * ceil(localVar) + paramValue;
67 float condition = 42.;
68 if (condition == 0.) {}
69 gl_Position = vec4(aPosition, 1.0);
70 vColor = vec4(MADBug(redIntensity), 0., 0., 1.);
74 <script id="fshader" type="x-shader/x-fragment">
75 precision mediump float;
80 gl_FragColor = vColor;
85 <canvas id="canvasNoBranch" width="50" height="50"></canvas>
86 <canvas id="canvasBranch" width="50" height="50"></canvas>
87 <div id="description">This tests against a Mac driver bug related to branches
88 inside of Vertex Shaders.</div>
89 <div id="console"></div>
94 var wtu = WebGLTestUtils;
96 function drawAndRead(canvasID, vshaderID, buffer)
98 var gl = wtu.create3DContext(canvasID);
99 var program = wtu.setupProgram(gl, [vshaderID, "fshader"], ["aPosition"]);
100 var vertexObject = gl.createBuffer();
101 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
102 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -1,-1,0, 1,-1,0 ]), gl.STATIC_DRAW);
103 gl.enableVertexAttribArray(0);
104 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
106 var loc = gl.getUniformLocation(program, "redIntensity");
107 gl.uniform1f(loc, 0.75);
108 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
109 gl.drawArrays(gl.TRIANGLES, 0, 3);
110 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
111 if (gl.getError() != gl.NO_ERROR)
116 function compareRendering(buffer1, buffer2, tol)
118 for (var i = 0; i < width * height * 4; ++i) {
119 if (Math.abs(buffer1[i] - buffer2[i]) > tol)
127 description("tests vertex shader with branch");
129 var bufBranch = new Uint8Array(width * height * 4);
130 var bufNoBranch = new Uint8Array(width * height * 4);
132 if (drawAndRead("canvasBranch", "vshaderBranch", bufBranch) == false ||
133 drawAndRead("canvasNoBranch", "vshaderNoBranch", bufNoBranch) == false) {
134 testFailed("Setup failed");
136 if (compareRendering(bufBranch, bufNoBranch, 4) == false)
137 testFailed("Rendering results are different");
139 testPassed("Rendering results are the same");
144 var successfullyParsed = true;
146 <script src="../../../resources/js-test-post.js"></script>