Skip to content
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
1 change: 1 addition & 0 deletions sdk/tests/conformance/textures/misc/00_test_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tex-image-and-sub-image-2d-with-array-buffer-view.html
tex-image-and-uniform-binding-bugs.html
--min-version 1.0.3 tex-image-canvas-corruption.html
--min-version 1.0.4 tex-image-svg-image-no-natural-width-and-height.html
--min-version 1.0.4 tex-image-svg-image-zero-natural-width-and-height.html
--min-version 1.0.2 tex-image-webgl.html
tex-image-with-format-and-type.html
tex-image-with-invalid-data.html
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!--
Copyright (c) 2025 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>
<meta charset="utf-8">
<title>WebGL texImage2D w/ &lt;img> with SVG image with zero natural width and height</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>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";

description("Test texImage2D from an img element with an SVG image with zero natural width and height.");

const wtu = WebGLTestUtils;

function makeTexture(image, variant) {
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.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);

if (variant === "texSubImage2D") {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.width, image.height, 0, gl.RGBA,
gl.UNSIGNED_BYTE, null);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image);
} else {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
}
}

function testWidthHeightSet(image, variant, description) {
debug('');
debug(`${variant} (HTMLImageElement.width/height set)`);

makeTexture(image, variant);
wtu.checkTextureSize(gl, 100, 100);

wtu.clearAndDrawUnitQuad(gl);

wtu.checkCanvasRect(gl, 75, 37, 2, 2, [0, 0, 0, 0], "should be transparent");
wtu.checkCanvasRect(gl, 75, 108, 2, 2, [0, 0, 0, 0], "should be transparent");
wtu.checkCanvasRect(gl, 225, 108, 2, 2, [0, 0, 0, 0], "should be transparent");
wtu.checkCanvasRect(gl, 225, 37, 2, 2, [0, 0, 0, 0], "should be transparent");
}

function testWidthHeightNotSet(image, variant) {
debug('');
debug(`${variant} (HTMLImageElement.width/height not set)`);

makeTexture(image, variant);
while (gl.getError()) {}

// Try to change the texture. This should fail because dimensions should have
// been specified as 0x0.
const buf = new Uint8Array(4);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "texture size should be 0x0");
}

const SVG_IMAGE = `<svg xmlns='http://www.w3.org/2000/svg' width='0' height='0'>
<rect width='100' height='100' fill='red'/>
</svg>`;
const gl = wtu.create3DContext();
const program = wtu.setupTexturedQuad(gl);

wtu.loadImageAsync(`data:image/svg+xml,${SVG_IMAGE}`, image => {
testWidthHeightNotSet(image, "texImage2D");
testWidthHeightNotSet(image, "texSubImage2D");

image.width = 100;
image.height = 100;

testWidthHeightSet(image, "texImage2D");
testWidthHeightSet(image, "texSubImage2D");

debug('');
finishTest();
});

var successfullyParsed = true;
</script>