gl-disabled-vertex-attrib.html (2097B)
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 Disabled Vertex Attrib Test</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 <canvas id="example" width="50" height="50"> 18 </canvas> 19 <div id="description"></div> 20 <div id="console"></div> 21 <script id="vshader" type="x-shader/x-vertex"> 22 attribute vec4 a_position; 23 attribute vec4 a_color; 24 varying vec4 v_color; 25 bool isCorrectColor(vec4 v) { 26 return v.x == 0.0 && v.y == 0.0 && v.z == 0.0 && v.w == 1.0; 27 } 28 void main() { 29 gl_Position = a_position; 30 v_color = isCorrectColor(a_color) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); 31 } 32 </script> 33 34 <script id="fshader" type="x-shader/x-fragment"> 35 precision mediump float; 36 varying vec4 v_color; 37 void main() { 38 gl_FragColor = v_color; 39 } 40 </script> 41 42 <script> 43 "use strict"; 44 var wtu = WebGLTestUtils; 45 description(); 46 47 var gl = wtu.create3DContext("example"); 48 49 var numVertexAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); 50 for (var ii = 0; ii < numVertexAttribs; ++ii) { 51 var colorLocation = (ii + 1) % numVertexAttribs; 52 var positionLocation = colorLocation ? 0 : 1; 53 54 if (positionLocation != 0) { 55 // We need to create a new 3d context for testing attrib 0 56 // since we've already effected attrib 0 on other tests. 57 gl = wtu.create3DContext(); 58 } 59 60 debug("testing attrib: " + colorLocation); 61 var program = wtu.setupProgram( 62 gl, 63 ['vshader', 'fshader'], 64 ['a_position', 'a_color'], 65 [positionLocation, colorLocation]); 66 var gridRes = 1; 67 wtu.setupIndexedQuad(gl, gridRes, positionLocation); 68 wtu.clearAndDrawIndexedQuad(gl, gridRes); 69 wtu.checkCanvas(gl, [0, 255, 0, 255], "should be green"); 70 } 71 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); 72 73 var successfullyParsed = true; 74 </script> 75 <script src="../../js/js-test-post.js"></script> 76 77 </body> 78 </html>