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 Texture Attachment Format Conformance Tests</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 <div id="description"></div> |
| 40 <div id="console"></div> |
| 41 <canvas id="canvas" width="2" height="2" style="width: 100px; height:100px; bord
er: 1px solid black;"> </canvas> |
| 42 <script> |
| 43 description(); |
| 44 |
| 45 var wtu = WebGLTestUtils; |
| 46 var gl = wtu.create3DContext(document.getElementById("canvas")); |
| 47 if (!gl) { |
| 48 testFailed("context does not exist"); |
| 49 } else { |
| 50 testPassed("context exists"); |
| 51 |
| 52 debug(""); |
| 53 debug("Checking texture formats."); |
| 54 |
| 55 var numValidFormats = 0; |
| 56 var clearColor = [0.25, 0.5, 0.75, 0.25]; |
| 57 |
| 58 var floatToBits = function(value, bits) { |
| 59 var range = (1 << bits) - 1; |
| 60 var result = 0; |
| 61 if (range > 0) { |
| 62 result = Math.floor(Math.floor(value * range) * 255 / range); |
| 63 } |
| 64 |
| 65 //debug("v = " + value + ", bits = " + bits + ", range = " + range + ", res
ult = " + result); |
| 66 return result; |
| 67 } |
| 68 |
| 69 function testFormat(info) { |
| 70 debug(""); |
| 71 debug("testing: " + info.format + ", " + info.type); |
| 72 |
| 73 var format = gl[info.format]; |
| 74 var type = gl[info.type]; |
| 75 |
| 76 gl.texImage2D(gl.TEXTURE_2D, |
| 77 0, // level |
| 78 format, // internalFormat |
| 79 16, // width |
| 80 16, // height |
| 81 0, // border |
| 82 format, // format |
| 83 type, // type |
| 84 null); // data |
| 85 var fbStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER); |
| 86 debug(wtu.glEnumToString(gl, fbStatus)); |
| 87 if (fbStatus != gl.FRAMEBUFFER_COMPLETE) { |
| 88 debug("format unsupported"); |
| 89 return; |
| 90 } |
| 91 |
| 92 ++numValidFormats; |
| 93 |
| 94 var startExpected = [0, 0, 0, info.channels[3] < 0 ? 255 : 0]; |
| 95 |
| 96 var expected = []; |
| 97 var tolerance = []; |
| 98 for (var ii = 0; ii < 4; ++ii) { |
| 99 var color = 0; |
| 100 var channel = info.channels[ii]; |
| 101 if (channel < 0) { |
| 102 color = ii < 3 ? 0 : 255 |
| 103 } else { |
| 104 color = floatToBits(clearColor[channel], info.bits[ii]); |
| 105 } |
| 106 expected.push(color); |
| 107 tolerance.push(channel < 0 ? 0 : (1 + (1 << (8 - info.bits[ii])))); |
| 108 } |
| 109 |
| 110 wtu.checkCanvas(gl, startExpected, "should be " + startExpected); |
| 111 gl.clear(gl.COLOR_BUFFER_BIT); |
| 112 wtu.checkCanvas(gl, expected, "should be " + expected + " with tolerance " +
tolerance, tolerance); |
| 113 } |
| 114 |
| 115 var validFormats = [ |
| 116 { format: 'RGBA', |
| 117 type: 'UNSIGNED_BYTE', |
| 118 channels: [0, 1, 2, 3], |
| 119 bits: [8, 8, 8, 8] |
| 120 }, |
| 121 { format: 'ALPHA', |
| 122 type: 'UNSIGNED_BYTE', |
| 123 channels: [-1, -1, -1, 3], |
| 124 bits: [0, 0, 0, 8] |
| 125 }, |
| 126 { format: 'RGB', |
| 127 type: 'UNSIGNED_BYTE', |
| 128 channels: [0, 1, 2, -1], |
| 129 bits: [8, 8, 8, 0] |
| 130 }, |
| 131 { format: 'RGB', |
| 132 type: 'UNSIGNED_SHORT_5_6_5', |
| 133 channels: [0, 1, 2, -1], |
| 134 bits: [5, 6, 5, 0] |
| 135 }, |
| 136 { format: 'RGBA', |
| 137 type: 'UNSIGNED_SHORT_5_5_5_1', |
| 138 channels: [0, 1, 2, 3], |
| 139 bits: [5, 5, 5, 1] |
| 140 }, |
| 141 { format: 'RGBA', |
| 142 type: 'UNSIGNED_SHORT_4_4_4_4', |
| 143 channels: [0, 1, 2, 3], |
| 144 bits: [4, 4, 4, 4] |
| 145 }, |
| 146 { format: 'LUMINANCE', |
| 147 type: 'UNSIGNED_BYTE', |
| 148 channels: [0, 0, 0, -1], |
| 149 bits: [8, 8, 8, -1] |
| 150 }, |
| 151 { format: 'LUMINANCE_ALPHA', |
| 152 type: 'UNSIGNED_BYTE', |
| 153 channels: [0, 0, 0, 3], |
| 154 bits: [8, 8, 8, 8] |
| 155 } |
| 156 ]; |
| 157 |
| 158 gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); |
| 159 fbo = gl.createFramebuffer(); |
| 160 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); |
| 161 var tex = gl.createTexture(); |
| 162 gl.bindTexture(gl.TEXTURE_2D, tex); |
| 163 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); |
| 164 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); |
| 165 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); |
| 166 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); |
| 167 gl.framebufferTexture2D( |
| 168 gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); |
| 169 |
| 170 for (var ii = 0; ii < validFormats.length; ++ii) { |
| 171 var info = validFormats[ii]; |
| 172 testFormat(info); |
| 173 } |
| 174 |
| 175 debug(""); |
| 176 shouldBeTrue("numValidFormats > 0"); |
| 177 glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); |
| 178 } |
| 179 |
| 180 debug(""); |
| 181 successfullyParsed = true; |
| 182 |
| 183 </script> |
| 184 <script src="../../resources/js-test-post.js"></script> |
| 185 |
| 186 </body> |
| 187 </html> |
OLD | NEW |