summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/rendering/more-than-65536-indices.html
blob: 02a0fe594ec6dd8451719d9cf721453f0b9099be (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
<!--
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 More than 65536 indices.</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="1" height="1" style="width: 40px; height: 40px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script id="vs" type="text/something-not-javascript">
attribute vec4 vPosition;
attribute vec4 vColor;
varying vec4 color;
void main() {
    gl_Position = vPosition;
    gl_PointSize = 1.0;
    color = vColor;
}
</script>
<script id="fs" type="text/something-not-javascript">
precision mediump float;
varying vec4 color;
void main() {
    gl_FragColor = color;
}
</script>
<script>
"use strict";
description("checks that rendering with more than 65536 indices works.");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var program = wtu.setupProgram(gl, ["vs", "fs"], ["vPosition", "vColor"]);
var bufferObjects = wtu.setupUnitQuad(gl, 0, 1);

gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[0]);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
      -1,  1,
       1,  1,
      -1, -1,
       1, -1,
      -1,  1,
       1,  1,
      -1, -1,
       1, -1]), gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, bufferObjects[1]);
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([
      255, 0, 0, 255,
      255, 0, 0, 255,
      255, 0, 0, 255,
      255, 0, 0, 255,
      0, 255, 0, 255,
      0, 255, 0, 255,
      0, 255, 0, 255,
      0, 255, 0, 255]), gl.STATIC_DRAW);
gl.vertexAttribPointer(1, 4, gl.UNSIGNED_BYTE, true, 0, 0);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after program setup");

wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after creating texture");
var numQuads = Math.floor(65536 / 6) + 4;
var numPoints = numQuads * 6;
debug("numQuads: " + numQuads);
debug("numPoints: " + numPoints);
var indexBuf = new ArrayBuffer(numPoints);
var indices = new Uint8Array(indexBuf);
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setting up indices");

var modes = [
  {mode: 'POINTS',         offsets: [0, 1, 2, 3, 2, 1], skip: 0},
  {mode: 'LINES',          offsets: [0, 1, 2, 3, 2, 1], skip: 0},
  {mode: 'LINE_LOOP',      offsets: [0, 1, 2, 3, 2, 1], skip: 1},
  {mode: 'LINE_STRIP',     offsets: [0, 1, 2, 3, 2, 1], skip: 0},
  {mode: 'TRIANGLES',      offsets: [0, 1, 2, 3, 2, 1], skip: 0},
  {mode: 'TRIANGLE_STRIP', offsets: [0, 1, 2, 3, 2, 1], skip: 0},
  {mode: 'TRIANGLE_FAN',   offsets: [0, 1, 3, 2, 2, 1], skip: 1}
];

for (var mm = 0; mm < modes.length; ++mm) {
  var modeInfo = modes[mm];
  var mode = modeInfo.mode;
  var offsets = modeInfo.offsets;
  var skip = modeInfo.skip;

  for (var ii = 0; ii < numQuads; ++ii) {
    var offset = ii * 6;
    var quad = (ii == 0 || ii == (numQuads - 1)) ? 4 : 0;
    for (var jj = 0; jj < 6; ++jj) {
      indices[offset + jj] = quad + offsets[jj];
    }
  }
  gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);

  debug("");
  debug("testing: " + mode);
  // Draw without last 6 points.
  gl.drawElements(gl[mode], numPoints - (skip + 1) * 6, gl.UNSIGNED_BYTE, skip * 6);
  wtu.checkCanvas(gl, [255, 0, 0, 255], "Should be red.");
  // Draw with last 6 points.
  gl.drawElements(gl[mode], numPoints, gl.UNSIGNED_BYTE, 0);
  wtu.checkCanvas(gl, [0, 255, 0, 255], "Should be green.");
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after drawing");

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

</body>
</html>