From dcf8adb360bb7a8ec0a648559787f73ad497f19b Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Mon, 5 Oct 2020 14:49:53 -0700 Subject: [PATCH 1/2] Add test for TEXTURE_MIN/MAG_FILTER and TEXTURE_MAX_ANISOTROPY. Addresses #3143. --- .../textures/misc/00_test_list.txt | 3 +- .../textures/misc/texture-min-mag-filter.html | 191 ++++++++++++++++++ .../tests/ext-texture-filter-anisotropic.js | 60 ++++++ 3 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 sdk/tests/conformance/textures/misc/texture-min-mag-filter.html diff --git a/sdk/tests/conformance/textures/misc/00_test_list.txt b/sdk/tests/conformance/textures/misc/00_test_list.txt index 01d34aae08..febb0a8ad3 100644 --- a/sdk/tests/conformance/textures/misc/00_test_list.txt +++ b/sdk/tests/conformance/textures/misc/00_test_list.txt @@ -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 @@ -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 diff --git a/sdk/tests/conformance/textures/misc/texture-min-mag-filter.html b/sdk/tests/conformance/textures/misc/texture-min-mag-filter.html new file mode 100644 index 0000000000..f041712ece --- /dev/null +++ b/sdk/tests/conformance/textures/misc/texture-min-mag-filter.html @@ -0,0 +1,191 @@ + + + + + + +Test TEXTURE_MIN/MAG_FILTER and TEXTURE_MAX_ANISOTROPY + + + + + +
+
+ + + + + + diff --git a/sdk/tests/js/tests/ext-texture-filter-anisotropic.js b/sdk/tests/js/tests/ext-texture-filter-anisotropic.js index 0793e4c364..631ac44e7b 100644 --- a/sdk/tests/js/tests/ext-texture-filter-anisotropic.js +++ b/sdk/tests/js/tests/ext-texture-filter-anisotropic.js @@ -34,6 +34,7 @@ if (!gl) { if (contextVersion >= 2) { runSamplerTestEnabled(); } + testFiltering(); } } @@ -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; From dd745f80b8384899d35756679000f9ccbc14942d Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Wed, 7 Oct 2020 12:06:40 -0700 Subject: [PATCH 2/2] Draw a quad instead of point for more predicable derivatives. --- .../textures/misc/texture-min-mag-filter.html | 62 ++++++++++++++----- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/sdk/tests/conformance/textures/misc/texture-min-mag-filter.html b/sdk/tests/conformance/textures/misc/texture-min-mag-filter.html index f041712ece..e65c05139a 100644 --- a/sdk/tests/conformance/textures/misc/texture-min-mag-filter.html +++ b/sdk/tests/conformance/textures/misc/texture-min-mag-filter.html @@ -70,24 +70,29 @@ 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() { - gl_Position = vec4(0, 0, 0, 1); - gl_PointSize = 1.0; + 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() { - vec2 pos = gl_PointCoord - vec2(0.5); - pos.x *= 1.03; - pos += vec2(0.3); - gl_FragColor = texture2D(u_tex0, pos, -0.7); - //gl_FragColor.rg = pos; + vec3 pos = v_pos; + pos.xy += 0.1; + gl_FragColor = texture2D(u_tex0, pos.xy, +0.3); + //gl_FragColor.rgb = pos; } `; @@ -103,14 +108,31 @@ 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 fb = makeRgbaFramebuffer(gl, 1, 1); + 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, 1, 1); + gl.viewport(0, 0, 2, 2); const MAG = [ gl.NEAREST, gl.LINEAR @@ -132,9 +154,7 @@ }, { // NEAREST, MIPMAP_LINEAR: The opposite filter: gl.NEAREST_MIPMAP_LINEAR, - //test: (r, g, b, a) => r && !g && b, - // NEAREST_MIPMAP_LINEAR w/ anisotropy sometimes yields RED. - test: (r, g, b, a) => !g, + test: (r, g, b, a) => r && !g && b, }, { filter: gl.LINEAR_MIPMAP_LINEAR, test: (r, g, b, a) => r && g && b, @@ -154,7 +174,7 @@ for (const aniso of ANISO) { debug(' aniso: ' + aniso); const res = filtering_result(mag, min.filter, anisoExt, aniso); - debug(' res: ' + res); + //debug(' res: ' + res); const ok = min.test(res[0], res[1], res[2], res[3]); if (ok) { testPassed('Result was ' + res.toString()); @@ -167,6 +187,20 @@ } 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) { @@ -175,7 +209,7 @@ gl.clearColor(0, 0, 0, 0); gl.clear(gl.COLOR_BUFFER_BIT); - gl.drawArrays(gl.POINTS, 0, 1); + gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); const data = new Uint8Array(4); gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, data);