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 Enable Vertex Attrib Zero Test</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 <canvas id="example" width="50" height="50"> |
| 40 </canvas> |
| 41 <div id="description"></div> |
| 42 <div id="console"></div> |
| 43 <script id="vshader" type="x-shader/x-vertex"> |
| 44 attribute vec4 vPosition; |
| 45 void main() |
| 46 { |
| 47 gl_Position = vPosition; |
| 48 } |
| 49 </script> |
| 50 |
| 51 <script id="fshader" type="x-shader/x-fragment"> |
| 52 void main() |
| 53 { |
| 54 gl_FragColor = vec4(0.0,0.0,0.0,0.0); |
| 55 } |
| 56 </script> |
| 57 |
| 58 <script> |
| 59 description("Test some of the issues of the difference between attrib 0 on OpenG
L vs WebGL"); |
| 60 debug(""); |
| 61 var wtu = WebGLTestUtils; |
| 62 var gl = wtu.create3DContext("example"); |
| 63 |
| 64 function setup(numVerts, attribIndex) { |
| 65 var program = wtu.setupProgram( |
| 66 gl, ['vshader', 'fshader'], ['vPosition'], [attribIndex]); |
| 67 // draw with something on attrib zero with a small number of vertices |
| 68 var vertexObject = gl.createBuffer(); |
| 69 g_program = program; |
| 70 g_attribLocation = attribIndex; |
| 71 shouldBe("g_attribLocation", "gl.getAttribLocation(g_program, 'vPosition')"); |
| 72 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 73 gl.bufferData( |
| 74 gl.ARRAY_BUFFER, new Float32Array(numVerts * 3), gl.STATIC_DRAW); |
| 75 gl.vertexAttribPointer(attribIndex, 3, gl.FLOAT, false, 0, 0); |
| 76 var indices = new Uint16Array(numVerts); |
| 77 for (var ii = 0; ii < numVerts; ++ii) { |
| 78 indices[ii] = ii; |
| 79 } |
| 80 var indexBuffer = gl.createBuffer(); |
| 81 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); |
| 82 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); |
| 83 return program; |
| 84 } |
| 85 |
| 86 var p1 = setup(3, 0); |
| 87 var p2 = setup(60000, 3); |
| 88 |
| 89 for (var ii = 0; ii < 5; ++ii) { |
| 90 gl.useProgram(p1); |
| 91 gl.enableVertexAttribArray(0); |
| 92 gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0); |
| 93 glErrorShouldBe( |
| 94 gl, gl.NO_ERROR, |
| 95 "drawing using attrib 0 with 3 verts"); |
| 96 |
| 97 gl.useProgram(p2); |
| 98 gl.enableVertexAttribArray(3); |
| 99 gl.drawArrays(gl.LINES, 0, 60000); |
| 100 glErrorShouldBe( |
| 101 gl, gl.NO_ERROR, |
| 102 "drawing using attrib 3 with 60000 verts"); |
| 103 } |
| 104 |
| 105 wtu.checkCanvas(gl, [0, 0, 0, 0], "canvas should be 0, 0, 0, 0"); |
| 106 |
| 107 successfullyParsed = true; |
| 108 </script> |
| 109 <script src="../../resources/js-test-post.js"></script> |
| 110 |
| 111 </body> |
| 112 </html> |
| 113 |
OLD | NEW |