Skip to content

Commit

Permalink
Move EXT_clip_control to draft; add tests (#3568)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexaknyazev authored Jul 27, 2023
1 parent 0343b57 commit be635cc
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<proposal href="proposals/EXT_clip_control/">
<draft href="EXT_clip_control/">
<name>EXT_clip_control</name>

<contact> <a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL
Expand All @@ -9,7 +9,7 @@
<contributor>Members of the WebGL working group</contributor>
</contributors>

<number>NN</number>
<number>51</number>

<depends>
<api version="1.0"/>
Expand Down Expand Up @@ -72,4 +72,4 @@ interface EXT_clip_control {
<change>Initial Draft.</change>
</revision>
</history>
</proposal>
</draft>
1 change: 1 addition & 0 deletions sdk/tests/conformance/extensions/00_test_list.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--min-version 1.0.3 --max-version 1.9.9 angle-instanced-arrays.html
--min-version 1.0.3 --max-version 1.9.9 angle-instanced-arrays-out-of-bounds.html
--min-version 1.0.3 --max-version 1.9.9 ext-blend-minmax.html
--min-version 1.0.4 ext-clip-control.html
--min-version 1.0.4 ext-color-buffer-half-float.html
--min-version 1.0.4 ext-float-blend.html
--min-version 1.0.4 ext-texture-compression-bptc.html
Expand Down
185 changes: 185 additions & 0 deletions sdk/tests/conformance/extensions/ext-clip-control.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<!--
Copyright (c) 2023 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 EXT_clip_control 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>
<canvas width="32" height="32" id="c"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("This test verifies the functionality of the EXT_clip_control extension, if it is available.");

debug("");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("c");
var ext;
const w = gl.drawingBufferWidth;
const h = gl.drawingBufferHeight;

function runTestNoExtension() {
debug("");
debug("Check the parameters without the extension");
shouldBeNull("gl.getParameter(0x935C /* CLIP_ORIGIN_EXT */)");
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "parameter unknown without enabling the extension");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
shouldBeNull("gl.getParameter(0x935D /* CLIP_DEPTH_MODE_EXT */)");
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, "parameter unknown without enabling the extension");
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
}

function checkEnums() {
debug("");
debug("Check enums");
shouldBe("ext.LOWER_LEFT_EXT", "0x8CA1");
shouldBe("ext.UPPER_LEFT_EXT", "0x8CA2");

shouldBe("ext.NEGATIVE_ONE_TO_ONE_EXT", "0x935E");
shouldBe("ext.ZERO_TO_ONE_EXT", "0x935F");

shouldBe("ext.CLIP_ORIGIN_EXT", "0x935C");
shouldBe("ext.CLIP_DEPTH_MODE_EXT", "0x935D");
}

function checkQueries() {
debug("");
debug("Check default state");
shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.LOWER_LEFT_EXT');
shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.NEGATIVE_ONE_TO_ONE_EXT');
debug("");
debug("Check state updates using the new function");
ext.clipControlEXT(ext.UPPER_LEFT_EXT, ext.ZERO_TO_ONE_EXT);
shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.UPPER_LEFT_EXT');
shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.ZERO_TO_ONE_EXT');
ext.clipControlEXT(ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT);
shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.LOWER_LEFT_EXT');
shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.ZERO_TO_ONE_EXT');
ext.clipControlEXT(ext.UPPER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT);
shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.UPPER_LEFT_EXT');
shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.NEGATIVE_ONE_TO_ONE_EXT');
ext.clipControlEXT(ext.LOWER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT);
shouldBe('gl.getParameter(ext.CLIP_ORIGIN_EXT)', 'ext.LOWER_LEFT_EXT');
shouldBe('gl.getParameter(ext.CLIP_DEPTH_MODE_EXT)', 'ext.NEGATIVE_ONE_TO_ONE_EXT');
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
}

function checkDepthMode() {
debug("");
debug("Check depth mode toggling");

gl.enable(gl.DEPTH_TEST);
gl.clear(gl.DEPTH_BUFFER_BIT);

const program = wtu.setupProgram(gl, [wtu.simpleVertexShader,
wtu.simpleColorFragmentShader]);
gl.useProgram(program);
const colorLoc = gl.getUniformLocation(program, "u_color");
wtu.setupUnitQuad(gl);

// Draw red at 0 with the default depth mode
gl.uniform4f(colorLoc, 1, 0, 0, 1);
ext.clipControlEXT(ext.LOWER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, w, h, [255, 0, 0, 255]);

// Draw green at 0, depth test must fail
gl.uniform4f(colorLoc, 0, 1, 0, 1);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, w, h, [255, 0, 0, 255]);

// Draw green at 0 after switching the depth mode
ext.clipControlEXT(ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, w, h, [0, 255, 0, 255]);

wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
}

function checkClipOrigin() {
debug("");
debug("Check clip origin toggling");

gl.disable(gl.DEPTH_TEST);

const vertexShader = `
attribute vec4 vPosition;
varying float y;
void main() {
gl_Position = vPosition;
y = vPosition.y;
}`;
const fragmentShader = `
precision mediump float;
varying float y;
void main() {
if (y > 0.0) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
} else {
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
}
}`;

const program = wtu.setupProgram(gl, [vertexShader, fragmentShader]);
gl.useProgram(program);

wtu.setupUnitQuad(gl);

ext.clipControlEXT(ext.LOWER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, w, h / 2 - 2, [0, 255, 0, 255]);
wtu.checkCanvasRect(gl, 0, h / 2 + 2, w, h / 2 - 2, [255, 0, 0, 255]);

ext.clipControlEXT(ext.UPPER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT);
wtu.drawUnitQuad(gl);
wtu.checkCanvasRect(gl, 0, 0, w, h / 2 - 2, [255, 0, 0, 255]);
wtu.checkCanvasRect(gl, 0, h / 2 + 2, w, h / 2 - 2, [0, 255, 0, 255]);

wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
}

function runTestExtension() {
checkEnums();
checkQueries();
checkDepthMode();
checkClipOrigin();
}

function runTest() {
if (!gl) {
testFailed("WebGL context does not exist");
return;
}
testPassed("WebGL context exists");

runTestNoExtension();

ext = gl.getExtension("EXT_clip_control");

wtu.runExtensionSupportedTest(gl, "EXT_clip_control", ext !== null);

if (ext !== null) {
runTestExtension();
} else {
testPassed("No EXT_clip_control support -- this is legal");
}
}

runTest();

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

0 comments on commit be635cc

Please sign in to comment.