content/canvas/test/webgl-conformance/conformance/glsl/samplers/glsl-function-texture2dlod.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.

     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>WebGL texture2D GLSL conformance test.</title>
    11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
    12 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/>
    13 <script src="../../../resources/js-test-pre.js"></script>
    14 <script src="../../resources/webgl-test.js"> </script>
    15 <script src="../../resources/webgl-test-utils.js"> </script>
    16 </head>
    17 <body>
    18 <canvas id="example" width="256" height="256" style="width: 16px; height: 16px;"></canvas>
    19 <div id="description"></div>
    20 <div id="console"></div>
    21 <script id="vshader2d" type="x-shader/x-vertex">
    22 attribute vec4 vPosition;
    23 attribute vec2 texCoord0;
    24 varying vec4 color;
    25 uniform sampler2D tex;
    26 uniform float lod;
    27 void main() {
    28     gl_Position = vPosition;
    29     color = texture2DLod(tex, texCoord0, lod);
    30 }
    31 </script>
    32 <script id="fshader2d" type="x-shader/x-vertex">
    33 precision mediump float;
    34 varying vec4 color;
    35 void main() {
    36     gl_FragData[0] = color;
    37 }
    38 </script>
    39 <script>
    40 description("tests GLSL texture2DLod function");
    42 var wtu = WebGLTestUtils;
    43 var canvas = document.getElementById("example");
    45 shouldBe("canvas.width", "256");
    46 shouldBe("canvas.height", "256");
    48 var gl = wtu.create3DContext(canvas);
    49 var program = wtu.setupProgram(
    50     gl, ['vshader2d', 'fshader2d'], ['vPosition', 'texCoord0'], [0, 1]);
    51 wtu.setupUnitQuad(gl, 0, 1);
    53 var colors = [
    54   {name: 'red', color:[255, 0, 0, 255]},
    55   {name: 'green', color:[0, 255, 0, 255]},
    56   {name: 'blue', color:[0, 0, 255, 255]},
    57   {name: 'yellow', color:[255, 255, 0, 255]},
    58   {name: 'magenta', color:[255, 0, 255, 255]},
    59   {name: 'cyan', color:[0, 255, 255, 255]},
    60   {name: 'pink', color:[255, 128, 128, 255]},
    61   {name: 'gray', color:[128, 128, 128, 255]},
    62   {name: 'light green', color:[128, 255, 128, 255]},
    63 ];
    65 shouldBe("colors.length", "9");
    67 var tex = gl.createTexture();
    68 gl.bindTexture(gl.TEXTURE_2D, tex);
    69 gl.texParameteri(
    70     gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR);
    71 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
    72 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
    73 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
    75 for (var ii = 0; ii < colors.length; ++ii) {
    76   var color = colors[ii];
    77   var size = Math.pow(2, colors.length - ii - 1);
    78   wtu.fillTexture(gl, tex, size, size, color.color, ii);
    79 }
    81 var loc = gl.getUniformLocation(program, "lod");
    83 for (var ii = 0; ii < colors.length; ++ii) {
    84   gl.uniform1f(loc, ii);
    85   var color = colors[ii];
    86   wtu.drawQuad(gl);
    87   wtu.checkCanvas(
    88       gl, color.color,
    89       "256x256 texture drawn to 256x256 dest with lod = " + ii +
    90       " should be " + color.name);
    91 }
    92 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors.");
    94 successfullyParsed = true;
    96 </script>
    97 <script>finishTest();</script>
    99 </body>
   100 </html>

mercurial