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 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 33 <script src="../../resources/js-test-pre.js"></script> |
| 34 <script src="../resources/webgl-test.js"></script> |
| 35 </head> |
| 36 <body> |
| 37 <canvas id="example" width="1px" height="1px"></canvas> |
| 38 <div id="description"></div> |
| 39 <div id="console"></div> |
| 40 |
| 41 <script id="vs" type="x-shader/x-vertex"> |
| 42 attribute vec4 vPosition; |
| 43 attribute vec4 vColor; |
| 44 varying vec4 color; |
| 45 void main() { |
| 46 gl_Position = vPosition; |
| 47 color = vColor; |
| 48 } |
| 49 </script> |
| 50 <script id="fs" type="x-shader/x-fragment"> |
| 51 precision mediump float; |
| 52 varying vec4 color; |
| 53 void main() { |
| 54 gl_FragColor = color; |
| 55 } |
| 56 </script> |
| 57 <script> |
| 58 description('Test that updating the size of a vertex buffer is properly noticed
by the WebGL implementation.') |
| 59 |
| 60 var gl = initWebGL("example"); |
| 61 var program = setupProgram(gl, "vs", "fs", ["vPosition", "vColor"]); |
| 62 glErrorShouldBe(gl, gl.NO_ERROR, "after initialization"); |
| 63 |
| 64 var vertexObject = gl.createBuffer(); |
| 65 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 66 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array( |
| 67 [-1,1,0, 1,1,0, -1,-1,0, |
| 68 -1,-1,0, 1,1,0, 1,-1,0]), gl.STATIC_DRAW); |
| 69 gl.enableVertexAttribArray(0); |
| 70 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
| 71 glErrorShouldBe(gl, gl.NO_ERROR, "after vertex setup"); |
| 72 |
| 73 var texCoordObject = gl.createBuffer(); |
| 74 gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject); |
| 75 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array( |
| 76 [0,0, 1,0, 0,1, |
| 77 0,1, 1,0, 1,1]), gl.STATIC_DRAW); |
| 78 gl.enableVertexAttribArray(1); |
| 79 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); |
| 80 glErrorShouldBe(gl, gl.NO_ERROR, "after texture coord setup"); |
| 81 |
| 82 // Now resize these buffers because we want to change what we're drawing. |
| 83 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 84 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ |
| 85 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0, |
| 86 -1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl.STATIC_DRAW); |
| 87 glErrorShouldBe(gl, gl.NO_ERROR, "after vertex redefinition"); |
| 88 gl.bindBuffer(gl.ARRAY_BUFFER, texCoordObject); |
| 89 gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([ |
| 90 255, 0, 0, 255, |
| 91 255, 0, 0, 255, |
| 92 255, 0, 0, 255, |
| 93 255, 0, 0, 255, |
| 94 0, 255, 0, 255, |
| 95 0, 255, 0, 255, |
| 96 0, 255, 0, 255, |
| 97 0, 255, 0, 255]), gl.STATIC_DRAW); |
| 98 gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0); |
| 99 glErrorShouldBe(gl, gl.NO_ERROR, "after texture coordinate / color redefinition"
); |
| 100 |
| 101 var numQuads = 2; |
| 102 var indices = new Uint8Array(numQuads * 6); |
| 103 for (var ii = 0; ii < numQuads; ++ii) { |
| 104 var offset = ii * 6; |
| 105 var quad = (ii == (numQuads - 1)) ? 4 : 0; |
| 106 indices[offset + 0] = quad + 0; |
| 107 indices[offset + 1] = quad + 1; |
| 108 indices[offset + 2] = quad + 2; |
| 109 indices[offset + 3] = quad + 2; |
| 110 indices[offset + 4] = quad + 1; |
| 111 indices[offset + 5] = quad + 3; |
| 112 } |
| 113 var indexObject = gl.createBuffer(); |
| 114 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexObject); |
| 115 gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); |
| 116 glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices"); |
| 117 gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0); |
| 118 glErrorShouldBe(gl, gl.NO_ERROR, "after drawing"); |
| 119 |
| 120 debug("") |
| 121 successfullyParsed = true; |
| 122 </script> |
| 123 |
| 124 <script src="../../resources/js-test-post.js"></script> |
| 125 </body> |
| 126 </html> |
OLD | NEW |