2010-06-04 12:03:40 -07:00
|
|
|
<!--
|
|
|
|
Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
|
|
|
* Neither the name of Google Inc. nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
-->
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<link rel="stylesheet" href="../resources/js-test-style.css"/>
|
|
|
|
<script src="../resources/js-test-pre.js"></script>
|
|
|
|
<script src="resources/webgl-test.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="description"></div>
|
|
|
|
<div id="console"></div>
|
|
|
|
|
2010-07-16 07:30:32 -07:00
|
|
|
<script>
|
|
|
|
description("Tests that index validation verifies the correct number of indices");
|
|
|
|
|
2010-08-25 16:09:26 -07:00
|
|
|
function sizeInBytes(type) {
|
|
|
|
switch (type) {
|
|
|
|
case gl.BYTE:
|
|
|
|
case gl.UNSIGNED_BYTE:
|
|
|
|
return 1;
|
|
|
|
case gl.SHORT:
|
|
|
|
case gl.UNSIGNED_SHORT:
|
|
|
|
return 2;
|
|
|
|
case gl.INT:
|
|
|
|
case gl.UNSIGNED_INT:
|
|
|
|
case gl.FLOAT:
|
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
throw "unknown type";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-16 07:30:32 -07:00
|
|
|
var gl = create3DContext();
|
|
|
|
var program = loadStandardProgram(gl);
|
|
|
|
|
|
|
|
// 3 vertices => 1 triangle, interleaved data
|
|
|
|
var dataComplete = new Float32Array([0, 0, 0, 1,
|
|
|
|
0, 0, 1,
|
|
|
|
1, 0, 0, 1,
|
|
|
|
0, 0, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
0, 0, 1]);
|
|
|
|
var dataIncomplete = new Float32Array([0, 0, 0, 1,
|
|
|
|
0, 0, 1,
|
|
|
|
1, 0, 0, 1,
|
|
|
|
0, 0, 1,
|
|
|
|
1, 1, 1, 1]);
|
|
|
|
var indices = new Uint16Array([0, 1, 2]);
|
|
|
|
|
|
|
|
debug("Testing with valid indices");
|
|
|
|
|
|
|
|
var bufferComplete = gl.createBuffer();
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, bufferComplete);
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dataComplete, gl.STATIC_DRAW);
|
|
|
|
var elements = gl.createBuffer();
|
|
|
|
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, elements);
|
|
|
|
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
|
|
|
gl.useProgram(program);
|
|
|
|
var vertexLoc = gl.getAttribLocation(program, "a_vertex");
|
|
|
|
var normalLoc = gl.getAttribLocation(program, "a_normal");
|
2010-08-25 16:09:26 -07:00
|
|
|
gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
|
2010-07-16 07:30:32 -07:00
|
|
|
gl.enableVertexAttribArray(vertexLoc);
|
2010-08-25 16:09:26 -07:00
|
|
|
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
|
2010-07-16 07:30:32 -07:00
|
|
|
gl.enableVertexAttribArray(normalLoc);
|
|
|
|
shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
2010-07-16 07:30:32 -07:00
|
|
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
2010-07-16 07:30:32 -07:00
|
|
|
|
|
|
|
debug("Testing with out-of-range indices");
|
|
|
|
|
|
|
|
var bufferIncomplete = gl.createBuffer();
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, bufferIncomplete);
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dataIncomplete, gl.STATIC_DRAW);
|
2010-08-25 16:09:26 -07:00
|
|
|
gl.vertexAttribPointer(vertexLoc, 4, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 0);
|
2010-07-16 07:30:32 -07:00
|
|
|
gl.enableVertexAttribArray(vertexLoc);
|
|
|
|
gl.disableVertexAttribArray(normalLoc);
|
|
|
|
debug("Enable vertices, valid");
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
2010-07-16 07:30:32 -07:00
|
|
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
2010-07-16 07:30:32 -07:00
|
|
|
debug("Enable normals, out-of-range");
|
2010-08-25 16:09:26 -07:00
|
|
|
gl.vertexAttribPointer(normalLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
|
2010-07-16 07:30:32 -07:00
|
|
|
gl.enableVertexAttribArray(normalLoc);
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
2010-07-16 07:30:32 -07:00
|
|
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.INVALID_OPERATION);
|
2010-07-16 07:30:32 -07:00
|
|
|
|
|
|
|
debug("Test with enabled attribute that does not belong to current program");
|
|
|
|
|
|
|
|
gl.disableVertexAttribArray(normalLoc);
|
|
|
|
var extraLoc = Math.max(vertexLoc, normalLoc) + 1;
|
|
|
|
gl.enableVertexAttribArray(extraLoc);
|
|
|
|
debug("Enable an extra attribute with null");
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
2010-07-16 07:30:32 -07:00
|
|
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.INVALID_OPERATION);
|
2010-07-16 07:30:32 -07:00
|
|
|
debug("Enable an extra attribute with insufficient data buffer");
|
2010-08-25 16:09:26 -07:00
|
|
|
gl.vertexAttribPointer(extraLoc, 3, gl.FLOAT, false, 7 * sizeInBytes(gl.FLOAT), 4 * sizeInBytes(gl.FLOAT));
|
|
|
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
2010-07-16 07:30:32 -07:00
|
|
|
shouldBeUndefined('gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0)');
|
2010-08-25 16:09:26 -07:00
|
|
|
glErrorShouldBe(gl, gl.NO_ERROR);
|
2010-07-16 07:30:32 -07:00
|
|
|
|
|
|
|
successfullyParsed = true;
|
|
|
|
</script>
|
2010-06-04 12:03:40 -07:00
|
|
|
|
|
|
|
<script src="../resources/js-test-post.js"></script>
|
|
|
|
</body>
|
|
|
|
</html>
|