1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/glsl/samplers/glsl-function-texture2dproj.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 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>WebGL texture2D GLSL conformance 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 +</head> 1.20 +<body> 1.21 +<canvas id="example" width="32" height="32"></canvas> 1.22 +<div id="description"></div> 1.23 +<div id="console"></div> 1.24 +<script id="vshader0" type="x-shader/x-vertex"> 1.25 +attribute vec4 vPosition; 1.26 +attribute vec2 texCoord0; 1.27 +varying vec2 texCoord; 1.28 +void main() { 1.29 + gl_Position = vPosition; 1.30 + texCoord = texCoord0; 1.31 +} 1.32 +</script> 1.33 +<script id="fshader0" type="x-shader/x-vertex"> 1.34 +precision mediump float; 1.35 +uniform sampler2D tex; 1.36 +uniform float divisor; 1.37 +varying vec2 texCoord; 1.38 +void main() { 1.39 + gl_FragData[0] = texture2DProj(tex, vec3(texCoord, divisor)); 1.40 +} 1.41 +</script> 1.42 +<script id="vshader1" type="x-shader/x-vertex"> 1.43 +attribute vec4 vPosition; 1.44 +attribute vec2 texCoord0; 1.45 +varying vec2 texCoord; 1.46 +void main() { 1.47 + gl_Position = vPosition; 1.48 + texCoord = texCoord0; 1.49 +} 1.50 +</script> 1.51 +<script id="fshader1" type="x-shader/x-vertex"> 1.52 +precision mediump float; 1.53 +uniform sampler2D tex; 1.54 +uniform float divisor; 1.55 +varying vec2 texCoord; 1.56 +void main() { 1.57 + gl_FragData[0] = texture2DProj(tex, vec4(texCoord, 123.0, divisor)); 1.58 +} 1.59 +</script> 1.60 +<script> 1.61 +description("tests GLSL texture2DProj function with"); 1.62 + 1.63 +var wtu = WebGLTestUtils; 1.64 +var gl = wtu.create3DContext("example", {antialias: false}); 1.65 + 1.66 +wtu.setupUnitQuad(gl, 0, 1); 1.67 +var tex = gl.createTexture(); 1.68 +gl.bindTexture(gl.TEXTURE_2D, tex); 1.69 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 1.70 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 1.71 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); 1.72 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); 1.73 + 1.74 +var c = document.createElement("canvas"); 1.75 +c.width = 16; 1.76 +c.height = 16; 1.77 +var ctx = c.getContext("2d"); 1.78 +ctx.fillStyle = "rgb(0,255,0)"; 1.79 +ctx.fillRect(0, 0, 16, 16); 1.80 +ctx.fillStyle = "rgb(0,0,255)"; 1.81 +ctx.fillRect(0, 0, 8, 8); 1.82 +ctx.fillRect(8, 8, 8, 8); 1.83 + 1.84 +gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c); 1.85 + 1.86 +for (var ss = 0; ss < 2; ++ss) { 1.87 + debug(""); 1.88 + debug(ss ? "testing vec4 version" : "testing vec3 version"); 1.89 + var program = wtu.setupProgram( 1.90 + gl, ['vshader' + ss, 'fshader' + ss], 1.91 + ['vPosition', 'texCoord0'], [0, 1]); 1.92 + gl.useProgram(program); 1.93 + var loc = gl.getUniformLocation(program, "divisor"); 1.94 + 1.95 + for (var ii = 0; ii < 3; ++ii) { 1.96 + var denominator = Math.pow(2, ii); 1.97 + gl.uniform1f(loc, 1 / denominator); 1.98 + wtu.drawQuad(gl); 1.99 + var size = 16 / denominator; 1.100 + for (var yy = 0; yy < 32; yy += size) { 1.101 + for (var xx = 0; xx < 32; xx += size) { 1.102 + var odd = (xx / size + yy / size) % 2; 1.103 + var color = odd ? [0, 255, 0, 255] : [0, 0, 255, 255]; 1.104 + var msg = "" + xx + ", " + yy + ", " + size + ", " + size + " should be " + (odd ? "green" : "blue"); 1.105 + wtu.checkCanvasRect(gl, xx, yy, size, size, color, msg); 1.106 + } 1.107 + } 1.108 + } 1.109 +} 1.110 +glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors."); 1.111 + 1.112 +successfullyParsed = true; 1.113 + 1.114 +</script> 1.115 +<script>finishTest();</script> 1.116 + 1.117 +</body> 1.118 +</html> 1.119 + 1.120 +