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
167
168
169
170
171
172
173
174
175
176
177
178
|
<!--
/*
** Copyright (c) 2013 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL Frag Depth Conformance Tests</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>
<div id="description"></div>
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
<div id="console"></div>
<!-- Shaders for testing fragment depth writing -->
<!-- Shader omitting the required #version -->
<script id="fragmentShaderESSL1" type="x-shader/x-fragment">
precision mediump float;
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragDepth = 1.0;
}
</script>
<!-- Shader with required #version -->
<script id="fragmentShaderESSL3" type="x-shader/x-fragment">#version 300 es
precision mediump float;
out vec4 my_FragColor;
void main() {
my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragDepth = 1.0;
}
</script>
<!-- Shader using the EXT suffix -->
<script id="fragmentShaderESSL3EXT" type="x-shader/x-fragment">#version 300 es
precision mediump float;
out vec4 my_FragColor;
void main() {
my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragDepthEXT = 1.0;
}
</script>
<!-- Shaders to link with test fragment shaders -->
<script id="vertexShaderESSL1" type="x-shader/x-vertex">
attribute vec4 vPosition;
void main() {
gl_Position = vPosition;
}
</script>
<script id="vertexShaderESSL3" type="x-shader/x-vertex">#version 300 es
in vec4 vPosition;
void main() {
gl_Position = vPosition;
}
</script>
<!-- Shader to test output -->
<script id="outputFragmentShader" type="x-shader/x-fragment">#version 300 es
precision mediump float;
uniform float uDepth;
out vec4 my_FragColor;
void main() {
my_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
gl_FragDepth = uDepth;
}
</script>
<script>
"use strict";
description("This test verifies the functionality of setting fragment depth in a shader.");
debug("");
var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, null, 2);
if (!gl) {
testFailed("WebGL context does not exist");
} else {
testPassed("WebGL context exists");
runShaderTests();
debug("");
runOutputTests();
}
function runShaderTests() {
debug("");
debug("Testing various shader compiles");
// Always expect ESSL1 shaders to fail
var fragmentProgramESSL1 = wtu.loadProgramFromScriptExpectError(gl, "vertexShaderESSL1", "fragmentShaderESSL1");
if (fragmentProgramESSL1) {
testFailed("gl_FragDepth allowed in ESSL1 shader - should be disallowed");
} else {
testPassed("gl_FragDepth disallowed in ESSL1 shader");
}
// Try to compile a shader using the built-ins that should only succeed if enabled
var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "vertexShaderESSL3", "fragmentShaderESSL3");
if (testFragmentProgram) {
testPassed("gl_FragDepth allowed in ESSL3 shader");
} else {
testFailed("gl_FragDepth disallowed in ESSL3 shader");
}
var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "vertexShaderESSL3", "fragmentShaderESSL3EXT");
if (testFragmentProgram) {
testFailed("gl_FragDepthEXT allowed in ESSL3 shader - should only allow gl_FragDepth");
} else {
testPassed("gl_FragDepthEXT disallowed in ESSL3 shader");
}
}
function runOutputTests() {
debug("Testing rendering results from writing to gl_FragData");
canvas.width = 50; canvas.height = 50;
gl.viewport(0, 0, canvas.width, canvas.height);
// Enable depth testing with a clearDepth of 0.5
// This makes it so that fragments are only rendered when
// gl_FragDepth is < 0.5
gl.clearDepth(0.5);
gl.enable(gl.DEPTH_TEST);
var positionLoc = 0;
var texcoordLoc = 1;
var program = wtu.setupProgram(gl, ["vertexShaderESSL3", "outputFragmentShader"], ['vPosition'], [0]);
var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
var depthUniform = gl.getUniformLocation(program, "uDepth");
// Draw 1: Greater than clear depth
gl.uniform1f(depthUniform, 1.0);
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvas(gl, [255, 255, 255, 255]);
// Draw 2: Less than clear depth
gl.uniform1f(depthUniform, 0.0);
wtu.clearAndDrawUnitQuad(gl);
wtu.checkCanvas(gl, [255, 0, 0, 255]);
}
debug("");
var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>
|