OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 |
| 28 <!DOCTYPE html> |
| 29 <html> |
| 30 <head> |
| 31 <meta charset="utf-8"> |
| 32 <title>WebGL texture2D GLSL conformance test.</title> |
| 33 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> |
| 34 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/> |
| 35 <script src="../../../resources/js-test-pre.js"></script> |
| 36 <script src="../../resources/webgl-test.js"> </script> |
| 37 <script src="../../resources/webgl-test-utils.js"> </script> |
| 38 </head> |
| 39 <body> |
| 40 <canvas id="example" width="256" height="256" style="width: 16px; height: 16px;"
></canvas> |
| 41 <div id="description"></div> |
| 42 <div id="console"></div> |
| 43 <script id="vshader2d" type="x-shader/x-vertex"> |
| 44 attribute vec4 vPosition; |
| 45 attribute vec2 texCoord0; |
| 46 varying vec4 color; |
| 47 uniform sampler2D tex; |
| 48 uniform float lod; |
| 49 void main() { |
| 50 gl_Position = vPosition; |
| 51 color = texture2DLod(tex, texCoord0, lod); |
| 52 } |
| 53 </script> |
| 54 <script id="fshader2d" type="x-shader/x-fragment"> |
| 55 precision mediump float; |
| 56 varying vec4 color; |
| 57 void main() { |
| 58 gl_FragData[0] = color; |
| 59 } |
| 60 </script> |
| 61 <script> |
| 62 description("tests GLSL texture2DLod function"); |
| 63 |
| 64 var wtu = WebGLTestUtils; |
| 65 var canvas = document.getElementById("example"); |
| 66 |
| 67 shouldBe("canvas.width", "256"); |
| 68 shouldBe("canvas.height", "256"); |
| 69 |
| 70 var colors = [ |
| 71 {name: 'red', color:[255, 0, 0, 255]}, |
| 72 {name: 'green', color:[0, 255, 0, 255]}, |
| 73 {name: 'blue', color:[0, 0, 255, 255]}, |
| 74 {name: 'yellow', color:[255, 255, 0, 255]}, |
| 75 {name: 'magenta', color:[255, 0, 255, 255]}, |
| 76 {name: 'cyan', color:[0, 255, 255, 255]}, |
| 77 {name: 'pink', color:[255, 128, 128, 255]}, |
| 78 {name: 'gray', color:[128, 128, 128, 255]}, |
| 79 {name: 'light green', color:[128, 255, 128, 255]}, |
| 80 ]; |
| 81 |
| 82 var gl = wtu.create3DContext(canvas); |
| 83 if (gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0) { |
| 84 runTest(); |
| 85 } else { |
| 86 testPassed("MAX_VERTEX_TEXTURE_IMAGE_UNITS == 0, this is okay."); |
| 87 } |
| 88 |
| 89 function runTest() { |
| 90 var program = wtu.setupProgram( |
| 91 gl, ['vshader2d', 'fshader2d'], ['vPosition', 'texCoord0'], [0, 1]); |
| 92 wtu.setupUnitQuad(gl, 0, 1); |
| 93 |
| 94 shouldBe("colors.length", "9"); |
| 95 |
| 96 var tex = gl.createTexture(); |
| 97 gl.bindTexture(gl.TEXTURE_2D, tex); |
| 98 gl.texParameteri( |
| 99 gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR); |
| 100 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
| 101 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); |
| 102 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); |
| 103 |
| 104 for (var ii = 0; ii < colors.length; ++ii) { |
| 105 var color = colors[ii]; |
| 106 var size = Math.pow(2, colors.length - ii - 1); |
| 107 wtu.fillTexture(gl, tex, size, size, color.color, ii); |
| 108 } |
| 109 |
| 110 var loc = gl.getUniformLocation(program, "lod"); |
| 111 |
| 112 for (var ii = 0; ii < colors.length; ++ii) { |
| 113 gl.uniform1f(loc, ii); |
| 114 var color = colors[ii]; |
| 115 wtu.drawQuad(gl); |
| 116 wtu.checkCanvas( |
| 117 gl, color.color, |
| 118 "256x256 texture drawn to 256x256 dest with lod = " + ii + |
| 119 " should be " + color.name); |
| 120 } |
| 121 glErrorShouldBe(gl, gl.NO_ERROR, "Should be no errors."); |
| 122 } |
| 123 |
| 124 successfullyParsed = true; |
| 125 |
| 126 </script> |
| 127 <script src="../../../resources/js-test-post.js"></script> |
| 128 |
| 129 </body> |
| 130 </html> |
| 131 |
| 132 |
OLD | NEW |