OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 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: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 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. |
| 24 */ |
| 25 |
| 26 --> |
| 27 |
| 28 <!DOCTYPE html> |
| 29 <html> |
| 30 <head> |
| 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.js"> </script> |
| 37 <script src="../../resources/webgl-test-utils.js"> </script> |
| 38 |
| 39 <script id="vshaderNoBranch", type="x-shader/x-vertex"> |
| 40 attribute vec3 aPosition; |
| 41 uniform float redIntensity; |
| 42 |
| 43 varying vec4 vColor; |
| 44 |
| 45 float MADBug(float paramValue) { |
| 46 float localVar = 1.0; |
| 47 return 0.25 * ceil(localVar) + paramValue; |
| 48 } |
| 49 |
| 50 void main(void) { |
| 51 gl_Position = vec4(aPosition, 1.0); |
| 52 vColor = vec4(MADBug(redIntensity), 0., 0., 1.); |
| 53 } |
| 54 </script> |
| 55 |
| 56 <script id="vshaderBranch", type="x-shader/x-vertex"> |
| 57 attribute vec3 aPosition; |
| 58 uniform float redIntensity; |
| 59 |
| 60 varying vec4 vColor; |
| 61 |
| 62 float MADBug(float paramValue) { |
| 63 float localVar = 1.0; |
| 64 return 0.25 * ceil(localVar) + paramValue; |
| 65 } |
| 66 |
| 67 void main(void) { |
| 68 float condition = 42.; |
| 69 if (condition == 0.) {} |
| 70 gl_Position = vec4(aPosition, 1.0); |
| 71 vColor = vec4(MADBug(redIntensity), 0., 0., 1.); |
| 72 } |
| 73 </script> |
| 74 |
| 75 <script id="fshader", type="x-shader/x-fragment"> |
| 76 #if defined(GL_ES) |
| 77 precision mediump float; |
| 78 #endif |
| 79 varying vec4 vColor; |
| 80 void main() |
| 81 { |
| 82 gl_FragColor = vColor; |
| 83 } |
| 84 </script> |
| 85 </head> |
| 86 <body> |
| 87 <canvas id="canvasNoBranch" width="50" height="50"></canvas> |
| 88 <canvas id="canvasBranch" width="50" height="50"></canvas> |
| 89 <div id="description">This tests against a Mac driver bug related to branches |
| 90 inside of Vertex Shaders.</div> |
| 91 <div id="console"></div> |
| 92 <script> |
| 93 var width = 50; |
| 94 var height = 50; |
| 95 |
| 96 function drawAndRead(canvasID, vshaderID, buffer) |
| 97 { |
| 98 var gl = initWebGL(canvasID); |
| 99 var program = 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); |
| 105 |
| 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) |
| 112 return false; |
| 113 return true; |
| 114 } |
| 115 |
| 116 function compareRendering(buffer1, buffer2, tol) |
| 117 { |
| 118 for (var i = 0; i < width * height * 4; ++i) { |
| 119 if (Math.abs(buffer1[i] - buffer2[i]) > tol) |
| 120 return false; |
| 121 } |
| 122 return true; |
| 123 } |
| 124 |
| 125 function init() |
| 126 { |
| 127 if (window.initNonKhronosFramework) { |
| 128 window.initNonKhronosFramework(false); |
| 129 } |
| 130 |
| 131 description("tests vertex shader with branch"); |
| 132 |
| 133 var bufBranch = new Uint8Array(width * height * 4); |
| 134 var bufNoBranch = new Uint8Array(width * height * 4); |
| 135 |
| 136 if (drawAndRead("canvasBranch", "vshaderBranch", bufBranch) == false || |
| 137 drawAndRead("canvasNoBranch", "vshaderNoBranch", bufNoBranch) == false)
{ |
| 138 testFailed("Setup failed"); |
| 139 } else { |
| 140 if (compareRendering(bufBranch, bufNoBranch, 4) == false) |
| 141 testFailed("Rendering results are different"); |
| 142 else |
| 143 testPassed("Rendering results are the same"); |
| 144 } |
| 145 } |
| 146 |
| 147 init(); |
| 148 successfullyParsed = true; |
| 149 </script> |
| 150 <script src="../../../resources/js-test-post.js"></script> |
| 151 </body> |
| 152 </html> |
| 153 |
OLD | NEW |