gl-vertexattribipointer.html (4076B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>WebGL vertexAttribIPointer Conformance Tests</title> 12 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 13 <script src="../../js/js-test-pre.js"></script> 14 <script src="../../js/webgl-test-utils.js"></script> 15 </head> 16 <body> 17 <div id="description"></div> 18 <div id="console"></div> 19 <canvas id="canvas" width="2" height="2"> </canvas> 20 <script> 21 "use strict"; 22 description("This test checks vertexAttribIPointer behaviors in WebGL 2."); 23 24 debug(""); 25 debug("Canvas.getContext"); 26 27 var wtu = WebGLTestUtils; 28 var gl = wtu.create3DContext("canvas", undefined, 2); 29 if (!gl) { 30 testFailed("context does not exist"); 31 } else { 32 testPassed("context exists"); 33 34 debug(""); 35 debug("Checking gl.vertexAttribIPointer."); 36 37 gl.vertexAttribIPointer(0, 3, gl.INT, 0, 0); 38 wtu.glErrorShouldBe(gl, gl.NO_ERROR, 39 "vertexAttribIPointer should succeed if no buffer is bound and offset is zero"); 40 41 gl.vertexAttribIPointer(0, 3, gl.INT, 0, 12); 42 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, 43 "vertexAttribIPointer should fail if no buffer is bound and offset is non-zero"); 44 45 var vertexObject = gl.createBuffer(); 46 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); 47 gl.bufferData(gl.ARRAY_BUFFER, new Int32Array(0), gl.STATIC_DRAW); 48 49 gl.vertexAttribIPointer(0, 1, gl.FLOAT, 0, 0); 50 wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, 51 "vertexAttribIPointer should not support FLOAT"); 52 53 var checkVertexAttribIPointer = function( 54 gl, err, reason, size, type, stride, offset) { 55 gl.vertexAttribIPointer(0, size, type, stride, offset); 56 wtu.glErrorShouldBe(gl, err, 57 "gl.vertexAttribIPointer(0, " + size + 58 ", gl." + wtu.glEnumToString(gl, type) + 59 ", " + stride + 60 ", " + offset + 61 ") should " + (err == gl.NO_ERROR ? "succeed " : "fail ") + reason); 62 } 63 64 var types = [ 65 { type:gl.BYTE, bytesPerComponent: 1 }, 66 { type:gl.UNSIGNED_BYTE, bytesPerComponent: 1 }, 67 { type:gl.SHORT, bytesPerComponent: 2 }, 68 { type:gl.UNSIGNED_SHORT, bytesPerComponent: 2 }, 69 { type:gl.INT, bytesPerComponent: 4 }, 70 { type:gl.UNSIGNED_INT, bytesPerComponent: 4 }, 71 ]; 72 73 for (var ii = 0; ii < types.length; ++ii) { 74 var info = types[ii]; 75 debug(""); 76 for (var size = 1; size <= 4; ++size) { 77 debug(""); 78 debug("checking: " + wtu.glEnumToString(gl, info.type) + " with size " + size); 79 var bytesPerElement = size * info.bytesPerComponent; 80 var offsetSet = [ 81 0, 82 1, 83 info.bytesPerComponent - 1, 84 info.bytesPerComponent, 85 info.bytesPerComponent + 1, 86 info.bytesPerComponent * 2]; 87 for (var jj = 0; jj < offsetSet.length; ++jj) { 88 var offset = offsetSet[jj]; 89 for (var kk = 0; kk < offsetSet.length; ++kk) { 90 var stride = offsetSet[kk]; 91 var err = gl.NO_ERROR; 92 var reason = "" 93 if (offset % info.bytesPerComponent != 0) { 94 reason = "because offset is bad"; 95 err = gl.INVALID_OPERATION; 96 } 97 if (stride % info.bytesPerComponent != 0) { 98 reason = "because stride is bad"; 99 err = gl.INVALID_OPERATION; 100 } 101 checkVertexAttribIPointer( 102 gl, err, reason, size, info.type, stride, offset); 103 } 104 var stride = Math.floor(255 / info.bytesPerComponent) * info.bytesPerComponent; 105 106 if (offset == 0) { 107 checkVertexAttribIPointer( 108 gl, gl.NO_ERROR, "at stride limit", 109 size, info.type, stride, offset); 110 checkVertexAttribIPointer( 111 gl, gl.INVALID_VALUE, "over stride limit", 112 size, info.type, stride + info.bytesPerComponent, offset); 113 } 114 } 115 } 116 } 117 } 118 119 debug(""); 120 var successfullyParsed = true; 121 122 </script> 123 <script src="../../js/js-test-post.js"></script> 124 125 </body> 126 </html>