Skip to content

Commit

Permalink
Move texture extensions to draft; add tests (#3576)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexaknyazev authored Aug 1, 2023
1 parent f4c305f commit 3e71f3b
Show file tree
Hide file tree
Showing 6 changed files with 498 additions and 8 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_texture_mirror_clamp_to_edge/">
<draft href="EXT_texture_mirror_clamp_to_edge/">
<name>EXT_texture_mirror_clamp_to_edge</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>62</number>

<depends>
<api version="1.0"/>
Expand Down Expand Up @@ -71,4 +71,4 @@ interface EXT_texture_mirror_clamp_to_edge {
<change>Initial Draft.</change>
</revision>
</history>
</proposal>
</draft>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<proposal href="proposals/WEBGL_stencil_texturing/">
<draft href="WEBGL_stencil_texturing/">
<name>WEBGL_stencil_texturing</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>61</number>

<depends>
<api version="2.0"/>
Expand All @@ -25,6 +25,7 @@
[Exposed=(Window,Worker), LegacyNoInterfaceObject]
interface WEBGL_stencil_texturing {
const GLenum DEPTH_STENCIL_TEXTURE_MODE_WEBGL = 0x90EA;
const GLenum STENCIL_INDEX_WEBGL = 0x1901;
};
</idl>

Expand All @@ -34,15 +35,15 @@ interface WEBGL_stencil_texturing {
<param name="pname" type="GLenum"/>
<param name="param" type="GLfloat"/>
A new enum <code>DEPTH_STENCIL_TEXTURE_MODE_WEBGL</code> is accepted as the <code>pname</code> parameter;
<code>param</code> must be <code>DEPTH_COMPONENT</code> (default) or <code>STENCIL_INDEX</code>.
<code>param</code> must be <code>DEPTH_COMPONENT</code> (default) or <code>STENCIL_INDEX_WEBGL</code>.
</function>

<function name="texParameteri" type="undefined">
<param name="target" type="GLenum"/>
<param name="pname" type="GLenum"/>
<param name="param" type="GLint"/>
A new enum <code>DEPTH_STENCIL_TEXTURE_MODE_WEBGL</code> is accepted as the <code>pname</code> parameter;
<code>param</code> must be <code>DEPTH_COMPONENT</code> (default) or <code>STENCIL_INDEX</code>.
<code>param</code> must be <code>DEPTH_COMPONENT</code> (default) or <code>STENCIL_INDEX_WEBGL</code>.
</function>

<function name="getTexParameter" type="any">
Expand All @@ -66,4 +67,4 @@ interface WEBGL_stencil_texturing {
<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
Expand Up @@ -13,6 +13,7 @@
--min-version 1.0.3 --max-version 1.9.9 ext-shader-texture-lod.html
--min-version 1.0.3 --max-version 1.9.9 ext-sRGB.html
--min-version 1.0.2 ext-texture-filter-anisotropic.html
--min-version 1.0.4 ext-texture-mirror-clamp-to-edge.html
--min-version 1.0.2 get-extension.html
--min-version 1.0.4 khr-parallel-shader-compile.html
--max-version 1.9.9 oes-standard-derivatives.html
Expand Down
217 changes: 217 additions & 0 deletions sdk/tests/conformance/extensions/ext-texture-mirror-clamp-to-edge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
<!--
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_texture_mirror_clamp_to_edge 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_texture_mirror_clamp_to_edge extension, if it is available.");

debug("");

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

const pnames = ['TEXTURE_WRAP_S', 'TEXTURE_WRAP_T'];
if (gl.TEXTURE_WRAP_R) {
pnames.push('TEXTURE_WRAP_R');
}

function runTestNoExtension() {
debug("");
debug("Check the texture parameter without the extension");

const tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);

const MIRROR_CLAMP_TO_EDGE_EXT = 0x8743;

for (const pname of pnames) {
gl.texParameteri(gl.TEXTURE_2D, gl[pname], MIRROR_CLAMP_TO_EDGE_EXT);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, `value unknown for ${pname} via texParameteri without enabling the extension`);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no more errors");
gl.texParameterf(gl.TEXTURE_2D, gl[pname], MIRROR_CLAMP_TO_EDGE_EXT);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, `value unknown for ${pname} via texParameterf without enabling the extension`);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no more errors");
}

if (!gl.createSampler) return;

const sampler = gl.createSampler();
for (const pname of pnames) {
gl.samplerParameteri(sampler, gl[pname], MIRROR_CLAMP_TO_EDGE_EXT);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, `value unknown for ${pname} via samplerParameteri without enabling the extension`);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no more errors");
gl.samplerParameterf(sampler, gl[pname], MIRROR_CLAMP_TO_EDGE_EXT);
wtu.glErrorShouldBe(gl, gl.INVALID_ENUM, `value unknown for ${pname} via samplerParameterf without enabling the extension`);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no more errors");
}
}

function checkEnums() {
debug("");
debug("Check enums");
shouldBe("ext.MIRROR_CLAMP_TO_EDGE_EXT", "0x8743");
}

function checkQueries() {
debug("");
debug("Check texture and sampler state updates");

const tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);

for (const pname of pnames) {
gl.texParameteri(gl.TEXTURE_2D, gl[pname], ext.MIRROR_CLAMP_TO_EDGE_EXT);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from texParameteri");
shouldBe(`gl.getTexParameter(gl.TEXTURE_2D, gl.${pname})`, "ext.MIRROR_CLAMP_TO_EDGE_EXT");
gl.texParameteri(gl.TEXTURE_2D, gl[pname], gl.REPEAT);

gl.texParameterf(gl.TEXTURE_2D, gl[pname], ext.MIRROR_CLAMP_TO_EDGE_EXT);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from texParameterf");
shouldBe(`gl.getTexParameter(gl.TEXTURE_2D, gl.${pname})`, "ext.MIRROR_CLAMP_TO_EDGE_EXT");
gl.texParameterf(gl.TEXTURE_2D, gl[pname], gl.REPEAT);
}

if (!gl.createSampler) return;

sampler = gl.createSampler();
for (const pname of pnames) {
gl.samplerParameteri(sampler, gl[pname], ext.MIRROR_CLAMP_TO_EDGE_EXT);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from samplerParameteri");
shouldBe(`gl.getSamplerParameter(sampler, gl.${pname})`, "ext.MIRROR_CLAMP_TO_EDGE_EXT");
gl.samplerParameteri(sampler, gl[pname], gl.REPEAT);

gl.samplerParameterf(sampler, gl[pname], ext.MIRROR_CLAMP_TO_EDGE_EXT);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors from samplerParameterf");
shouldBe(`gl.getSamplerParameter(sampler, gl.${pname})`, "ext.MIRROR_CLAMP_TO_EDGE_EXT");
gl.samplerParameterf(sampler, gl[pname], gl.REPEAT);
}
}

function checkSampling() {
debug("");
debug(`Check texture sampling with mirror-clamp-to-edge mode`);

wtu.setupUnitQuad(gl);
const vs = `precision highp float;
attribute vec4 vPosition;
varying vec2 texCoord;
void main() {
gl_Position = vec4(vPosition.xy, 0.0, 1.0);
texCoord = vPosition.xy * 2.0;
}`;
const program = wtu.setupProgram(gl, [vs, wtu.simpleTextureFragmentShader]);
gl.useProgram(program);

const black = [ 0, 0, 0, 255];
const red = [255, 0, 0, 255];
const green = [ 0, 255, 0, 255];
const blue = [ 0, 0, 255, 255];
const data = new Uint8Array([...black, ...red, ...green, ...blue]);

function checkPixels() {
function checkPixel(x, y, color) {
const screen = (s, t) => s * (t * 0.5 + 0.5);
wtu.checkCanvasRect(gl, screen(w, x), screen(h, y), 1, 1, color,
`(${x.toFixed(3)}, ${y.toFixed(3)}): ${color} `);
}
for (const signX of [+1, -1]) {
for (const signY of [+1, -1]) {
// This function expects screen-space coordinates
// normalized to [-1, +1]. The region from [0, 0]
// to [+1, +1] behaves like regular clamp-to-edge.
// Other three quadrants should be mirrored.
checkPixel(signX * 0.125, signY * 0.125, black);
checkPixel(signX * 0.375, signY * 0.125, red);
checkPixel(signX * 0.750, signY * 0.125, red);
checkPixel(signX * 0.125, signY * 0.375, green);
checkPixel(signX * 0.125, signY * 0.750, green);
checkPixel(signX * 0.375, signY * 0.375, blue);
checkPixel(signX * 0.750, signY * 0.375, blue);
checkPixel(signX * 0.375, signY * 0.750, blue);
checkPixel(signX * 0.750, signY * 0.750, blue);
}
}
}

const tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, ext.MIRROR_CLAMP_TO_EDGE_EXT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, ext.MIRROR_CLAMP_TO_EDGE_EXT);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texture created and configured");

wtu.drawUnitQuad(gl);
checkPixels();

if (!gl.createSampler) return;

debug("");
debug(`Check texture sampling with mirror-clamp-to-edge mode using a sampler object`);

const texWithSampler = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texWithSampler);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);

sampler = gl.createSampler();
gl.bindSampler(0, sampler);
gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_S, ext.MIRROR_CLAMP_TO_EDGE_EXT);
gl.samplerParameteri(sampler, gl.TEXTURE_WRAP_T, ext.MIRROR_CLAMP_TO_EDGE_EXT);
gl.samplerParameteri(sampler, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.samplerParameteri(sampler, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texture created and sampler configured");

wtu.drawUnitQuad(gl);
checkPixels();
}

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

runTestNoExtension();

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

if (ext !== null) {
checkEnums();
checkQueries();
checkSampling();
} else {
testPassed("No EXT_texture_mirror_clamp_to_edge support -- this is legal");
}
}

runTest();

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions sdk/tests/conformance2/extensions/00_test_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ promoted-extensions-in-shaders.html
--min-version 2.0.1 webgl-provoking-vertex.html
--min-version 2.0.1 webgl-render-shared-exponent.html
--min-version 2.0.1 webgl-shader-pixel-local-storage.html
--min-version 2.0.1 webgl-stencil-texturing.html
Loading

0 comments on commit 3e71f3b

Please sign in to comment.