1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/glsl/misc/glsl-function-nodes.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,139 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<title>GLSL function nodes Test</title> 1.14 +<link rel="stylesheet" href="../../../resources/js-test-style.css"/> 1.15 +<link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/> 1.16 +<script src="../../../resources/js-test-pre.js"></script> 1.17 +<script src="../../resources/webgl-test.js"> </script> 1.18 +<script src="../../resources/webgl-test-utils.js"> </script> 1.19 + 1.20 +<script id="vshaderFunction", type="x-shader/x-vertex"> 1.21 +attribute vec4 aPosition; 1.22 +varying vec4 vColor; 1.23 + 1.24 +float sign_emu(float value) { 1.25 + if (value == 0.0) return 0.0; 1.26 + return value > 0.0 ? 1.0 : -1.0; 1.27 +} 1.28 + 1.29 +void main() 1.30 +{ 1.31 + gl_Position = aPosition; 1.32 + vec2 texcoord = vec2(aPosition.xy * 0.5 + vec2(0.5, 0.5)); 1.33 + vec4 color = vec4( 1.34 + texcoord, 1.35 + texcoord.x * texcoord.y, 1.36 + (1.0 - texcoord.x) * texcoord.y * 0.5 + 0.5); 1.37 + vColor = vec4( 1.38 + sign_emu(color.x * 2.0 - 1.0) * 0.5 + 0.5, 1.39 + sign_emu(color.y * 2.0 - 1.0) * 0.5 + 0.5, 1.40 + 0, 1.41 + 1); 1.42 +} 1.43 +</script> 1.44 + 1.45 +<script id="vshaderMacro", type="x-shader/x-vertex"> 1.46 +attribute vec4 aPosition; 1.47 +varying vec4 vColor; 1.48 + 1.49 +#define sign_emu(value) ((value) == 0.0 ? 0.0 : ((value) > 0.0 ? 1.0 : -1.0)) 1.50 + 1.51 +void main() 1.52 +{ 1.53 + gl_Position = aPosition; 1.54 + vec2 texcoord = vec2(aPosition.xy * 0.5 + vec2(0.5, 0.5)); 1.55 + vec4 color = vec4( 1.56 + texcoord, 1.57 + texcoord.x * texcoord.y, 1.58 + (1.0 - texcoord.x) * texcoord.y * 0.5 + 0.5); 1.59 + vColor = vec4( 1.60 + sign_emu(color.x * 2.0 - 1.0) * 0.5 + 0.5, 1.61 + sign_emu(color.y * 2.0 - 1.0) * 0.5 + 0.5, 1.62 + 0, 1.63 + 1); 1.64 +} 1.65 +</script> 1.66 + 1.67 +<script id="fshader", type="x-shader/x-fragment"> 1.68 +#if defined(GL_ES) 1.69 +precision mediump float; 1.70 +#endif 1.71 +varying vec4 vColor; 1.72 +void main() 1.73 +{ 1.74 + gl_FragColor = vColor; 1.75 +} 1.76 +</script> 1.77 +</head> 1.78 +<body> 1.79 +<canvas id="canvasFunction" width="50" height="50"></canvas> 1.80 +<canvas id="canvasMacro" width="50" height="50"></canvas> 1.81 +<div id="description">This tests against a Mac driver bug related to function calls.</div> 1.82 +<div id="console"></div> 1.83 +<script> 1.84 +var width = 50; 1.85 +var height = 50; 1.86 + 1.87 +function drawAndRead(canvasID, vshaderID, buffer) 1.88 +{ 1.89 + var gl = initWebGL(canvasID, vshaderID, "fshader", ["aPosition"], [0, 0, 0, 1], 1); 1.90 + var vertexObject = gl.createBuffer(); 1.91 + gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); 1.92 + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW); 1.93 + gl.enableVertexAttribArray(0); 1.94 + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); 1.95 + 1.96 + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 1.97 + gl.drawArrays(gl.TRIANGLES, 0, 3); 1.98 + gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buffer); 1.99 + if (gl.getError() != gl.NO_ERROR) 1.100 + return false; 1.101 + return true; 1.102 +} 1.103 + 1.104 +function compareRendering(buffer1, buffer2, tol) 1.105 +{ 1.106 + for (var i = 0; i < width * height * 4; ++i) { 1.107 + if (Math.abs(buffer1[i] - buffer2[i]) > tol) 1.108 + return false; 1.109 + } 1.110 + return true; 1.111 +} 1.112 + 1.113 +function init() 1.114 +{ 1.115 + if (window.initNonKhronosFramework) { 1.116 + window.initNonKhronosFramework(false); 1.117 + } 1.118 + 1.119 + description("tests function nodes"); 1.120 + 1.121 + var bufFunction = new Uint8Array(width * height * 4); 1.122 + var bufMacro = new Uint8Array(width * height * 4); 1.123 + 1.124 + if (drawAndRead("canvasFunction", "vshaderFunction", bufFunction) == false || 1.125 + drawAndRead("canvasMacro", "vshaderMacro", bufMacro) == false) { 1.126 + testFailed("Setup failed"); 1.127 + } else { 1.128 + if (compareRendering(bufFunction, bufMacro, 4) == false) 1.129 + testFailedRender("Rendering results are different", bufMacro, 1.130 + bufFunction, width, height); 1.131 + else 1.132 + testPassed("Rendering results are the same"); 1.133 + } 1.134 +} 1.135 + 1.136 +init(); 1.137 +successfullyParsed = true; 1.138 +</script> 1.139 +<script>finishTest();</script> 1.140 +</body> 1.141 +</html> 1.142 +