summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/rendering/point-specific-shader-variables.html
blob: 71f0bcad502fa78a3060d95ac2059323a22c85d7 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!--
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>Point-specific shader variables 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="c" width="64" height="64"></canvas>
<div id="description"></div>
<div id="console"></div>

<script id="vs-assign" type="x-shader/x-vertex">
attribute vec2 aPosition;

varying vec2 vPos;

void main()
{
    gl_Position = vec4(aPosition, 0, 1);
    vPos = aPosition;

    gl_PointSize = 1.0;
}
</script>

<script id="vs-conditional" type="x-shader/x-vertex">
uniform float renderingPoints; // not assigned, equal to 0.0
attribute vec2 aPosition;

varying vec2 vPos;

void main()
{
    gl_Position = vec4(aPosition, 0, 1);
    vPos = aPosition;

    if (renderingPoints > 0.0) {
        gl_PointSize = 1.0;
    }
}
</script>

<script id="fs-overwrite" type="x-shader/x-fragment">
varying mediump vec2 vPos;

void main()
{
    gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);
    gl_FragColor = vec4(vPos * -2.0, 0, 1);
}
</script>

<script id="fs-unused-branch" type="x-shader/x-fragment">
varying mediump vec2 vPos;
uniform mediump float uDefaultsToZero;

void main()
{
    gl_FragColor = vec4(vPos * -2.0, 0, 1);
    if (uDefaultsToZero == 1.0) {
        gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);
    }
}
</script>

<script>
"use strict";
description(document.title);

debug('This test verifies rendering with programs referencing shader variables specific to rendering of POINTS primitives.');

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("c", {depth: false});

var prog_overwrite = wtu.setupProgram(gl, ["vs-assign", "fs-overwrite"], ["aPosition"]);
var prog_branch = wtu.setupProgram(gl, ["vs-assign", "fs-unused-branch"], ["aPosition"]);
var prog_cond_overwrite = wtu.setupProgram(gl, ["vs-conditional", "fs-overwrite"], ["aPosition"]);
var prog_cond_branch = wtu.setupProgram(gl, ["vs-conditional", "fs-unused-branch"], ["aPosition"]);

var vertData = new Float32Array([
    -1, -1,
    +1, -1,
    -1, +1,
]);

var vertexObject = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
gl.bufferData(gl.ARRAY_BUFFER, vertData, gl.STATIC_DRAW);

gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);

//////////

debug("");
debug("prog-overwrite");

gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 0]); // Bottom-left

gl.useProgram(prog_overwrite);
gl.drawArrays(gl.TRIANGLES, 0, 3);

wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255, 255, 0, 255]); // Bottom-left
wtu.checkCanvasRect(gl, 63, 63, 1, 1, [0, 0, 0, 0]); // Top-right


//////////

debug("");
debug("prog-branch");

gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 0]); // Bottom-left

gl.useProgram(prog_branch);
gl.drawArrays(gl.TRIANGLES, 0, 3);

wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255, 255, 0, 255]); // Bottom-left
wtu.checkCanvasRect(gl, 63, 63, 1, 1, [0, 0, 0, 0]); // Top-right

//////////

debug("");
debug("prog-cond-overwrite");

gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 0]); // Bottom-left

gl.useProgram(prog_cond_overwrite);
gl.drawArrays(gl.TRIANGLES, 0, 3);

wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255, 255, 0, 255]); // Bottom-left
wtu.checkCanvasRect(gl, 63, 63, 1, 1, [0, 0, 0, 0]); // Top-right


//////////

debug("");
debug("prog-cond-branch");

gl.clear(gl.COLOR_BUFFER_BIT);
wtu.checkCanvasRect(gl, 0, 0, 1, 1, [0, 0, 0, 0]); // Bottom-left

gl.useProgram(prog_cond_branch);
gl.drawArrays(gl.TRIANGLES, 0, 3);

wtu.checkCanvasRect(gl, 0, 0, 1, 1, [255, 255, 0, 255]); // Bottom-left
wtu.checkCanvasRect(gl, 63, 63, 1, 1, [0, 0, 0, 0]); // Top-right

var successfullyParsed = true;
</script>

<script src="../../js/js-test-post.js"></script>

</body>
</html>