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

changeset 0
6474c204b198
     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-texture2d-bias.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     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="256" height="256" style="width: 16px; height: 16px;"></canvas>
    1.22 +<div id="description"></div>
    1.23 +<div id="console"></div>
    1.24 +<script id="vshader2d" 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="fshader2d" type="x-shader/x-fragment">
    1.34 +precision mediump float;
    1.35 +uniform sampler2D tex;
    1.36 +uniform float bias;
    1.37 +varying vec2 texCoord;
    1.38 +void main() {
    1.39 +    gl_FragData[0] = texture2D(tex, texCoord, bias);
    1.40 +}
    1.41 +</script>
    1.42 +<script>
    1.43 +description("tests GLSL texture2D function with bias");
    1.44 +
    1.45 +var wtu = WebGLTestUtils;
    1.46 +var canvas = document.getElementById("example");
    1.47 +
    1.48 +shouldBe("canvas.width", "256");
    1.49 +shouldBe("canvas.height", "256");
    1.50 +
    1.51 +var gl = wtu.create3DContext(canvas);
    1.52 +var program = wtu.setupProgram(
    1.53 +    gl, ['vshader2d', 'fshader2d'], ['vPosition', 'texCoord0'], [0, 1]);
    1.54 +wtu.setupUnitQuad(gl, 0, 1);
    1.55 +
    1.56 +var colors = [
    1.57 +  {name: 'red', color:[255, 0, 0, 255]},
    1.58 +  {name: 'green', color:[0, 255, 0, 255]},
    1.59 +  {name: 'blue', color:[0, 0, 255, 255]},
    1.60 +  {name: 'yellow', color:[255, 255, 0, 255]},
    1.61 +  {name: 'magenta', color:[255, 0, 255, 255]},
    1.62 +  {name: 'cyan', color:[0, 255, 255, 255]},
    1.63 +  {name: 'pink', color:[255, 128, 128, 255]},
    1.64 +  {name: 'gray', color:[128, 128, 128, 255]},
    1.65 +  {name: 'light green', color:[128, 255, 128, 255]},
    1.66 +];
    1.67 +
    1.68 +shouldBe("colors.length", "9");
    1.69 +
    1.70 +var tex = gl.createTexture();
    1.71 +gl.bindTexture(gl.TEXTURE_2D, tex);
    1.72 +gl.texParameteri(
    1.73 +    gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
    1.74 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
    1.75 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
    1.76 +gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
    1.77 +
    1.78 +for (var ii = 0; ii < colors.length; ++ii) {
    1.79 +  var color = colors[ii];
    1.80 +  var size = Math.pow(2, colors.length - ii - 1);
    1.81 +  wtu.fillTexture(gl, tex, size, size, color.color, ii);
    1.82 +}
    1.83 +
    1.84 +var loc = gl.getUniformLocation(program, "bias");
    1.85 +
    1.86 +for (var ii = 0; ii < colors.length; ++ii) {
    1.87 +  gl.uniform1f(loc, ii);
    1.88 +  var color = colors[ii];
    1.89 +  wtu.drawQuad(gl);
    1.90 +  wtu.checkCanvas(
    1.91 +      gl, color.color,
    1.92 +      "256x256 texture drawn to 256x256 dest with bias = " + ii +
    1.93 +      " should be " + color.name);
    1.94 +}
    1.95 +glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
    1.96 +
    1.97 +successfullyParsed = true;
    1.98 +
    1.99 +</script>
   1.100 +<script>finishTest();</script>
   1.101 +
   1.102 +</body>
   1.103 +</html>
   1.104 +
   1.105 +

mercurial