| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 3 Use of this source code is governed by a BSD-style license that can be | |
| 4 found in the LICENSE file. | |
| 5 --> | |
| 6 <!DOCTYPE html> | |
| 7 <html> | |
| 8 <head> | |
| 9 <meta charset="utf-8"> | |
| 10 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
| 11 <script src="../resources/js-test-pre.js"></script> | |
| 12 <script src="resources/webgl-test.js"></script> | |
| 13 </head> | |
| 14 <body> | |
| 15 <canvas id="example" width="1px" height="1px"></canvas> | |
| 16 <div id="description"></div> | |
| 17 <div id="console"></div> | |
| 18 | |
| 19 <script id="vs" type="x-shader/x-vertex"> | |
| 20 attribute vec4 vPosition; | |
| 21 attribute vec4 vColor; | |
| 22 varying vec4 color; | |
| 23 void main() { | |
| 24 gl_Position = vPosition; | |
| 25 color = vColor; | |
| 26 } | |
| 27 </script> | |
| 28 <script id="fs" type="x-shader/x-fragment"> | |
| 29 precision mediump float; | |
| 30 varying vec4 color; | |
| 31 void main() { | |
| 32 gl_FragColor = color; | |
| 33 } | |
| 34 </script> | |
| 35 <script> | |
| 36 description('Test that updating the size of a vertex buffer is properly noticed
by the WebGL implementation.') | |
| 37 | |
| 38 var gl = initWebGL("example", "vs", "fs", ["vPosition", "vColor"], [0, 0, 0, 1],
1); | |
| 39 glErrorShouldBe(gl, gl.NO_ERROR, "after initialization"); | |
| 40 | |
| 41 gl.useProgram(gl.program); | |
| 42 var vertexObject = gl.createBuffer(); | |
| 43 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
| 44 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array( | |
| 45 [-1,1,0, 1,1,0, -1,-1,0, | |
| 46 -1,-1,0, 1,1,0, 1,-1,0]), gl.STATIC_DRAW); | |
| 47 gl.enableVertexAttribArray(0); | |
| 48 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); | |
| 49 glErrorShouldBe(gl, gl.NO_ERROR, "after vertex setup"); | |
| 50 | |
| 51 var texCoordObject = gl.createBuffer(); | |
| 52 gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject); | |
| 53 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array( | |
| 54 [0,0, 1,0, 0,1, | |
| 55 0,1, 1,0, 1,1]), gl.STATIC_DRAW); | |
| 56 gl.enableVertexAttribArray(1); | |
| 57 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); | |
| 58 glErrorShouldBe(gl, gl.NO_ERROR, "after texture coord setup"); | |
| 59 | |
| 60 // Now resize these buffers because we want to change what we're drawing. | |
| 61 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
| 62 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ | |
| 63 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0, | |
| 64 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl.STATIC_DRAW); | |
| 65 glErrorShouldBe(gl, gl.NO_ERROR, "after vertex redefinition"); | |
| 66 gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject); | |
| 67 gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([ | |
| 68 255, 0, 0, 255, | |
| 69 255, 0, 0, 255, | |
| 70 255, 0, 0, 255, | |
| 71 255, 0, 0, 255, | |
| 72 0, 255, 0, 255, | |
| 73 0, 255, 0, 255, | |
| 74 0, 255, 0, 255, | |
| 75 0, 255, 0, 255]), gl.STATIC_DRAW); | |
| 76 gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0); | |
| 77 glErrorShouldBe(gl, gl.NO_ERROR, "after texture coordinate / color redefinition"
); | |
| 78 | |
| 79 var numQuads = 2; | |
| 80 var indices = new Uint8Array(numQuads * 6); | |
| 81 for (var ii = 0; ii < numQuads; ++ii) { | |
| 82 var offset = ii * 6; | |
| 83 var quad = (ii == (numQuads - 1)) ? 4 : 0; | |
| 84 indices[offset + 0] = quad + 0; | |
| 85 indices[offset + 1] = quad + 1; | |
| 86 indices[offset + 2] = quad + 2; | |
| 87 indices[offset + 3] = quad + 2; | |
| 88 indices[offset + 4] = quad + 1; | |
| 89 indices[offset + 5] = quad + 3; | |
| 90 } | |
| 91 var indexObject = gl.createBuffer(); | |
| 92 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject); | |
| 93 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); | |
| 94 glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices"); | |
| 95 gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0); | |
| 96 glErrorShouldBe(gl, gl.NO_ERROR, "after drawing"); | |
| 97 | |
| 98 debug("") | |
| 99 successfullyParsed = true; | |
| 100 </script> | |
| 101 | |
| 102 <script src="../resources/js-test-post.js"></script> | |
| 103 </body> | |
| 104 </html> | |
| OLD | NEW |