content/canvas/test/webgl-conformance/conformance/glsl/samplers/glsl-function-texture2dproj.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 <!--
michael@0 2 Copyright (c) 2011 The Chromium Authors. All rights reserved.
michael@0 3 Use of this source code is governed by a BSD-style license that can be
michael@0 4 found in the LICENSE file.
michael@0 5 -->
michael@0 6 <!DOCTYPE html>
michael@0 7 <html>
michael@0 8 <head>
michael@0 9 <meta charset="utf-8">
michael@0 10 <title>WebGL texture2D GLSL conformance test.</title>
michael@0 11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
michael@0 12 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/>
michael@0 13 <script src="../../../resources/js-test-pre.js"></script>
michael@0 14 <script src="../../resources/webgl-test.js"> </script>
michael@0 15 <script src="../../resources/webgl-test-utils.js"> </script>
michael@0 16 </head>
michael@0 17 <body>
michael@0 18 <canvas id="example" width="32" height="32"></canvas>
michael@0 19 <div id="description"></div>
michael@0 20 <div id="console"></div>
michael@0 21 <script id="vshader0" type="x-shader/x-vertex">
michael@0 22 attribute vec4 vPosition;
michael@0 23 attribute vec2 texCoord0;
michael@0 24 varying vec2 texCoord;
michael@0 25 void main() {
michael@0 26 gl_Position = vPosition;
michael@0 27 texCoord = texCoord0;
michael@0 28 }
michael@0 29 </script>
michael@0 30 <script id="fshader0" type="x-shader/x-vertex">
michael@0 31 precision mediump float;
michael@0 32 uniform sampler2D tex;
michael@0 33 uniform float divisor;
michael@0 34 varying vec2 texCoord;
michael@0 35 void main() {
michael@0 36 gl_FragData[0] = texture2DProj(tex, vec3(texCoord, divisor));
michael@0 37 }
michael@0 38 </script>
michael@0 39 <script id="vshader1" type="x-shader/x-vertex">
michael@0 40 attribute vec4 vPosition;
michael@0 41 attribute vec2 texCoord0;
michael@0 42 varying vec2 texCoord;
michael@0 43 void main() {
michael@0 44 gl_Position = vPosition;
michael@0 45 texCoord = texCoord0;
michael@0 46 }
michael@0 47 </script>
michael@0 48 <script id="fshader1" type="x-shader/x-vertex">
michael@0 49 precision mediump float;
michael@0 50 uniform sampler2D tex;
michael@0 51 uniform float divisor;
michael@0 52 varying vec2 texCoord;
michael@0 53 void main() {
michael@0 54 gl_FragData[0] = texture2DProj(tex, vec4(texCoord, 123.0, divisor));
michael@0 55 }
michael@0 56 </script>
michael@0 57 <script>
michael@0 58 description("tests GLSL texture2DProj function with");
michael@0 59
michael@0 60 var wtu = WebGLTestUtils;
michael@0 61 var gl = wtu.create3DContext("example", {antialias: false});
michael@0 62
michael@0 63 wtu.setupUnitQuad(gl, 0, 1);
michael@0 64 var tex = gl.createTexture();
michael@0 65 gl.bindTexture(gl.TEXTURE_2D, tex);
michael@0 66 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
michael@0 67 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
michael@0 68 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
michael@0 69 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
michael@0 70
michael@0 71 var c = document.createElement("canvas");
michael@0 72 c.width = 16;
michael@0 73 c.height = 16;
michael@0 74 var ctx = c.getContext("2d");
michael@0 75 ctx.fillStyle = "rgb(0,255,0)";
michael@0 76 ctx.fillRect(0, 0, 16, 16);
michael@0 77 ctx.fillStyle = "rgb(0,0,255)";
michael@0 78 ctx.fillRect(0, 0, 8, 8);
michael@0 79 ctx.fillRect(8, 8, 8, 8);
michael@0 80
michael@0 81 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);
michael@0 82
michael@0 83 for (var ss = 0; ss < 2; ++ss) {
michael@0 84 debug("");
michael@0 85 debug(ss ? "testing vec4 version" : "testing vec3 version");
michael@0 86 var program = wtu.setupProgram(
michael@0 87 gl, ['vshader' + ss, 'fshader' + ss],
michael@0 88 ['vPosition', 'texCoord0'], [0, 1]);
michael@0 89 gl.useProgram(program);
michael@0 90 var loc = gl.getUniformLocation(program, "divisor");
michael@0 91
michael@0 92 for (var ii = 0; ii < 3; ++ii) {
michael@0 93 var denominator = Math.pow(2, ii);
michael@0 94 gl.uniform1f(loc, 1 / denominator);
michael@0 95 wtu.drawQuad(gl);
michael@0 96 var size = 16 / denominator;
michael@0 97 for (var yy = 0; yy < 32; yy += size) {
michael@0 98 for (var xx = 0; xx < 32; xx += size) {
michael@0 99 var odd = (xx / size + yy / size) % 2;
michael@0 100 var color = odd ? [0, 255, 0, 255] : [0, 0, 255, 255];
michael@0 101 var msg = "" + xx + ", " + yy + ", " + size + ", " + size + " should be " + (odd ? "green" : "blue");
michael@0 102 wtu.checkCanvasRect(gl, xx, yy, size, size, color, msg);
michael@0 103 }
michael@0 104 }
michael@0 105 }
michael@0 106 }
michael@0 107 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
michael@0 108
michael@0 109 successfullyParsed = true;
michael@0 110
michael@0 111 </script>
michael@0 112 <script>finishTest();</script>
michael@0 113
michael@0 114 </body>
michael@0 115 </html>
michael@0 116
michael@0 117

mercurial