Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test aniso filter #3159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdk/tests/conformance/textures/misc/00_test_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ copy-tex-image-and-sub-image-2d.html
--min-version 1.0.2 copy-tex-image-2d-formats.html
--min-version 1.0.4 copy-tex-image-crash.html
--min-version 1.0.4 copytexsubimage2d-large-partial-copy-corruption.html
--min-version 1.0.4 copytexsubimage2d-subrects.html
--min-version 1.0.4 copytexsubimage2d-subrects.html
--min-version 1.0.4 cube-incomplete-fbo.html
--min-version 1.0.4 cube-map-uploads-out-of-order.html
--min-version 1.0.3 default-texture.html
Expand Down Expand Up @@ -38,6 +38,7 @@ texture-complete.html
--min-version 1.0.3 --max-version 1.9.9 texture-fakeblack.html
--min-version 1.0.2 --max-version 1.9.9 texture-formats-test.html
--min-version 1.0.2 texture-hd-dpi.html
--min-version 1.0.4 texture-min-mag-filter.html
texture-mips.html
--max-version 1.9.9 texture-npot-video.html
--max-version 1.9.9 texture-npot.html
Expand Down
225 changes: 225 additions & 0 deletions sdk/tests/conformance/textures/misc/texture-min-mag-filter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
<!--
Copyright (c) 2020 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>Test TEXTURE_MIN/MAG_FILTER and TEXTURE_MAX_ANISOTROPY</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>
<div id="console"></div>
<script>
"use strict";
description("Test TEXTURE_MIN/MAG_FILTER and TEXTURE_MAX_ANISOTROPY");
debug("");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext();

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

testFiltering();

debug('');
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "End of run");
}

function makeRgbaFramebuffer(gl, w, h) {
const tex = gl.createTexture();

let was = gl.getParameter(gl.TEXTURE_BINDING_2D);
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.bindTexture(gl.TEXTURE_2D, was);

const fb = gl.createFramebuffer();
was = gl.getParameter(gl.FRAMEBUFFER_BINDING);
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D, tex, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, was);

return fb;
}

function testFiltering() {
const RED = [255, 0, 0, 255];
const GREEN = [0, 255, 0, 255];
const BLUE = [0, 0, 255, 255];
const DATA_LEVEL_0 = new Uint8Array([
RED[0], RED[1], RED[2], RED[3],
GREEN[0], GREEN[1], GREEN[2], GREEN[3],
GREEN[0], GREEN[1], GREEN[2], GREEN[3],
RED[0], RED[1], RED[2], RED[3],
]);

const DATA_LEVEL_1 = new Uint8Array([
BLUE[0], BLUE[1], BLUE[2], BLUE[3],
]);

const tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, DATA_LEVEL_0);
gl.texImage2D(gl.TEXTURE_2D, 1, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, DATA_LEVEL_1);

const VS = `
attribute vec2 a_pos;
varying vec3 v_pos;
void main() {
v_pos = a_pos.xyx;
v_pos.z *= 0.03;
gl_Position = vec4(2.0*v_pos - 1.0, 1);
}
`;
const FS = `
uniform sampler2D u_tex0;
precision mediump float;
varying vec3 v_pos;
void main() {
vec3 pos = v_pos;
pos.xy += 0.1;
gl_FragColor = texture2D(u_tex0, pos.xy, +0.3);
//gl_FragColor.rgb = pos;
}
`;

const prog = gl.createProgram();
let shader;
shader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(shader, VS);
gl.compileShader(shader);
gl.attachShader(prog, shader);

shader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(shader, FS);
gl.compileShader(shader);
gl.attachShader(prog, shader);

gl.bindAttribLocation(prog, 0, 'a_pos');
gl.linkProgram(prog);
console.log(gl.getShaderInfoLog(shader));
gl.useProgram(prog);

// -

const VDATA = [
0, 0,
1, 0,
0, 1,
1, 1,
];
const vbuf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbuf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(VDATA), gl.STATIC_DRAW);

gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);

// -

const fb = makeRgbaFramebuffer(gl, 2, 2);
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.viewport(0, 0, 2, 2);

const MAG = [
gl.NEAREST, gl.LINEAR
];
const MIN = [
{
filter: gl.NEAREST,
test: (r, g, b, a) => r && !g && !b,
}, {
filter: gl.LINEAR,
test: (r, g, b, a) => r && g && !b,
}, {
filter: gl.NEAREST_MIPMAP_NEAREST,
test: (r, g, b, a) => r && !g && !b,
}, {
// LINEAR, MIPMAP_NEAREST: Linear within mipmap that's nearest
filter: gl.LINEAR_MIPMAP_NEAREST,
test: (r, g, b, a) => r && g && !b,
}, {
// NEAREST, MIPMAP_LINEAR: The opposite
filter: gl.NEAREST_MIPMAP_LINEAR,
test: (r, g, b, a) => r && !g && b,
}, {
filter: gl.LINEAR_MIPMAP_LINEAR,
test: (r, g, b, a) => r && g && b,
},
];

const ANISO = [1];
const anisoExt = gl.getExtension('EXT_texture_filter_anisotropic');
if (anisoExt) {
ANISO.push(2);
}

for (const min of MIN) {
debug('\nmin: ' + wtu.glEnumToString(gl,min.filter));
for (const mag of MAG) {
debug(' mag: ' + wtu.glEnumToString(gl,mag));
for (const aniso of ANISO) {
debug(' aniso: ' + aniso);
const res = filtering_result(mag, min.filter, anisoExt, aniso);
//debug(' res: ' + res);
const ok = min.test(res[0], res[1], res[2], res[3]);
if (ok) {
testPassed('Result was ' + res.toString());
} else {
testFailed('Result was ' + res.toString());
}
}
}
}
}

function filtering_result(mag, min, anisoExt, aniso) {
const DISABLE_ANISO_FOR_NEAREST = false;
if (DISABLE_ANISO_FOR_NEAREST) {
if (mag == gl.NEAREST) {
aniso = 1.0;
}
switch (min) {
case gl.NEAREST:
case gl.NEAREST_MIPMAP_NEAREST:
case gl.NEAREST_MIPMAP_LINEAR:
case gl.LINEAR_MIPMAP_NEAREST:
aniso = 1.0;
break;
}
}
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, mag);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, min);
if (anisoExt) {
gl.texParameterf(gl.TEXTURE_2D, anisoExt.TEXTURE_MAX_ANISOTROPY_EXT, aniso);
}

gl.clearColor(0, 0, 0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

const data = new Uint8Array(4);
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, data);
return data;
}

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

</body>
</html>

60 changes: 60 additions & 0 deletions sdk/tests/js/tests/ext-texture-filter-anisotropic.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if (!gl) {
if (contextVersion >= 2) {
runSamplerTestEnabled();
}
testFiltering();
}
}

Expand Down Expand Up @@ -162,5 +163,64 @@ function runSamplerTestEnabled() {
gl.deleteSampler(sampler);
}

function makeRgbaFramebuffer(gl, w, h) {
const tex = gl.createTexture();

let was = gl.getParameter(gl.TEXTURE_2D_BINDING);
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.bindTexture(gl.TEXTURE_2D, was);

const fb = gl.createFramebuffer();
was = gl.getParameter(gl.FRAMEBUFFER_BINDING);
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D, tex, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, was);

return fb;
}

function testFiltering() {
const fb = makeRgbaFramebuffer(gl, 1, 1);
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);

const DATA_LEVEL_0 = new Uint8Array([
255, 0, 0, 255,
0, 255, 0, 255,
0, 255, 0, 255,
255, 0, 0, 255,
]);

const DATA_LEVEL_1 = new Uint8Array([
0, 0, 255, 255,
]);

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_LEVEL_0);
gl.texImage2D(gl.TEXTURE_2D, 1, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, DATA_LEVEL_1);

const VS = `
void main() {
gl_Position = vec4(0, 0, 0, 1);
}
`;
const FS = `
uniform sampler2D u_tex0;
void main() {
gl_FragColor = texture2D(u_tex0, vec2(0.3, 0.3), 0.3);
}
`;










debug("");
var successfullyParsed = true;