1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/attribs/gl-vertexattribpointer.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,133 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<title>WebGL vertexAttribPointer Conformance Tests</title> 1.14 +<link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.15 +<script src="../../resources/desktop-gl-constants.js" type="text/javascript"></script> 1.16 +<script src="../../resources/js-test-pre.js"></script> 1.17 +<script src="../resources/webgl-test.js"></script> 1.18 +<script src="../resources/webgl-test-utils.js"></script> 1.19 +</head> 1.20 +<body> 1.21 +<div id="description"></div> 1.22 +<div id="console"></div> 1.23 +<canvas id="canvas" width="2" height="2"> </canvas> 1.24 +<script> 1.25 +description("This test checks vertexAttribPointer behaviors in WebGL."); 1.26 + 1.27 +debug(""); 1.28 +debug("Canvas.getContext"); 1.29 + 1.30 +var wtu = WebGLTestUtils; 1.31 +var gl = create3DContext(document.getElementById("canvas")); 1.32 +if (!gl) { 1.33 + testFailed("context does not exist"); 1.34 +} else { 1.35 + testPassed("context exists"); 1.36 + 1.37 + debug(""); 1.38 + debug("Checking gl.vertexAttribPointer."); 1.39 + 1.40 + if (!gl.FIXED) { 1.41 + gl.FIXED = 0x140C; 1.42 + } 1.43 + 1.44 + gl.vertexAttribPointer(0, 3, gl.FLOAT, 0, 0, 12); 1.45 + glErrorShouldBe(gl, gl.INVALID_OPERATION, 1.46 + "vertexAttribPointer should fail if no buffer is bound"); 1.47 + 1.48 + var vertexObject = gl.createBuffer(); 1.49 + gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); 1.50 + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(0), gl.STATIC_DRAW); 1.51 + 1.52 + gl.vertexAttribPointer(0, 1, gl.INT, 0, 0, 0); 1.53 + glErrorShouldBe(gl, gl.INVALID_ENUM, 1.54 + "vertexAttribPointer should not support INT"); 1.55 + gl.vertexAttribPointer(0, 1, gl.UNSIGNED_INT, 0, 0, 0); 1.56 + glErrorShouldBe(gl, gl.INVALID_ENUM, 1.57 + "vertexAttribPointer should not support UNSIGNED_INT"); 1.58 + gl.vertexAttribPointer(0, 1, gl.FIXED, 0, 0, 0); 1.59 + glErrorShouldBe(gl, gl.INVALID_ENUM, 1.60 + "vertexAttribPointer should not support FIXED"); 1.61 + 1.62 + function checkVertexAttribPointer( 1.63 + gl, err, reason, size, type, normalize, stride, offset) { 1.64 + gl.vertexAttribPointer(0, size, type, normalize, stride, offset); 1.65 + glErrorShouldBe(gl, err, 1.66 + "gl.vertexAttribPointer(0, " + size + 1.67 + ", gl." + wtu.glEnumToString(gl, type) + 1.68 + ", " + normalize + 1.69 + ", " + stride + 1.70 + ", " + offset + 1.71 + ") should " + (err == gl.NO_ERROR ? "succeed " : "fail ") + reason); 1.72 + } 1.73 + 1.74 + var types = [ 1.75 + { type:gl.BYTE, bytesPerComponent: 1 }, 1.76 + { type:gl.UNSIGNED_BYTE, bytesPerComponent: 1 }, 1.77 + { type:gl.SHORT, bytesPerComponent: 2 }, 1.78 + { type:gl.UNSIGNED_SHORT, bytesPerComponent: 2 }, 1.79 + { type:gl.FLOAT, bytesPerComponent: 4 }, 1.80 + ]; 1.81 + 1.82 + for (var ii = 0; ii < types.length; ++ii) { 1.83 + var info = types[ii]; 1.84 + debug(""); 1.85 + for (var size = 1; size <= 4; ++size) { 1.86 + debug(""); 1.87 + debug("checking: " + wtu.glEnumToString(gl, info.type) + " with size " + size); 1.88 + var bytesPerElement = size * info.bytesPerComponent; 1.89 + var offsetSet = [ 1.90 + 0, 1.91 + 1, 1.92 + info.bytesPerComponent - 1, 1.93 + info.bytesPerComponent, 1.94 + info.bytesPerComponent + 1, 1.95 + info.bytesPerComponent * 2]; 1.96 + for (var jj = 0; jj < offsetSet.length; ++jj) { 1.97 + var offset = offsetSet[jj]; 1.98 + for (var kk = 0; kk < offsetSet.length; ++kk) { 1.99 + var stride = offsetSet[kk]; 1.100 + var err = gl.NO_ERROR; 1.101 + var reason = "" 1.102 + if (offset % info.bytesPerComponent != 0) { 1.103 + reason = "because offset is bad"; 1.104 + err = gl.INVALID_OPERATION; 1.105 + } 1.106 + if (stride % info.bytesPerComponent != 0) { 1.107 + reason = "because stride is bad"; 1.108 + err = gl.INVALID_OPERATION; 1.109 + } 1.110 + checkVertexAttribPointer( 1.111 + gl, err, reason, size, info.type, false, stride, offset); 1.112 + } 1.113 + var stride = Math.floor(255 / info.bytesPerComponent) * info.bytesPerComponent; 1.114 + 1.115 + if (offset == 0) { 1.116 + checkVertexAttribPointer( 1.117 + gl, gl.NO_ERROR, "at stride limit", 1.118 + size, info.type, false, stride, offset); 1.119 + checkVertexAttribPointer( 1.120 + gl, gl.INVALID_VALUE, "over stride limit", 1.121 + size, info.type, false, 1.122 + stride + info.bytesPerComponent, offset); 1.123 + } 1.124 + } 1.125 + } 1.126 + } 1.127 +} 1.128 + 1.129 +debug(""); 1.130 +successfullyParsed = true; 1.131 + 1.132 +</script> 1.133 +<script>finishTest();</script> 1.134 + 1.135 +</body> 1.136 +</html>