Skip to content
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

Add drawingBufferColorSpace/unpackColorSpace attributes to WebGLRenderingContextBase. #3292

Merged
merged 6 commits into from
May 7, 2022
Merged
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
72 changes: 62 additions & 10 deletions specs/latest/1.0/index.html
Original file line number Diff line number Diff line change
@@ -1721,6 +1721,8 @@ <h3><a name="WEBGLRENDERINGCONTEXT">The WebGL context</a></h3>
[Exposed=Worker] readonly attribute OffscreenCanvas canvas;
readonly attribute GLsizei drawingBufferWidth;
readonly attribute GLsizei drawingBufferHeight;
attribute PredefinedColorSpace drawingBufferColorSpace = "srgb";
attribute PredefinedColorSpace unpackColorSpace = "srgb";

[WebGLHandlesContextLoss] WebGLContextAttributes? getContextAttributes();
[WebGLHandlesContextLoss] boolean isContextLost();
@@ -1979,6 +1981,33 @@ <h4>Attributes</h4>
The actual height of the drawing buffer. May be different from the
<code>height</code> attribute of the <code>HTMLCanvasElement</code> if
the implementation is unable to satisfy the requested width or height.
<dt>
<code class=attribute-name>
<a id="DOM-WebGLRenderingContext-drawingBufferColorSpace">
drawingBufferColorSpace
</a>
</code>
of type <code><a href="https://html.spec.whatwg.org/multipage/canvas.html#predefinedcolorspace">PredefinedColorSpace</a></code>
<a href="#refsPREDEFINEDCOLORSPACE">(specification)</a>
<dd>
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 <a href="#refsWEBGPU">WebGPU</a> rendering
context.
<dt>
<code class=attribute-name>
<a id="DOM-WebGLRenderingContext-unpackColorSpace">
unpackColorSpace
</a>
</code>
of type <code><a href="https://html.spec.whatwg.org/multipage/canvas.html#predefinedcolorspace">PredefinedColorSpace</a></code>
<a href="#refsPREDEFINEDCOLORSPACE">(specification)</a>
<dd>
The color space into which <code>TexImageSource</code> sources are
converted when uploading them to textures in this context.
</dl>

<!-- ======================================================================================================= -->
@@ -2653,10 +2682,27 @@ <h4>Texture objects</h4>
The width and height of the texture are set as specified in section
<a href="#TEXTURE_UPLOAD_SIZE">Texture Upload Width and Height</a>.<br><br>

The source image data is conceptually first converted to the data type and format
specified by the <em>format</em> and <em>type</em> 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 <a href="#DOM-WebGLRenderingContext-unpackColorSpace">unpackColorSpace</a>
attribute, except if the source image data is an <code>HTMLImageElement</code>, and
the <code>UNPACK_COLORSPACE_CONVERSION_WEBGL</code> pixel storage parameter is set
to <code>NONE</code>. <br><br>

<div class="note rationale">

This color space conversion applies to <code>ImageBitmap</code> objects as well, though
other texture unpack parameters do not apply to <code>ImageBitmap</code>s because they
are expected to be specified during <code>ImageBitmap</code> construction.
Implementation experience revealed that it was beneficial to
perform <code>ImageBitmap</code>s' color space conversion as late as possible when
uploading to WebGL textures.

</div>

Next, the source image data is converted to the data type and format specified by
the <em>format</em> and <em>type</em> 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. <br><br>

<table class="foo">
@@ -2799,12 +2845,8 @@ <h4>Texture objects</h4>
<a href="#TEXTURE_UPLOAD_SIZE">Texture Upload Width and Height</a>.<br><br>

See <a href="#TEXIMAGE2D_HTML">texImage2D</a> for the interpretation of
the <em>format</em> and <em>type</em> arguments, and notes on
the <code>UNPACK_PREMULTIPLY_ALPHA_WEBGL</code> pixel storage parameter. <br><br>

See <a href="#PIXEL_STORAGE_PARAMETERS">Pixel Storage Parameters</a> for WebGL-specific
pixel storage parameters that affect the behavior of this function when it is called
with any argument type other than <code>ImageBitmap</code>. <br><br>
the <em>format</em> and <em>type</em> arguments, handling of WebGL-specific pixel
storage parameters, and potential color space transformations of the input. <br><br>

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 +4597,16 @@ <h2>References</h2>
<dd>(Non-normative) <cite><a href="https://w3c.github.io/webcodecs/">WebCodecs API</a></cite>,
C. Cunningham, P. Adenot, B. Aboba. W3C.
</dd>
<dt id="refsPREDEFINEDCOLORSPACE">[PREDEFINEDCOLORSPACE]</dt>
<dd><cite><a href="https://html.spec.whatwg.org/multipage/canvas.html#predefinedcolorspace">
HTML Living Standard - The PredefinedColorSpace enum</a></cite>,
WHATWG.
</dd>
<dt id="refsWEBGPU">[WEBGPU]</dt>
<dd><cite><a href="https://gpuweb.github.io/gpuweb/">
WebGPU Editor's Draft</a></cite>,
WebGPU Community Group.
</dd>
</dl>

<!-- ======================================================================================================= -->