6 Copyright (c) 2019 The Khronos Group Inc.
7 Use of this source code is governed by an MIT-style license that can be
8 found in the LICENSE.txt file.
10 <link rel=
"stylesheet" type=
"text/css" href=
"../unit.css" />
11 <script type=
"application/javascript" src=
"../unit.js"></script>
12 <script type=
"application/javascript" src=
"../util.js"></script>
13 <script type=
"application/javascript">
15 var verts = [
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
0.0];
16 var normals = [
0.0,
0.0,
1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
1.0];
17 var texcoords = [
0.0,
0.0,
1.0,
0.0,
0.0,
1.0];
19 Tests.startUnit = function () {
20 var canvas = document.getElementById('gl');
21 var gl = wrapGLContext(getGLContext(canvas));
22 var prog = new Shader(gl, 'vert', 'frag');
24 var sh = prog.shader.program;
25 // log(gl.getShaderInfoLog(prog.shaders[
1]));
26 var v = gl.getAttribLocation(sh, 'Vertex');
27 var n = gl.getAttribLocation(sh, 'Normal');
28 var t = gl.getAttribLocation(sh, 'Tex');
29 return [gl,prog,v,n,t];
32 Tests.setup = function(gl, prog, v,n,t) {
33 assert(
0 == gl.getError());
34 return [gl, prog, v,n,t];
36 Tests.teardown = function(gl, prog, v,n,t) {
37 gl.disableVertexAttribArray(v);
38 gl.disableVertexAttribArray(n);
39 gl.disableVertexAttribArray(t);
42 Tests.endUnit = function(gl, prog, v,n,t) {
47 Tests.testVertexAttrib = function(gl, prog, v,n,t) {
48 var vbo = gl.createBuffer();
49 var vertsArr = new Float32Array(verts);
50 gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
51 gl.bufferData(gl.ARRAY_BUFFER, vertsArr, gl.STATIC_DRAW);
52 gl.enableVertexAttribArray(v);
53 gl.vertexAttribPointer(v,
3, gl.FLOAT, false,
0,
0);
54 assertFail(
"bad index",
55 function(){gl.vertexAttrib1f(-
1,
1);});
56 assertFail(
"bad index (big negative)",
57 function(){gl.vertexAttrib1f(-
69092342,
1);});
58 assertFail(
"bad index (big positive)",
59 function(){gl.vertexAttrib1f(
58928938,
1);});
60 assertOk(
"array too large",
61 function(){gl.vertexAttrib1fv(v, [
1,
2,
3,
4,
5]);});
62 assertFail(
"array too small",
63 function(){gl.vertexAttrib1fv(v, []);});
65 function(){gl.drawArrays(gl.TRIANGLES,
0,
3);});
70 <script id=
"vert" type=
"x-shader/x-vertex">
71 attribute vec3 Vertex;
72 attribute vec3 Normal;
75 varying vec4 texCoord0;
78 gl_Position = vec4(Vertex * Normal,
1.0);
79 texCoord0 = vec4(Tex,
0.0,
0.0) + gl_Position;
82 <script id=
"frag" type=
"x-shader/x-fragment">
83 precision mediump float;
85 varying vec4 texCoord0;
94 <style>canvas{ position:absolute; }
</style>
96 <canvas id=
"gl" width=
"1" height=
"1"></canvas>