-
Notifications
You must be signed in to change notification settings - Fork 685
Add test for tex{Sub}Image2D from HTMLImageElement w/ SVG image w/o natural sizes #3728
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
Merged
kenrussell
merged 5 commits into
KhronosGroup:main
from
fsoder:svg-no-natural-width-height-test
Apr 17, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6e1b953
Add test for tex{Sub}Image2D from HTMLImageElement w/ SVG image w/o n…
fsoder e7451f4
Make sure test finishes asynchronously
fsoder ba588ac
Check the size of the resulting texture
fsoder d49f675
Test with and without width/height specified on the image element
fsoder 7ea5b1a
Add --min-version=1.0.4 for the new test
kenrussell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
sdk/tests/conformance/textures/misc/tex-image-svg-image-no-natural-width-and-height.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| <!-- | ||
| 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/ <img> with SVG image without 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 without 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); | ||
fsoder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| 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, 255, 255], "should be blue"); | ||
| wtu.checkCanvasRect(gl, 75, 108, 2, 2, [0, 0, 0, 0], "should be transparent"); | ||
| wtu.checkCanvasRect(gl, 225, 108, 2, 2, [255, 255, 0, 255], "should be yellow"); | ||
| 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' viewBox='0 0 100 100'> | ||
| <rect width='50' height='50' fill='blue'/> | ||
| <rect x='50' y='50' width='50' height='50' fill='yellow'/> | ||
| </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; | ||
fsoder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| testWidthHeightSet(image, "texImage2D"); | ||
| testWidthHeightSet(image, "texSubImage2D"); | ||
|
|
||
| debug(''); | ||
| finishTest(); | ||
| }); | ||
|
|
||
| var successfullyParsed = true; | ||
| </script> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.