content/canvas/test/webgl-conformance/conformance/attribs/gl-vertexattribpointer.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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 vertexAttribPointer Conformance Tests</title>
michael@0 11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 12 <script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script>
michael@0 13 <script src="../../resources/js-test-pre.js"></script>
michael@0 14 <script src="../resources/webgl-test.js"></script>
michael@0 15 <script src="../resources/webgl-test-utils.js"></script>
michael@0 16 </head>
michael@0 17 <body>
michael@0 18 <div id="description"></div>
michael@0 19 <div id="console"></div>
michael@0 20 <canvas id="canvas" width="2" height="2"> </canvas>
michael@0 21 <script>
michael@0 22 description("This test checks vertexAttribPointer behaviors in WebGL.");
michael@0 23
michael@0 24 debug("");
michael@0 25 debug("Canvas.getContext");
michael@0 26
michael@0 27 var wtu = WebGLTestUtils;
michael@0 28 var gl = create3DContext(document.getElementById("canvas"));
michael@0 29 if (!gl) {
michael@0 30 testFailed("context does not exist");
michael@0 31 } else {
michael@0 32 testPassed("context exists");
michael@0 33
michael@0 34 debug("");
michael@0 35 debug("Checking gl.vertexAttribPointer.");
michael@0 36
michael@0 37 if (!gl.FIXED) {
michael@0 38 gl.FIXED = 0x140C;
michael@0 39 }
michael@0 40
michael@0 41 gl.vertexAttribPointer(0, 3, gl.FLOAT, 0, 0, 12);
michael@0 42 glErrorShouldBe(gl, gl.INVALID_OPERATION,
michael@0 43 "vertexAttribPointer should fail if no buffer is bound");
michael@0 44
michael@0 45 var vertexObject = gl.createBuffer();
michael@0 46 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
michael@0 47 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(0), gl.STATIC_DRAW);
michael@0 48
michael@0 49 gl.vertexAttribPointer(0, 1, gl.INT, 0, 0, 0);
michael@0 50 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 51 "vertexAttribPointer should not support INT");
michael@0 52 gl.vertexAttribPointer(0, 1, gl.UNSIGNED_INT, 0, 0, 0);
michael@0 53 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 54 "vertexAttribPointer should not support UNSIGNED_INT");
michael@0 55 gl.vertexAttribPointer(0, 1, gl.FIXED, 0, 0, 0);
michael@0 56 glErrorShouldBe(gl, gl.INVALID_ENUM,
michael@0 57 "vertexAttribPointer should not support FIXED");
michael@0 58
michael@0 59 function checkVertexAttribPointer(
michael@0 60 gl, err, reason, size, type, normalize, stride, offset) {
michael@0 61 gl.vertexAttribPointer(0, size, type, normalize, stride, offset);
michael@0 62 glErrorShouldBe(gl, err,
michael@0 63 "gl.vertexAttribPointer(0, " + size +
michael@0 64 ", gl." + wtu.glEnumToString(gl, type) +
michael@0 65 ", " + normalize +
michael@0 66 ", " + stride +
michael@0 67 ", " + offset +
michael@0 68 ") should " + (err == gl.NO_ERROR ? "succeed " : "fail ") + reason);
michael@0 69 }
michael@0 70
michael@0 71 var types = [
michael@0 72 { type:gl.BYTE, bytesPerComponent: 1 },
michael@0 73 { type:gl.UNSIGNED_BYTE, bytesPerComponent: 1 },
michael@0 74 { type:gl.SHORT, bytesPerComponent: 2 },
michael@0 75 { type:gl.UNSIGNED_SHORT, bytesPerComponent: 2 },
michael@0 76 { type:gl.FLOAT, bytesPerComponent: 4 },
michael@0 77 ];
michael@0 78
michael@0 79 for (var ii = 0; ii < types.length; ++ii) {
michael@0 80 var info = types[ii];
michael@0 81 debug("");
michael@0 82 for (var size = 1; size <= 4; ++size) {
michael@0 83 debug("");
michael@0 84 debug("checking: " + wtu.glEnumToString(gl, info.type) + " with size " + size);
michael@0 85 var bytesPerElement = size * info.bytesPerComponent;
michael@0 86 var offsetSet = [
michael@0 87 0,
michael@0 88 1,
michael@0 89 info.bytesPerComponent - 1,
michael@0 90 info.bytesPerComponent,
michael@0 91 info.bytesPerComponent + 1,
michael@0 92 info.bytesPerComponent * 2];
michael@0 93 for (var jj = 0; jj < offsetSet.length; ++jj) {
michael@0 94 var offset = offsetSet[jj];
michael@0 95 for (var kk = 0; kk < offsetSet.length; ++kk) {
michael@0 96 var stride = offsetSet[kk];
michael@0 97 var err = gl.NO_ERROR;
michael@0 98 var reason = ""
michael@0 99 if (offset % info.bytesPerComponent != 0) {
michael@0 100 reason = "because offset is bad";
michael@0 101 err = gl.INVALID_OPERATION;
michael@0 102 }
michael@0 103 if (stride % info.bytesPerComponent != 0) {
michael@0 104 reason = "because stride is bad";
michael@0 105 err = gl.INVALID_OPERATION;
michael@0 106 }
michael@0 107 checkVertexAttribPointer(
michael@0 108 gl, err, reason, size, info.type, false, stride, offset);
michael@0 109 }
michael@0 110 var stride = Math.floor(255 / info.bytesPerComponent) * info.bytesPerComponent;
michael@0 111
michael@0 112 if (offset == 0) {
michael@0 113 checkVertexAttribPointer(
michael@0 114 gl, gl.NO_ERROR, "at stride limit",
michael@0 115 size, info.type, false, stride, offset);
michael@0 116 checkVertexAttribPointer(
michael@0 117 gl, gl.INVALID_VALUE, "over stride limit",
michael@0 118 size, info.type, false,
michael@0 119 stride + info.bytesPerComponent, offset);
michael@0 120 }
michael@0 121 }
michael@0 122 }
michael@0 123 }
michael@0 124 }
michael@0 125
michael@0 126 debug("");
michael@0 127 successfullyParsed = true;
michael@0 128
michael@0 129 </script>
michael@0 130 <script>finishTest();</script>
michael@0 131
michael@0 132 </body>
michael@0 133 </html>

mercurial