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