| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| <title>WebGL vertexAttribPointer Conformance Tests</title> |
| <script src="resources/desktop-gl-constants.js" type="text/javascript"></script> |
| <script src="../../../resources/js-test.js"></script> |
| <script src="resources/webgl-test.js"></script> |
| <script src="resources/webgl-test-utils.js"></script> |
| </head> |
| <body> |
| <div id="description"></div> |
| <div id="console"></div> |
| <canvas id="canvas" width="2" height="2"> </canvas> |
| <script> |
| description("This test checks vertexAttribPointer behaviors in WebGL."); |
| |
| debug(""); |
| debug("Canvas.getContext"); |
| |
| if (window.internals) |
| window.internals.settings.setWebGLErrorsToConsoleEnabled(false); |
| |
| var wtu = WebGLTestUtils; |
| var gl = create3DContext(document.getElementById("canvas")); |
| if (!gl) { |
| testFailed("context does not exist"); |
| } else { |
| testPassed("context exists"); |
| |
| debug(""); |
| debug("Checking gl.vertexAttribPointer."); |
| |
| if (!gl.FIXED) { |
| gl.FIXED = 0x140C; |
| } |
| |
| gl.vertexAttribPointer(0, 3, gl.FLOAT, 0, 0, 12); |
| glErrorShouldBe(gl, gl.INVALID_OPERATION, |
| "vertexAttribPointer should fail if no buffer is bound"); |
| |
| var vertexObject = gl.createBuffer(); |
| gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(0), gl.STATIC_DRAW); |
| |
| gl.vertexAttribPointer(0, 1, gl.INT, 0, 0, 0); |
| glErrorShouldBe(gl, gl.INVALID_ENUM, |
| "vertexAttribPointer should not support INT"); |
| gl.vertexAttribPointer(0, 1, gl.UNSIGNED_INT, 0, 0, 0); |
| glErrorShouldBe(gl, gl.INVALID_ENUM, |
| "vertexAttribPointer should not support UNSIGNED_INT"); |
| gl.vertexAttribPointer(0, 1, gl.FIXED, 0, 0, 0); |
| glErrorShouldBe(gl, gl.INVALID_ENUM, |
| "vertexAttribPointer should not support FIXED"); |
| |
| function checkVertexAttribPointer( |
| gl, err, reason, size, type, normalize, stride, offset) { |
| gl.vertexAttribPointer(0, size, type, normalize, stride, offset); |
| glErrorShouldBe(gl, err, |
| "gl.vertexAttribPointer(0, " + size + |
| ", gl." + wtu.glEnumToString(gl, type) + |
| ", " + normalize + |
| ", " + stride + |
| ", " + offset + |
| ") should " + (err == gl.NO_ERROR ? "succeed " : "fail ") + reason); |
| } |
| |
| var types = [ |
| { type:gl.BYTE, bytesPerComponent: 1 }, |
| { type:gl.UNSIGNED_BYTE, bytesPerComponent: 1 }, |
| { type:gl.SHORT, bytesPerComponent: 2 }, |
| { type:gl.UNSIGNED_SHORT, bytesPerComponent: 2 }, |
| { type:gl.FLOAT, bytesPerComponent: 4 }, |
| ]; |
| |
| for (var ii = 0; ii < types.length; ++ii) { |
| var info = types[ii]; |
| debug(""); |
| for (var size = 1; size <= 4; ++size) { |
| debug(""); |
| debug("checking: " + wtu.glEnumToString(gl, info.type) + " with size " + size); |
| var bytesPerElement = size * info.bytesPerComponent; |
| var offsetSet; |
| if (info.bytesPerComponent > 1) |
| offsetSet = [0, info.bytesPerComponent - 1]; |
| else |
| offsetSet = [0]; |
| for (var jj = 0; jj < offsetSet.length; ++jj) { |
| var offset = offsetSet[jj]; |
| var strideSet; |
| if (bytesPerElement > 1) |
| strideSet = [0, bytesPerElement - 1, bytesPerElement]; |
| else |
| strideSet = [0, bytesPerElement]; |
| for (var kk = 0; kk < strideSet.length; ++kk) { |
| var stride = strideSet[kk]; |
| var err = gl.NO_ERROR; |
| var reason = "" |
| if (offset != 0) { |
| reason = "because offset is bad"; |
| err = gl.INVALID_OPERATION; |
| } |
| if (stride % info.bytesPerComponent != 0) { |
| reason = "because stride is bad"; |
| err = gl.INVALID_OPERATION; |
| } |
| checkVertexAttribPointer( |
| gl, err, reason, size, info.type, false, stride, offset); |
| } |
| var stride = Math.floor(255 / info.bytesPerComponent) * info.bytesPerComponent; |
| |
| if (offset == 0) { |
| checkVertexAttribPointer( |
| gl, gl.NO_ERROR, "at stride limit", |
| size, info.type, false, stride, offset); |
| checkVertexAttribPointer( |
| gl, gl.INVALID_VALUE, "over stride limit", |
| size, info.type, false, |
| stride + info.bytesPerComponent, offset); |
| } |
| } |
| } |
| } |
| } |
| |
| debug(""); |
| |
| </script> |
| </body> |
| </html> |