4 ** Copyright (c) 2013 The Khronos Group Inc.
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 <meta charset="utf-8">
32 <title>WebGL Frag Depth Conformance Tests</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../../conformance/resources/webgl-test-utils.js"></script>
38 <div id="description"></div>
39 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
40 <div id="console"></div>
41 <!-- Shaders for testing fragment depth writing -->
43 <!-- Shader omitting the required #version -->
44 <script id="missingPragmaFragmentShader" type="x-shader/x-fragment">
45 precision mediump float;
47 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
52 <!-- Shader with required #version -->
53 <script id="testFragmentShader" type="x-shader/x-fragment">
55 precision mediump float;
57 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
61 <!-- Shaders to link with test fragment shaders -->
62 <script id="goodVertexShader" type="x-shader/x-vertex">
63 attribute vec4 vPosition;
65 gl_Position = vPosition;
68 <!-- Shaders to test output -->
69 <script id="outputVertexShader" type="x-shader/x-vertex">
70 attribute vec4 vPosition;
72 gl_Position = vPosition;
75 <script id="outputFragmentShader" type="x-shader/x-fragment">
77 precision mediump float;
80 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
81 gl_FragDepthEXT = uDepth;
87 description("This test verifies the functionality of setting fragment depth in a shader.");
91 var wtu = WebGLTestUtils;
92 var canvas = document.getElementById("canvas");
93 var gl = wtu.create3DContext(canvas, null, 2);
96 testFailed("WebGL context does not exist");
98 testPassed("WebGL context exists");
104 function runShaderTests() {
106 debug("Testing various shader compiles");
108 // Always expect the shader missing the #version to fail
109 var missingPragmaFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "missingPragmaFragmentShader");
110 if (missingPragmaFragmentProgram) {
111 testFailed("Shader built-ins allowed without #version");
113 testPassed("Shader built-ins disallowed without #version");
116 // Try to compile a shader using the built-ins that should only succeed if enabled
117 var testFragmentProgram = wtu.loadProgramFromScriptExpectError(gl, "goodVertexShader", "testFragmentShader");
118 if (testFragmentProgram) {
119 testPassed("Shader built-ins compiled successfully");
121 testFailed("Shader built-ins failed to compile");
125 function runOutputTests() {
126 debug("Testing various draws for valid built-in function behavior");
128 canvas.width = 50; canvas.height = 50;
129 gl.viewport(0, 0, canvas.width, canvas.height);
131 // Enable depth testing with a clearDepth of 0.5
132 // This makes it so that fragments are only rendered when
133 // gl_fragDepth is < 0.5
135 gl.enable(gl.DEPTH_TEST);
139 var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition'], [0]);
140 var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
141 var depthUniform = gl.getUniformLocation(program, "uDepth");
143 // Draw 1: Greater than clear depth
144 gl.uniform1f(depthUniform, 1.0);
145 wtu.clearAndDrawUnitQuad(gl);
146 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 255, 255, 255]);
148 // Draw 2: Less than clear depth
149 gl.uniform1f(depthUniform, 0.0);
150 wtu.clearAndDrawUnitQuad(gl);
151 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [255, 0, 0, 255]);
155 var successfullyParsed = true;
157 <script src="../../resources/js-test-post.js"></script>