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 ActiveTexture BindTexture conformance test.</title> |
| 33 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 34 <script src="../../resources/js-test-pre.js"></script> |
| 35 <script src="../resources/webgl-test.js"> </script> |
| 36 <script src="../resources/webgl-test-utils.js"></script> |
| 37 </head> |
| 38 <body> |
| 39 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></c
anvas> |
| 40 <canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></
canvas> |
| 41 <div id="description"></div> |
| 42 <div id="console"></div> |
| 43 <script id="vshader" type="x-shader/x-vertex"> |
| 44 uniform mat4 world; |
| 45 attribute vec3 vPosition; |
| 46 attribute vec2 texCoord0; |
| 47 varying vec2 texCoord; |
| 48 void main() |
| 49 { |
| 50 gl_Position = world * vec4(vPosition, 1); |
| 51 texCoord = texCoord0; |
| 52 } |
| 53 </script> |
| 54 <script> |
| 55 var gl; |
| 56 |
| 57 function init() |
| 58 { |
| 59 if (window.initNonKhronosFramework) { |
| 60 window.initNonKhronosFramework(false); |
| 61 } |
| 62 |
| 63 description( |
| 64 "Tests that glActiveTexture and glBindTexture work as expected" + |
| 65 "Specifically texture targets are per active texture unit."); |
| 66 |
| 67 var canvas2d = document.getElementById("canvas2d"); |
| 68 var ctx2d = canvas2d.getContext("2d"); |
| 69 |
| 70 var wtu = WebGLTestUtils; |
| 71 gl = wtu.create3DContext("example"); |
| 72 var program = wtu.setupProgram( |
| 73 gl, |
| 74 ["vshader", wtu.setupSimpleTextureFragmentShader(gl)], |
| 75 ['vPosition', 'texCoord0']); |
| 76 wtu.setupUnitQuad(gl); |
| 77 gl.disable(gl.DEPTH_TEST); |
| 78 gl.disable(gl.BLEND); |
| 79 glErrorShouldBe(gl, gl.NO_ERROR); |
| 80 |
| 81 var colors = [ |
| 82 [0,192,128,255], |
| 83 [128,64,255,255], |
| 84 [192,255,64,255], |
| 85 [200,0,255,255]]; |
| 86 |
| 87 // Make 4 textures by using 4 active texture units if available. |
| 88 var texunits = Math.min(colors.length, gl.getParameter(gl.MAX_COMBINED_TEXTURE
_IMAGE_UNITS)) |
| 89 var textures = []; |
| 90 for (var ii = 0; ii < texunits; ++ii) { |
| 91 var tex = gl.createTexture(); |
| 92 gl.activeTexture(gl.TEXTURE0 + ii); |
| 93 gl.bindTexture(gl.TEXTURE_2D, tex); |
| 94 textures[ii] = tex; |
| 95 } |
| 96 glErrorShouldBe(gl, gl.NO_ERROR); |
| 97 |
| 98 // now use each texture unit to write into the textures, |
| 99 for (var ii = 0; ii < texunits; ++ii) { |
| 100 var c = colors[ii]; |
| 101 ctx2d.fillStyle = |
| 102 "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")"; |
| 103 ctx2d.fillRect(0, 0, 1, 1); |
| 104 gl.activeTexture(gl.TEXTURE0 + ii); |
| 105 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d
); |
| 106 } |
| 107 glErrorShouldBe(gl, gl.NO_ERROR); |
| 108 |
| 109 var textureLoc = gl.getUniformLocation(program, "tex"); |
| 110 var worldLoc = gl.getUniformLocation(program, "world"); |
| 111 glErrorShouldBe(gl, gl.NO_ERROR); |
| 112 |
| 113 gl.clearColor(1,0,0,1); |
| 114 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 115 |
| 116 for (var ii = 0; ii < texunits; ++ii) { |
| 117 var x = ii % 2; |
| 118 var y = Math.floor(ii / 2); |
| 119 gl.uniform1i(textureLoc, ii); |
| 120 gl.uniformMatrix4fv( |
| 121 worldLoc, false, |
| 122 [0.5, 0, 0, 0, |
| 123 0, 0.5, 0, 0, |
| 124 0, 0, 1, 0, |
| 125 -0.5 + x, -0.5 + y, 0, 1]); |
| 126 gl.drawArrays(gl.TRIANGLES, 0, 6); |
| 127 } |
| 128 glErrorShouldBe(gl, gl.NO_ERROR); |
| 129 |
| 130 for (var ii = 0; ii < texunits; ++ii) { |
| 131 var c = colors[ii]; |
| 132 var x = ii % 2; |
| 133 var y = Math.floor(ii / 2); |
| 134 var buf = new Uint8Array(4); |
| 135 gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 136 var msg = 'expected:' + |
| 137 c[0] + ', ' + c[1] + ', ' + c[2] + ', ' + c[3] + ' found: ' + |
| 138 buf[0] + ', ' + |
| 139 buf[1] + ', ' + |
| 140 buf[2] + ', ' + |
| 141 buf[3]; |
| 142 if (buf[0] != c[0] || |
| 143 buf[1] != c[1] || |
| 144 buf[2] != c[2] || |
| 145 buf[3] != c[3]) |
| 146 testFailed(msg); |
| 147 else |
| 148 testPassed(msg); |
| 149 } |
| 150 } |
| 151 |
| 152 init(); |
| 153 successfullyParsed = true; |
| 154 </script> |
| 155 |
| 156 <script src="../../resources/js-test-post.js"></script> |
| 157 |
| 158 </body> |
| 159 </html> |
| 160 |
OLD | NEW |