summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/attribs/gl-vertex-attrib-zero-issues.html
blob: 9de94399118ca5ef7bb1a2e24b6402a5007e122b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Enable Vertex Attrib Zero Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<canvas id="example" width="50" height="50">
</canvas>
<div id="description"></div>
<div id="console"></div>
<script id="vshader" type="x-shader/x-vertex">
    attribute vec4 vPosition;
    void main()
    {
        gl_Position = vPosition;
    }
</script>

<script id="fshader" type="x-shader/x-fragment">
    void main()
    {
        gl_FragColor = vec4(0.0,1.0,0.0,1.0);
    }
</script>

<script>
"use strict";
description("Test some of the issues of the difference between attrib 0 on OpenGL vs WebGL");
debug("");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var g_program;
var g_attribLocation;
function setup(attribIndex) {
  var program = wtu.setupProgram(
      gl, ['vshader', 'fshader'], ['vPosition'], [attribIndex]);
  g_program = program;
  g_attribLocation = attribIndex;
  shouldBe("g_attribLocation", "gl.getAttribLocation(g_program, 'vPosition')");
  return program;
}

function setupVerts(numVerts) {
  var verts = [
     1.0,  1.0, 0.0,
    -1.0,  1.0, 0.0,
    -1.0, -1.0, 0.0,
     1.0,  1.0, 0.0,
    -1.0, -1.0, 0.0,
     1.0, -1.0, 0.0
  ];
  var positions = new Float32Array(numVerts * 3);
  var indices = new Uint16Array(numVerts);
  for (var ii = 0; ii < numVerts; ++ii) {
    var ndx = ii % 6;
    var dst = ii * 3;
    var src = ndx * 3;
    for (var jj = 0; jj < 3; ++jj) {
      positions[dst + jj] = verts[src + jj];
    }
    indices[ii] = ii;
  }
  var vertexObject = gl.createBuffer();
  gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
  gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
  var indexBuffer = gl.createBuffer();
  gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
  gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
}

var p0 = setup(0);
var p3 = setup(3);
setupVerts(60000);

for (var ii = 0; ii < 5; ++ii) {
  // test drawing with attrib 0
  gl.useProgram(p0);
  gl.enableVertexAttribArray(0);
  gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
  gl.clear(gl.COLOR_BUFFER_BIT);
  gl.drawElements(gl.TRIANGLES, 60000, gl.UNSIGNED_SHORT, 0);
  wtu.glErrorShouldBe(
      gl, gl.NO_ERROR,
      "drawing using attrib 0 with 6 verts");
  wtu.checkCanvas(gl, [0, 255, 0, 255], "canvas should be green");
  gl.disableVertexAttribArray(0);

  // test drawing without attrib 0
  gl.useProgram(p3);
  gl.enableVertexAttribArray(3);
  gl.vertexAttribPointer(3, 3, gl.FLOAT, false, 0, 0);
  gl.clear(gl.COLOR_BUFFER_BIT);
  gl.drawArrays(gl.TRIANGLES, 0, 60000);
  wtu.glErrorShouldBe(
      gl, gl.NO_ERROR,
      "drawing using attrib 3 with 60000 verts");
  wtu.checkCanvas(gl, [0, 255, 0, 255], "canvas should be green");
  gl.disableVertexAttribArray(3);

  // This second test of drawing without attrib0 uncovered a bug in chrome
  // where after the draw without attrib0 the attrib 0 emulation code disabled
  // attrib 0 and it was never re-enabled so this next draw failed.
  gl.useProgram(p3);
  gl.enableVertexAttribArray(3);
  gl.clear(gl.COLOR_BUFFER_BIT);
  gl.drawElements(gl.TRIANGLES, 60000, gl.UNSIGNED_SHORT, 0);
  wtu.glErrorShouldBe(
      gl, gl.NO_ERROR,
      "drawing using attrib 3 with 60000 verts");
  wtu.checkCanvas(gl, [0, 255, 0, 255], "canvas should be green");
  gl.disableVertexAttribArray(3);
}


var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>

</body>
</html>