OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 /* |
| 3 ** Copyright (c) 2012 The Khronos Group Inc. |
| 4 ** |
| 5 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 6 ** copy of this software and/or associated documentation files (the |
| 7 ** "Materials"), to deal in the Materials without restriction, including |
| 8 ** without limitation the rights to use, copy, modify, merge, publish, |
| 9 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 10 ** permit persons to whom the Materials are furnished to do so, subject to |
| 11 ** the following conditions: |
| 12 ** |
| 13 ** The above copyright notice and this permission notice shall be included |
| 14 ** in all copies or substantial portions of the Materials. |
| 15 ** |
| 16 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 20 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 23 */ |
| 24 --> |
| 25 <!DOCTYPE html> |
| 26 <html> |
| 27 <head> |
| 28 <meta charset="utf-8"> |
| 29 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 30 <script src="../../resources/js-test-pre.js"></script> |
| 31 <script src="../resources/webgl-test.js"></script> |
| 32 </head> |
| 33 <body> |
| 34 <div id="description"></div> |
| 35 <div id="console"></div> |
| 36 |
| 37 <script> |
| 38 description("Tests that index validation verifies the correct number of indices"
); |
| 39 |
| 40 function sizeInBytes(type) { |
| 41 switch (type) { |
| 42 case gl.BYTE: |
| 43 case gl.UNSIGNED_BYTE: |
| 44 return 1; |
| 45 case gl.SHORT: |
| 46 case gl.UNSIGNED_SHORT: |
| 47 return 2; |
| 48 case gl.INT: |
| 49 case gl.UNSIGNED_INT: |
| 50 case gl.FLOAT: |
| 51 return 4; |
| 52 default: |
| 53 throw "unknown type"; |
| 54 } |
| 55 } |
| 56 |
| 57 var gl = create3DContext(); |
| 58 var program = loadStandardProgram(gl); |
| 59 |
| 60 // 3 vertices => 1 triangle, interleaved data |
| 61 var dataComplete = new Float32Array([0, 0, 0, 1, |
| 62 0, 0, 1, |
| 63 1, 0, 0, 1, |
| 64 0, 0, 1, |
| 65 1, 1, 1, 1, |
| 66 0, 0, 1]); |
| 67 var dataIncomplete = new Float32Array([0, 0, 0, 1, |
| 68 0, 0, 1, |
| 69 1, 0, 0, 1, |
| 70 0, 0, 1, |
| 71 1, 1, 1, 1]); |
| 72 var indices = new Uint16Array([0, 1, 2]); |
| 73 |
| 74 debug("Testing with valid indices"); |
| 75 |
| 76 var bufferComplete = gl.createBuffer(); |
| 77 gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete); |
| 78 gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW); |
| 79 var elements = gl.createBuffer(); |
| 80 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements); |
| 81 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); |
| 82 gl.useProgram(program); |
| 83 var vertexLoc = gl.getAttribLocation(program, "a_vertex"); |
| 84 var normalLoc = gl.getAttribLocation(program, "a_normal"); |
| 85 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
0); |
| 86 gl.enableVertexAttribArray(vertexLoc); |
| 87 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
4 * sizeInBytes(gl.FLOAT)); |
| 88 gl.enableVertexAttribArray(normalLoc); |
| 89 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE')
; |
| 90 glErrorShouldBe(gl, gl.NO_ERROR); |
| 91 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); |
| 92 glErrorShouldBe(gl, gl.NO_ERROR); |
| 93 |
| 94 debug("Testing with out-of-range indices"); |
| 95 |
| 96 var bufferIncomplete = gl.createBuffer(); |
| 97 gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete); |
| 98 gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW); |
| 99 gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
0); |
| 100 gl.enableVertexAttribArray(vertexLoc); |
| 101 gl.disableVertexAttribArray(normalLoc); |
| 102 debug("Enable vertices, valid"); |
| 103 glErrorShouldBe(gl, gl.NO_ERROR); |
| 104 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); |
| 105 glErrorShouldBe(gl, gl.NO_ERROR); |
| 106 debug("Enable normals, out-of-range"); |
| 107 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
4 * sizeInBytes(gl.FLOAT)); |
| 108 gl.enableVertexAttribArray(normalLoc); |
| 109 glErrorShouldBe(gl, gl.NO_ERROR); |
| 110 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); |
| 111 glErrorShouldBe(gl, gl.INVALID_OPERATION); |
| 112 |
| 113 debug("Test with enabled attribute that does not belong to current program"); |
| 114 |
| 115 gl.disableVertexAttribArray(normalLoc); |
| 116 var extraLoc = Math.max(vertexLoc, normalLoc) + 1; |
| 117 gl.enableVertexAttribArray(extraLoc); |
| 118 debug("Enable an extra attribute with null"); |
| 119 glErrorShouldBe(gl, gl.NO_ERROR); |
| 120 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); |
| 121 glErrorShouldBe(gl, gl.INVALID_OPERATION); |
| 122 debug("Enable an extra attribute with insufficient data buffer"); |
| 123 gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
4 * sizeInBytes(gl.FLOAT)); |
| 124 glErrorShouldBe(gl, gl.NO_ERROR); |
| 125 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); |
| 126 debug("Pass large negative index to vertexAttribPointer"); |
| 127 gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT),
-2000000000 * sizeInBytes(gl.FLOAT)); |
| 128 glErrorShouldBe(gl, gl.INVALID_VALUE); |
| 129 shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)'); |
| 130 |
| 131 successfullyParsed = true; |
| 132 </script> |
| 133 |
| 134 <script src="../../resources/js-test-post.js"></script> |
| 135 </body> |
| 136 </html> |
OLD | NEW |