get-active-test.html (3843B)
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 <link rel="stylesheet" href="../../resources/js-test-style.css"/> 12 <script src="../../js/js-test-pre.js"></script> 13 <script src="../../js/webgl-test-utils.js"></script> 14 </head> 15 <body> 16 <div id="description"></div> 17 <div id="console"></div> 18 19 <script> 20 "use strict"; 21 description("Test of getActiveAttrib and getActiveUniform"); 22 23 var wtu = WebGLTestUtils; 24 var context = wtu.create3DContext(); 25 var context2 = wtu.create3DContext(); 26 var program = wtu.loadStandardProgram(context); 27 var program2 = wtu.loadProgramFromFile(context2, 28 "../../resources/intArrayUniformShader.vert", 29 "../../resources/noopUniformShader.frag"); 30 31 wtu.glErrorShouldBe(context, context.NO_ERROR); 32 shouldBe("context.getActiveUniform(program, 0).name", "'u_modelViewProjMatrix'"); 33 shouldBe("context.getActiveUniform(program, 0).type", "context.FLOAT_MAT4"); 34 shouldBe("context.getActiveUniform(program, 0).size", "1"); 35 shouldBeNull("context.getActiveUniform(program, 1)"); 36 wtu.glErrorShouldBe(context, context.INVALID_VALUE); 37 shouldBeNull("context.getActiveUniform(program, -1)"); 38 wtu.glErrorShouldBe(context, context.INVALID_VALUE); 39 shouldThrow("context.getActiveUniform(null, 0)"); 40 wtu.glErrorShouldBe(context, context.NO_ERROR); 41 42 // we don't know the order the attribs will appear. 43 var info = [ 44 context.getActiveAttrib(program, 0), 45 context.getActiveAttrib(program, 1) 46 ]; 47 for (var ii = 0; ii < info.length; ++ii) 48 shouldBeNonNull("info[ii]"); 49 50 var expected = [ 51 { name: 'a_normal', type: context.FLOAT_VEC3, size: 1 }, 52 { name: 'a_vertex', type: context.FLOAT_VEC4, size: 1 } 53 ]; 54 55 if (info[0].name != expected[0].name) { 56 var t = info[0]; 57 info[0] = info[1]; 58 info[1] = t; 59 } 60 61 for (var ii = 0; ii < info.length; ++ii) { 62 shouldBe("info[ii].name", "expected[ii].name"); 63 shouldBe("info[ii].type", "expected[ii].type"); 64 shouldBe("info[ii].size", "expected[ii].size"); 65 } 66 67 // we don't know the order the uniforms will appear. 68 var info2 = [ 69 context2.getActiveUniform(program2, 0), 70 context2.getActiveUniform(program2, 1) 71 ]; 72 for (var ii = 0; ii < info2.length; ++ii) 73 shouldBeNonNull("info2[ii]"); 74 75 var expected2 = [ 76 { name: 'ival', type: context2.INT, size: 1 }, 77 { name: 'ival2[0]', type: context2.INT, size: 2 } 78 ]; 79 80 if (info2[0].name != expected2[0].name) { 81 t = info2[0]; 82 info2[0] = info2[1]; 83 info2[1] = t; 84 } 85 86 for (var ii = 0; ii < info2.length; ++ii) { 87 shouldBe("info2[ii].name", "expected2[ii].name"); 88 shouldBe("info2[ii].type", "expected2[ii].type"); 89 shouldBe("info2[ii].size", "expected2[ii].size"); 90 } 91 92 shouldBeNull("context.getActiveAttrib(program, 2)"); 93 wtu.glErrorShouldBe(context, context.INVALID_VALUE); 94 shouldBeNull("context.getActiveAttrib(program, -1)"); 95 wtu.glErrorShouldBe(context, context.INVALID_VALUE); 96 shouldThrow("context.getActiveAttrib(null, 0)"); 97 wtu.glErrorShouldBe(context, context.NO_ERROR); 98 99 wtu.glErrorShouldBe(context2, context.NO_ERROR); 100 101 debug("Check trying to get attribs from different context"); 102 shouldBeNull("context2.getActiveAttrib(program, 0)"); 103 wtu.glErrorShouldBe(context2, context2.INVALID_OPERATION); 104 shouldBeNull("context2.getActiveUniform(program, 0)"); 105 wtu.glErrorShouldBe(context2, context2.INVALID_OPERATION); 106 107 debug("Check trying to get attribs from deleted program"); 108 context.deleteProgram(program); 109 shouldBeNull("context.getActiveUniform(program, 0)"); 110 wtu.glErrorShouldBe(context, context.INVALID_VALUE); 111 shouldBeNull("context.getActiveAttrib(program, 0)"); 112 wtu.glErrorShouldBe(context, context.INVALID_VALUE); 113 114 var successfullyParsed = true; 115 </script> 116 117 <script src="../../js/js-test-post.js"></script> 118 </body> 119 </html>