Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | <!-- |
michael@0 | 2 | Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 3 | Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | found in the LICENSE file. |
michael@0 | 5 | --> |
michael@0 | 6 | <!DOCTYPE html> |
michael@0 | 7 | <html> |
michael@0 | 8 | <head> |
michael@0 | 9 | <meta charset="utf-8"> |
michael@0 | 10 | <title>WebGL More than 65536 indices.</title> |
michael@0 | 11 | <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
michael@0 | 12 | <script src="../../resources/js-test-pre.js"></script> |
michael@0 | 13 | <script src="../resources/webgl-test.js"> </script> |
michael@0 | 14 | <script src="../resources/webgl-test-utils.js"> </script> |
michael@0 | 15 | </head> |
michael@0 | 16 | <body> |
michael@0 | 17 | <canvas id="example" width="40" height="40" style="width: 40px; height: 40px;"></canvas> |
michael@0 | 18 | <div id="description"></div> |
michael@0 | 19 | <div id="console"></div> |
michael@0 | 20 | <script id="vs" type="text/something-not-javascript"> |
michael@0 | 21 | attribute vec4 vPosition; |
michael@0 | 22 | attribute vec4 vColor; |
michael@0 | 23 | varying vec4 color; |
michael@0 | 24 | void main() { |
michael@0 | 25 | gl_Position = vPosition; |
michael@0 | 26 | color = vColor; |
michael@0 | 27 | } |
michael@0 | 28 | </script> |
michael@0 | 29 | <script id="fs" type="text/something-not-javascript"> |
michael@0 | 30 | precision mediump float; |
michael@0 | 31 | varying vec4 color; |
michael@0 | 32 | void main() { |
michael@0 | 33 | gl_FragColor = color; |
michael@0 | 34 | } |
michael@0 | 35 | </script> |
michael@0 | 36 | <script> |
michael@0 | 37 | description("checks that rendering with more than 65536 indices works."); |
michael@0 | 38 | var wtu = WebGLTestUtils; |
michael@0 | 39 | // The antialias:false context creation attribute is a concession to some older and buggier drivers. |
michael@0 | 40 | var gl = initWebGL("example", "vs", "fs", ["vPosition", "vColor"], [0, 0, 0, 1], 1, { antialias: false }); |
michael@0 | 41 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after initWebGL"); |
michael@0 | 42 | var bufferObjects = wtu.setupUnitQuad(gl, 0, 1); |
michael@0 | 43 | gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[0]); |
michael@0 | 44 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ |
michael@0 | 45 | -1,1,0, 1,1,0, -1,-1,0, 1,-1,0, |
michael@0 | 46 | -1,1,0, 1,1,0, -1,-1,0, 1,-1,0]), gl.STATIC_DRAW); |
michael@0 | 47 | gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[1]); |
michael@0 | 48 | gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([ |
michael@0 | 49 | 255, 0, 0, 255, |
michael@0 | 50 | 255, 0, 0, 255, |
michael@0 | 51 | 255, 0, 0, 255, |
michael@0 | 52 | 255, 0, 0, 255, |
michael@0 | 53 | 0, 255, 0, 255, |
michael@0 | 54 | 0, 255, 0, 255, |
michael@0 | 55 | 0, 255, 0, 255, |
michael@0 | 56 | 0, 255, 0, 255]), gl.STATIC_DRAW); |
michael@0 | 57 | gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, false, 0, 0); |
michael@0 | 58 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after program setup"); |
michael@0 | 59 | gl.enable(gl.BLEND); |
michael@0 | 60 | gl.disable(gl.DEPTH_TEST); |
michael@0 | 61 | |
michael@0 | 62 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture"); |
michael@0 | 63 | var numQuads = Math.floor(65536 / 6) + 2; |
michael@0 | 64 | debug("numQuads: " + numQuads); |
michael@0 | 65 | debug("numPoints: " + numQuads * 6); |
michael@0 | 66 | var indexBuf = new ArrayBuffer(numQuads * 6); |
michael@0 | 67 | var indices = new Uint8Array(indexBuf); |
michael@0 | 68 | for (var ii = 0; ii < numQuads; ++ii) { |
michael@0 | 69 | var offset = ii * 6; |
michael@0 | 70 | var quad = (ii == (numQuads - 1)) ? 4 : 0; |
michael@0 | 71 | indices[offset + 0] = quad + 0; |
michael@0 | 72 | indices[offset + 1] = quad + 1; |
michael@0 | 73 | indices[offset + 2] = quad + 2; |
michael@0 | 74 | indices[offset + 3] = quad + 2; |
michael@0 | 75 | indices[offset + 4] = quad + 1; |
michael@0 | 76 | indices[offset + 5] = quad + 3; |
michael@0 | 77 | } |
michael@0 | 78 | var indexBuffer = gl.createBuffer(); |
michael@0 | 79 | gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); |
michael@0 | 80 | gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW); |
michael@0 | 81 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices"); |
michael@0 | 82 | gl.drawElements(gl.TRIANGLES, numQuads * 6, gl.UNSIGNED_BYTE, 0); |
michael@0 | 83 | wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing"); |
michael@0 | 84 | wtu.checkCanvas(gl, [0, 255, 0, 255], "Should be green."); |
michael@0 | 85 | |
michael@0 | 86 | successfullyParsed = true; |
michael@0 | 87 | </script> |
michael@0 | 88 | |
michael@0 | 89 | <script>finishTest();</script> |
michael@0 | 90 | |
michael@0 | 91 | </body> |
michael@0 | 92 | </html> |
michael@0 | 93 | |
michael@0 | 94 |