KhronosGroup / KhronosGroup/WebGL
Image sizing behavior for SVG images passed to texImage2D is poorly defined
- Dominant language
- HTML
- Stars
- 2.9k
- Forks
- 703
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 4
Description
The WebGL spec says that for determining the size of an SVG image uploaded to a texture: "If an SVG image is uploaded, the width and height of the texture are set to the current values of the width and height properties of the HTMLImageElement object"
Source: https://www.khronos.org/registry/webgl/specs/latest/1.0/#TEXTURE_UPLOAD_SIZE
This seem fine at first glance but... the spec says that in cases where the image is not being rendered (sucha as a texture upload), that the width and height IDL attributes are "0, if the image is not available or does not have intrinsic dimensions". And guess what, SVG images do not have intrinsic dimensions, they only have an intrinsic aspect ratio.
Source:
https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-width
So an implementation that strictly respects the spec does not allow svg to be uploaded to a texture.
Perhaps something like the sizing behavior of CanvasREnderingContext2D.drawImage should be used?
The 2D canvas spec is unambiguous, but requires some effort to interpret because it references other specs and there is a lot of unrelated cases handled by the various algorithms. In essence, it says that the SVG image should be scaled uniformly (respecting its intrinsic aspect ratio) to a size that contains the size of the destination canvas.
The releavant spec for 2D canvas drawImage are:
https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-drawimage
https://drafts.csswg.org/css-images/#default-sizing
https://drafts.csswg.org/css-images/#contain-constraint
Contributor guide
Research direction
Start with the WebGL 1.0 TEXTURE_UPLOAD_SIZE section, then read the HTMLImageElement width and height definition and the linked Canvas 2D drawImage, CSS default-sizing, and contain-constraint sections. Clarify the normative SVG sizing behavior for texture uploads and update the WebGL specification so the result is unambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html
- Domain
- computer-graphics, web-dev
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100