From 7d554b15695e87946afbef6049568c105507d4a6 Mon Sep 17 00:00:00 2001 From: Ken Russell Date: Tue, 15 Jun 2021 11:18:43 -0700 Subject: [PATCH 1/6] Add colorSpace attribute to WebGLRenderingContextBase. Define its behavior both for presenting the rendering context's results, and uploading textures via texImage2D / texSubImage2D from DOM inputs (the TexImageSource union type). Follows https://github.com/whatwg/html/pull/6562 , in which the PredefinedColorSpace enum was defined, and its behavior for 2D canvas contexts specified. --- specs/latest/1.0/index.html | 49 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/specs/latest/1.0/index.html b/specs/latest/1.0/index.html index b941de3604..11ece8c3de 100644 --- a/specs/latest/1.0/index.html +++ b/specs/latest/1.0/index.html @@ -1721,6 +1721,7 @@

The WebGL context

[Exposed=Worker] readonly attribute OffscreenCanvas canvas; readonly attribute GLsizei drawingBufferWidth; readonly attribute GLsizei drawingBufferHeight; + attribute PredefinedColorSpace colorSpace = "srgb"; [WebGLHandlesContextLoss] WebGLContextAttributes? getContextAttributes(); [WebGLHandlesContextLoss] boolean isContextLost(); @@ -1979,6 +1980,20 @@

Attributes

The actual height of the drawing buffer. May be different from the height attribute of the HTMLCanvasElement if the implementation is unable to satisfy the requested width or height. +
+ + + colorSpace + + + of type PredefinedColorSpace + (specification) +
+ The color space in which the drawing buffer's contents are assumed to + have been produced. Changing this attribute affects the on-screen display + of the rendering context, but does not change the drawing buffer's + contents. This attribute also affects how TexImageSource + sources are uploaded to textures. @@ -2653,10 +2668,23 @@

Texture objects

The width and height of the texture are set as specified in section Texture Upload Width and Height.

- The source image data is conceptually first converted to the data type and format - specified by the format and type arguments, and then transferred to - the WebGL implementation. Format conversion is performed according to the following table. - If a packed pixel format is specified which would imply loss of bits of precision from the + First, the source image data is conceptually converted to the color space + specified by the colorSpace + attribute, except in the following situations: + + + + Next, the source image data is converted to the data type and format specified by + the format and type arguments, and then transferred to the WebGL + implementation. Format conversion is performed according to the following table. If a + packed pixel format is specified which would imply loss of bits of precision from the image data, this loss of precision must occur.

@@ -2799,12 +2827,8 @@

Texture objects

Texture Upload Width and Height.

See texImage2D for the interpretation of - the format and type arguments, and notes on - the UNPACK_PREMULTIPLY_ALPHA_WEBGL pixel storage parameter.

- - See Pixel Storage Parameters for WebGL-specific - pixel storage parameters that affect the behavior of this function when it is called - with any argument type other than ImageBitmap.

+ the format and type arguments, handling of WebGL-specific pixel + storage parameters, and potential color space transformations of the input.

The first pixel transferred from the source to the WebGL implementation corresponds to the upper left corner of the source. This behavior is modified by the @@ -4555,6 +4579,11 @@

References

(Non-normative) WebCodecs API, C. Cunningham, P. Adenot, B. Aboba. W3C.
+
[PREDEFINEDCOLORSPACE]
+
+ HTML Living Standard - The PredefinedColorSpace enum, + WHATWG. +
From 1a2aa51c30849a0e6e2844a38b12e1041b7217fc Mon Sep 17 00:00:00 2001 From: Ken Russell Date: Tue, 15 Jun 2021 13:20:10 -0700 Subject: [PATCH 2/6] Address review feedback from kainino. colorSpace affects how this context is uploaded or drawn to another one. --- specs/latest/1.0/index.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/specs/latest/1.0/index.html b/specs/latest/1.0/index.html index 11ece8c3de..817242902f 100644 --- a/specs/latest/1.0/index.html +++ b/specs/latest/1.0/index.html @@ -1993,7 +1993,10 @@

Attributes

have been produced. Changing this attribute affects the on-screen display of the rendering context, but does not change the drawing buffer's contents. This attribute also affects how TexImageSource - sources are uploaded to textures. + sources are uploaded to textures in this context, and how the contents of + this context's drawing buffer are interpreted when they are drawn to a 2D + canvas context, or uploaded to textures in another WebGL + or WebGPU rendering context. @@ -4584,6 +4587,11 @@

References

HTML Living Standard - The PredefinedColorSpace enum, WHATWG. +
[WEBGPU]
+
+ WebGPU Editor's Draft, + WebGPU Community Group. +
From ad8dff0c8fa536797302cf3d80dfa29b79bedbb4 Mon Sep 17 00:00:00 2001 From: Kenneth Russell Date: Thu, 24 Mar 2022 14:51:25 -0700 Subject: [PATCH 3/6] Split into drawingBuffer/unpackColorSpace on ccameron's feedback. Reallocate drawing buffer when drawingBufferColorSpace is changed. --- specs/latest/1.0/index.html | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/specs/latest/1.0/index.html b/specs/latest/1.0/index.html index 817242902f..c354ab8142 100644 --- a/specs/latest/1.0/index.html +++ b/specs/latest/1.0/index.html @@ -1721,7 +1721,8 @@

The WebGL context

[Exposed=Worker] readonly attribute OffscreenCanvas canvas; readonly attribute GLsizei drawingBufferWidth; readonly attribute GLsizei drawingBufferHeight; - attribute PredefinedColorSpace colorSpace = "srgb"; + attribute PredefinedColorSpace drawingBufferColorSpace = "srgb"; + attribute PredefinedColorSpace unpackColorSpace = "srgb"; [WebGLHandlesContextLoss] WebGLContextAttributes? getContextAttributes(); [WebGLHandlesContextLoss] boolean isContextLost(); @@ -1982,21 +1983,31 @@

Attributes

the implementation is unable to satisfy the requested width or height.
- - colorSpace + + drawingBufferColorSpace of type PredefinedColorSpace (specification)
The color space in which the drawing buffer's contents are assumed to - have been produced. Changing this attribute affects the on-screen display - of the rendering context, but does not change the drawing buffer's - contents. This attribute also affects how TexImageSource - sources are uploaded to textures in this context, and how the contents of - this context's drawing buffer are interpreted when they are drawn to a 2D - canvas context, or uploaded to textures in another WebGL - or WebGPU rendering context. + have been produced. Changing this attribute causes the drawing buffer to + be reallocated; its current contents are lost. This attribute affects the + on-screen display of the rendering context, and the interpretation of + this context's drawing buffer when it is drawn to a 2D canvas context, or + uploaded to textures in another WebGL or WebGPU + rendering context. +
+ + + unpackColorSpace + + + of type PredefinedColorSpace + (specification) +
+ The color space into which TexImageSource sources are + converted when uploading them to textures in this context. From e18376fa3446ebcd6022d29f173cab54c0acb30b Mon Sep 17 00:00:00 2001 From: Kenneth Russell Date: Thu, 24 Mar 2022 14:55:29 -0700 Subject: [PATCH 4/6] Fix reference to colorSpace attribute --- specs/latest/1.0/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/latest/1.0/index.html b/specs/latest/1.0/index.html index c354ab8142..0aed642302 100644 --- a/specs/latest/1.0/index.html +++ b/specs/latest/1.0/index.html @@ -2683,7 +2683,7 @@

Texture objects

Texture Upload Width and Height.

First, the source image data is conceptually converted to the color space - specified by the colorSpace + specified by the unpackColorSpace attribute, except in the following situations:
    From e591f6cc99700264a2741df170660d56e12582cf Mon Sep 17 00:00:00 2001 From: Kenneth Russell Date: Fri, 6 May 2022 17:47:35 -0700 Subject: [PATCH 5/6] Apply kdashg's suggestion on drawingBufferColorSpace wording. Make unpackColorSpace apply to ImageBitmaps and add rationale. --- specs/latest/1.0/index.html | 39 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/specs/latest/1.0/index.html b/specs/latest/1.0/index.html index 0aed642302..03f38d3195 100644 --- a/specs/latest/1.0/index.html +++ b/specs/latest/1.0/index.html @@ -1990,13 +1990,13 @@

    Attributes

    of type PredefinedColorSpace (specification)
    - The color space in which the drawing buffer's contents are assumed to - have been produced. Changing this attribute causes the drawing buffer to - be reallocated; its current contents are lost. This attribute affects the - on-screen display of the rendering context, and the interpretation of - this context's drawing buffer when it is drawn to a 2D canvas context, or - uploaded to textures in another WebGL or WebGPU - rendering context. + The color space used to interpret the drawing buffer's content values. + Changing this attribute causes the drawing buffer to be reallocated; its + current contents are lost. This attribute affects the on-screen display + of the rendering context, and the interpretation of this context's + drawing buffer when it is drawn to a 2D canvas context, or uploaded to + textures in another WebGL or WebGPU rendering + context.
    @@ -2682,18 +2682,21 @@

    Texture objects

    The width and height of the texture are set as specified in section
    Texture Upload Width and Height.

    - First, the source image data is conceptually converted to the color space - specified by the unpackColorSpace - attribute, except in the following situations: + First, the source image data is conceptually converted to the color space specified by + the unpackColorSpace + attribute, except if the source image data is an HTMLImageElement, and + the UNPACK_COLORSPACE_CONVERSION_WEBGL pixel storage parameter is set + to NONE.

    -
      -
    • the source image data is an HTMLImageElement, and - the UNPACK_COLORSPACE_CONVERSION_WEBGL pixel storage - parameter is set to NONE.
    • -
    • the source image data is an ImageBitmap, in which case - all color space conversions were assumed to have occurred - during ImageBitmap construction.
    • -
    +
    + + This color space conversion applies to ImageBitmap objects as well, though + other texture unpack parameters do not apply to ImageBitmaps because they + are expected to be specified during ImageBitmap construction. + Implementation experience revealed that it was beneficial to + perform ImageBitmaps' color space conversion as late as possible when + uploading to WebGL textures. +
    Next, the source image data is converted to the data type and format specified by the format and type arguments, and then transferred to the WebGL From 14ad5f940871eeb5275db7abd1496e85b5235766 Mon Sep 17 00:00:00 2001 From: Kenneth Russell Date: Fri, 6 May 2022 17:53:32 -0700 Subject: [PATCH 6/6] Whitespace symmetry. --- specs/latest/1.0/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/latest/1.0/index.html b/specs/latest/1.0/index.html index 03f38d3195..b4c8cd91a5 100644 --- a/specs/latest/1.0/index.html +++ b/specs/latest/1.0/index.html @@ -2696,6 +2696,7 @@

    Texture objects

    Implementation experience revealed that it was beneficial to perform ImageBitmaps' color space conversion as late as possible when uploading to WebGL textures. + Next, the source image data is converted to the data type and format specified by