2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>WebGL Frag Depth Conformance Tests
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <canvas id=
"canvas" style=
"width: 50px; height: 50px;"> </canvas>
19 <div id=
"console"></div>
20 <!-- Shaders for testing fragment depth writing -->
22 <!-- Shader omitting the required #version -->
23 <script id=
"fragmentShaderESSL1" type=
"x-shader/x-fragment">
24 precision mediump float;
26 gl_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
30 <!-- Shader with required #version -->
31 <script id=
"fragmentShaderESSL3" type=
"x-shader/x-fragment">#version
300 es
32 precision mediump float;
33 out vec4 my_FragColor;
35 my_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
39 <!-- Shader using the EXT suffix -->
40 <script id=
"fragmentShaderESSL3EXT" type=
"x-shader/x-fragment">#version
300 es
41 precision mediump float;
42 out vec4 my_FragColor;
44 my_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
45 gl_FragDepthEXT =
1.0;
48 <!-- Shaders to link with test fragment shaders -->
49 <script id=
"vertexShaderESSL1" type=
"x-shader/x-vertex">
50 attribute vec4 vPosition;
52 gl_Position = vPosition;
55 <script id=
"vertexShaderESSL3" type=
"x-shader/x-vertex">#version
300 es
58 gl_Position = vPosition;
62 <!-- Shader to test output -->
63 <script id=
"outputFragmentShader" type=
"x-shader/x-fragment">#version
300 es
64 precision mediump float;
67 out vec4 my_FragColor;
69 my_FragColor = vec4(
1.0,
0.0,
0.0,
1.0);
70 gl_FragDepth = uDepth;
76 description("This test verifies the functionality of setting fragment depth in a shader.");
80 var wtu
= WebGLTestUtils
;
81 var canvas
= document
.getElementById("canvas");
82 var gl
= wtu
.create3DContext(canvas
, null, 2);
85 testFailed("WebGL context does not exist");
87 testPassed("WebGL context exists");
94 function runShaderTests() {
96 debug("Testing various shader compiles");
98 // Always expect ESSL1 shaders to fail
99 var fragmentProgramESSL1
= wtu
.loadProgramFromScriptExpectError(gl
, "vertexShaderESSL1", "fragmentShaderESSL1");
100 if (fragmentProgramESSL1
) {
101 testFailed("gl_FragDepth allowed in ESSL1 shader - should be disallowed");
103 testPassed("gl_FragDepth disallowed in ESSL1 shader");
106 // Try to compile a shader using the built-ins that should only succeed if enabled
107 var testFragmentProgram
= wtu
.loadProgramFromScriptExpectError(gl
, "vertexShaderESSL3", "fragmentShaderESSL3");
108 if (testFragmentProgram
) {
109 testPassed("gl_FragDepth allowed in ESSL3 shader");
111 testFailed("gl_FragDepth disallowed in ESSL3 shader");
114 var testFragmentProgram
= wtu
.loadProgramFromScriptExpectError(gl
, "vertexShaderESSL3", "fragmentShaderESSL3EXT");
115 if (testFragmentProgram
) {
116 testFailed("gl_FragDepthEXT allowed in ESSL3 shader - should only allow gl_FragDepth");
118 testPassed("gl_FragDepthEXT disallowed in ESSL3 shader");
122 function runOutputTests() {
123 debug("Testing rendering results from writing to gl_FragData");
125 canvas
.width
= 50; canvas
.height
= 50;
126 gl
.viewport(0, 0, canvas
.width
, canvas
.height
);
128 // Enable depth testing with a clearDepth of 0.5
129 // This makes it so that fragments are only rendered when
130 // gl_FragDepth is < 0.5
132 gl
.enable(gl
.DEPTH_TEST
);
136 var program
= wtu
.setupProgram(gl
, ["vertexShaderESSL3", "outputFragmentShader"], ['vPosition'], [0]);
137 var quadParameters
= wtu
.setupUnitQuad(gl
, 0, 1);
138 var depthUniform
= gl
.getUniformLocation(program
, "uDepth");
140 // Draw 1: Greater than clear depth
141 gl
.uniform1f(depthUniform
, 1.0);
142 wtu
.clearAndDrawUnitQuad(gl
);
143 wtu
.checkCanvas(gl
, [255, 255, 255, 255]);
145 // Draw 2: Less than clear depth
146 gl
.uniform1f(depthUniform
, 0.0);
147 wtu
.clearAndDrawUnitQuad(gl
);
148 wtu
.checkCanvas(gl
, [255, 0, 0, 255]);
152 var successfullyParsed
= true;
154 <script src=
"../../js/js-test-post.js"></script>