OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 Use of this source code is governed by a BSD-style license that can be |
| 4 found in the LICENSE file. |
| 5 --> |
| 6 <!DOCTYPE html> |
| 7 <html> |
| 8 <head> |
| 9 <meta charset="utf-8"> |
| 10 <title>GLSL function nodes Test</title> |
| 11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> |
| 12 <script src="../../../resources/js-test-pre.js"></script> |
| 13 <script src="../../resources/webgl-test.js"> </script> |
| 14 <script src="../../resources/webgl-test-utils.js"> </script> |
| 15 |
| 16 <script id="vshaderFunction", type="x-shader/x-vertex"> |
| 17 attribute vec4 aPosition; |
| 18 varying vec4 vColor; |
| 19 |
| 20 float sign_emu(float value) { |
| 21 if (value == 0.0) return 0.0; |
| 22 return value > 0.0 ? 1.0 : -1.0; |
| 23 } |
| 24 |
| 25 void main() |
| 26 { |
| 27 gl_Position = aPosition; |
| 28 vec2 texcoord = vec2(aPosition.xy * 0.5 + vec2(0.5, 0.5)); |
| 29 vec4 color = vec4( |
| 30 texcoord, |
| 31 texcoord.x * texcoord.y, |
| 32 (1.0 - texcoord.x) * texcoord.y * 0.5 + 0.5); |
| 33 vColor = vec4( |
| 34 sign_emu(color.x * 2.0 - 1.0) * 0.5 + 0.5, |
| 35 sign_emu(color.y * 2.0 - 1.0) * 0.5 + 0.5, |
| 36 0, |
| 37 1); |
| 38 } |
| 39 </script> |
| 40 |
| 41 <script id="vshaderMacro", type="x-shader/x-vertex"> |
| 42 attribute vec4 aPosition; |
| 43 varying vec4 vColor; |
| 44 |
| 45 #define sign_emu(value) ((value) == 0.0 ? 0.0 : ((value) > 0.0 ? 1.0 : -1.0)) |
| 46 |
| 47 void main() |
| 48 { |
| 49 gl_Position = aPosition; |
| 50 vec2 texcoord = vec2(aPosition.xy * 0.5 + vec2(0.5, 0.5)); |
| 51 vec4 color = vec4( |
| 52 texcoord, |
| 53 texcoord.x * texcoord.y, |
| 54 (1.0 - texcoord.x) * texcoord.y * 0.5 + 0.5); |
| 55 vColor = vec4( |
| 56 sign_emu(color.x * 2.0 - 1.0) * 0.5 + 0.5, |
| 57 sign_emu(color.y * 2.0 - 1.0) * 0.5 + 0.5, |
| 58 0, |
| 59 1); |
| 60 } |
| 61 </script> |
| 62 |
| 63 <script id="fshader", type="x-shader/x-fragment"> |
| 64 #if defined(GL_ES) |
| 65 precision mediump float; |
| 66 #endif |
| 67 varying vec4 vColor; |
| 68 void main() |
| 69 { |
| 70 gl_FragColor = vColor; |
| 71 } |
| 72 </script> |
| 73 </head> |
| 74 <body> |
| 75 <canvas id="canvasFunction" width="50" height="50"></canvas> |
| 76 <canvas id="canvasMacro" width="50" height="50"></canvas> |
| 77 <div id="description">This tests against a Mac driver bug related to function ca
lls.</div> |
| 78 <div id="console"></div> |
| 79 <script> |
| 80 var width = 50; |
| 81 var height = 50; |
| 82 |
| 83 function drawAndRead(canvasID, vshaderID, buffer) |
| 84 { |
| 85 var gl = initWebGL(canvasID, vshaderID, "fshader", ["aPosition"], [0, 0, 0,
1], 1); |
| 86 var vertexObject = gl.createBuffer(); |
| 87 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 88 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,
-0.5,0 ]), gl.STATIC_DRAW); |
| 89 gl.enableVertexAttribArray(0); |
| 90 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
| 91 |
| 92 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 93 gl.drawArrays(gl.TRIANGLES, 0, 3); |
| 94 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buffer); |
| 95 if (gl.getError() != gl.NO_ERROR) |
| 96 return false; |
| 97 return true; |
| 98 } |
| 99 |
| 100 function compareRendering(buffer1, buffer2, tol) |
| 101 { |
| 102 for (var i = 0; i < width * height * 4; ++i) { |
| 103 if (Math.abs(buffer1[i] - buffer2[i]) > tol) |
| 104 return false; |
| 105 } |
| 106 return true; |
| 107 } |
| 108 |
| 109 function init() |
| 110 { |
| 111 if (window.initNonKhronosFramework) { |
| 112 window.initNonKhronosFramework(false); |
| 113 } |
| 114 |
| 115 var bufFunction = new Uint8Array(width * height * 4); |
| 116 var bufMacro = new Uint8Array(width * height * 4); |
| 117 |
| 118 if (drawAndRead("canvasFunction", "vshaderFunction", bufFunction) == false |
| |
| 119 drawAndRead("canvasMacro", "vshaderMacro", bufMacro) == false) { |
| 120 testFailed("Setup failed"); |
| 121 } else { |
| 122 if (compareRendering(bufFunction, bufMacro, 4) == false) |
| 123 testFailed("Rendering results are different"); |
| 124 else |
| 125 testPassed("Rendering results are the same"); |
| 126 } |
| 127 } |
| 128 |
| 129 init(); |
| 130 successfullyParsed = true; |
| 131 </script> |
| 132 <script src="../../../resources/js-test-post.js"></script> |
| 133 </body> |
| 134 </html> |
| 135 |
OLD | NEW |