-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwebxrlayers-1.bs
executable file
·2188 lines (1750 loc) · 138 KB
/
webxrlayers-1.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class="metadata">
Shortname: webxrlayers
Title: WebXR Layers API Level 1
Group: immersivewebwg
Status: ED
TR: https://www.w3.org/TR/webxrlayers-1/
ED: https://immersive-web.github.io/layers/
Repository: immersive-web/layers
Level: 1
Mailing List Archives: https://lists.w3.org/Archives/Public/public-immersive-web-wg/
!Participate: <a href="https://github.com/immersive-web/layers/issues/new">File an issue</a> (<a href="https://github.com/immersive-web/layers/issues">open issues</a>)
!Participate: <a href="https://lists.w3.org/Archives/Public/public-immersive-web-wg/">Mailing list archive</a>
!Participate: <a href="irc://irc.w3.org:6665/">W3C's #immersive-web IRC</a>
Editor: Rik Cabanier 106988, Meta https://facebook.com, [email protected]
Abstract: This specification describes support for various layer types used in a WebXR session.
</pre>
<pre class="link-defaults">
spec:infra;
type: dfn; text:string
spec: permissions-request-1;
type: dfn; text: request(permissionDesc); for: Permissions
spec: webxr;
type: dfn; text: immersive xr device; for: XR
type: dfn; text: xr device; for: /
type: dfn; text: active; for: XRFrame
type: dfn; text: eye; for: XRView
type: dfn; text: initialize the render state
type: dfn; text: active render state
type: dfn; text: pending render state
type: dfn; text: apply the pending render state
type: dfn; text: viewer reference space
type: dfn; text: xr animation frame
type: dfn; text: immersive xr device
type: dfn; text: list of views; for: XRSession
type: dfn; text: list of viewports
type: dfn; text: opaque framebuffer
type: dfn; text: feature descriptor
type: dfn; text: feature requirement
type: dfn; text: active immersive session
type: dfn; text: type; for: XRReferenceSpace
type: dfn; text: session; for: XRSpace
type: dfn; text: view
type: dfn; text: XRLayer
type: dfn; text: XRReferenceSpace
type: dfn; text: type; for: XRReferenceSpace
type: dfn; text: updateRenderState; for: XRSession
type: dfn; text: session; for: XRWebGLLayer
type: dfn; text: layers; for: XRRenderStateInit
type: dfn; text: secondary-views; for: secondary view
type: dfn; text: primary view
type: dfn; text: secondary view
type: dfn; text: active; for: view
type: enum-value; text: local
spec: html;
type: dfn; text: check the usability of the image argument
type: dfn; text: request the xr permission
spec:webidl;
type:dfn; text:new
</pre>
<pre class="anchors">
spec: webxr; urlPrefix: https://www.w3.org/TR/webxr/
type: dfn; text: feature descriptor
type: dfn; text: xr compositor
type: dfn; text: recommended WebGL framebuffer resolution
type: dfn; text: native WebGL framebuffer resolution
type: dfn; text: immersive session
type: dfn; text: xr compatible
type: dfn; text: ended
type: dfn; text: context
type: dfn; text: XRFrame/active
type: dfn; text: XRView/active
type: dfn; text: eye; for: XRView
type: dfn; text: frame
type: dfn; text: animationFrame; for: XRFrame
type: dfn; text: XRSession/requestAnimationFrame()
spec: WebGL; urlPrefix: https://www.khronos.org/registry/webgl/specs/latest/1.0/
type: interface; text: WebGLFramebuffer; url: WebGLFramebuffer
type: interface; text: WebGLTexture; url: WebGLTexture
type: interface; text: WebGLShader; url: 5.8
type: interface; text: WebGLRenderingContext; url: WebGLRenderingContext
type: interface; text: WebGLRenderingContextBase; url: WebGLRenderingContextBase
type: typedef; text: INVALID_OPERATION; url: WebGLRenderingContextBase
type: typedef; text: TEXTURE_2D; url: 5.14
type: typedef; text: TEXTURE_CUBE_MAP; url: 5.14
type: method; text: clear; url: 5.14.11
type: method; text: deleteTexture; url: 5.14.8
type: method; text: drawArrays; url: 5.14.11
type: method; text: drawElements; url: 5.14.11
type: dfn; text: WebGL viewport; url:#5.14.4
type: typedef; text: GLenum; url: #5.1
type: typedef; text: RGBA; url: #5.14
type: typedef; text: RGB; url: #5.14
type: dfn; text: extension; url:#5.14.14
spec: ; urlPrefix: https://www.khronos.org/registry/webgl/extensions/EXT_sRGB/
type: typedef; text: SRGB_EXT
type: typedef; text: SRGB_ALPHA_EXT
type: typedef; text: EXT_sRGB
spec: ; urlPrefix: https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/
type: typedef; text: DEPTH_COMPONENT
type: typedef; text: DEPTH_STENCIL
type: typedef; text: WEBGL_depth_texture
spec: ; urlPrefix: https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_etc/
type: typedef; text: COMPRESSED_RGB8_ETC2
type: typedef; text: COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
type: typedef; text: COMPRESSED_RGBA8_ETC2_EAC
type: typedef; text: COMPRESSED_SRGB8_ETC2
type: typedef; text: COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
type: typedef; text: COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
type: typedef; text: WEBGL_compressed_texture_etc
spec: ; urlPrefix: https://www.khronos.org/registry/webgl/extensions/WEBGL_compressed_texture_astc/
type: typedef; text: WEBGL_compressed_texture_astc
spec: WebGL 2.0; urlPrefix: https://www.khronos.org/registry/webgl/specs/latest/2.0/
type: interface; text: WebGL2RenderingContext; url: WebGL2RenderingContext
type: typedef; text: TEXTURE_2D_ARRAY; url: 3.7
type: dfn; text: texStorage2D; url: 3.7.6
type: dfn; text: texStorage3D; url: 3.7.6
type: typedef; text: RGB8; url: #3.7
type: typedef; text: RGBA8; url: #3.7
type: typedef; text: RGBA16F; url: #3.7
type: typedef; text: SRGB8; url: #3.7
type: typedef; text: SRGB8_ALPHA8; url: #3.7
type: typedef; text: DEPTH_COMPONENT24; url: #3.7
type: typedef; text: DEPTH24_STENCIL8; url: #3.7
spec: WEBGL_depth_texture; urlPrefix: https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/
type: typedef; text: WEBGL_depth_texture
type: typedef; text: UNSIGNED_INT_24_8_WEBGL
spec:html; urlPrefix: https://html.spec.whatwg.org/multipage/
type: dfn; text: current realm; url: webappapis.html#current
spec: ECMAScript; urlPrefix: https://tc39.github.io/ecma262/#
type: dfn; text: Realm; url: realm
spec: compositing-1; urlPrefix: https://www.w3.org/TR/compositing-1/
type: dfn; text: source-over; url: porterduffcompositingoperators_srcover
</pre>
<pre class=link-defaults>
spec:webxr-ar-module-1; type:enum-value; text:"immersive-ar"
</pre>
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="favicon-96x96.png">
<style>
.unstable::before {
content: "This section is not stable";
display: block;
font-weight: bold;
text-align: right;
color: red;
}
.unstable {
border: thin solid pink;
border-radius: .5em;
padding: .5em;
margin: .5em calc(-0.5em - 1px);
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='290'><text transform='rotate(-45)' text-anchor='middle' font-family='sans-serif' font-weight='bold' font-size='70' y='210' opacity='.1' fill='white'>Unstable</text></svg>");
background-repeat: repeat;
background-color: #282828;
}
@media (prefers-color-scheme: light) {
.unstable {
background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='290'><text transform='rotate(-45)' text-anchor='middle' font-family='sans-serif' font-weight='bold' font-size='70' y='210' opacity='.1'>Unstable</text></svg>");
background-color: #FFF4F4;
}
}
.unstable h3:first-of-type {
margin-top: 0.5rem;
}
.unstable.example:not(.no-marker)::before {
content: "Example " counter(example) " (Unstable)";
float: none;
}
.non-normative::before {
content: "This section is non-normative.";
font-style: italic;
}
.tg {
border-collapse: collapse;
border-spacing: 0;
}
.tg th {
border-style: solid;
border-width: 1px;
background: #90b8de;
color: #fff;
font-family: sans-serif;
font-weight: bold;
border-color: grey;
}
.tg td {
padding: 4px 5px;
background-color: rgb(221, 238, 255);
font-family: monospace;
border-style: solid;
border-width: 1px;
border-color: grey;
overflow: hidden;
word-break: normal;
}
</style>
Introduction {#intro}
============
<section class="non-normative">
This specification adds support of `composition` layers to the WebXR spec. The benefits of layers are as follows:
* <b>Performance and judder</b>: Composition layers are presented at the frame rate of the compositor (i.e. native refresh rate of HMD) rather than at the application frame rate.
Even when the application is not updating the layer's rendering at the native refresh rate of the compositor, the compositor might be able to re-project the existing
rendering to the proper pose. This results in smoother rendering and less judder. Another feature of layers is that each of them can have different resolution. This allows the
application to scale down the main eye buffer resolution on low performance systems, but keeping essential information, such as text or a map, in its own layer at a higher
resolution.
* <b>Legibility/visual fidelity</b>: In regular WebXR, the resolution for eye-buffers might be reduced to relatively low values especially on low performance systems. This makes
it harder to render high fidelity content, such as text. With Composition Layers, a static cylinder or quad layer can be drawn once at high resolution and is resampled only once by the compositor. This contrasts with
the traditional approach with rendering an {{XRWebGLLayer}} where content is produced at the device's refresh rate and resampled at least twice: once when rendering into WebGL eye-buffer (which can lose details due to
lower eye-buffer resolution) and the second time by the compositor.
* <b>Power consumption / battery life</b>: Due to the reduced rendering pipeline, the lack of double sampling and no need to update the layer's rendering each frame, the power
consumption is expected to be improved.
* <b>Latency</b>: Pose sampling for composition layers may occur at the very end of the frame and then certain reprojection techniques could be used to update the layer's pose to
match it with the most recent HMD pose. This may significantly reduce the effective latency for the layers' rendering and as a result improve overall experience.
* <b>Support for more color types</b>: WebXR only supports RGB values. Composition layer will have broader support for color types so authors can use compressed formats or sRGB.
</section>
Terminology {#terminology}
-----------
Application flow {#applicationflow}
----------------
<section class="non-normative">
If an author wants to use GL layers, they have to go through these steps:
1. For any layer type other than {{XRProjectionLayer}} request support through {{XRPermissionDescriptor/requiredFeatures}} or {{XRPermissionDescriptor/optionalFeatures}} in {{XRSystem/requestSession()}}.
1. Create an {{XRWebGLBinding}} or {{XRMediaBinding}}.
1. Create layers with these objects.
1. Add the layers to {{XRRenderStateInit}} and call {{XRSession/updateRenderState()}}.
1. During {{XRSession/requestAnimationFrame()}} for webgl layers, draw content each WebGL layer.
</section>
Initialization {#initialization}
==============
If an application wants to create layers other than of type {{XRProjectionLayer}} during a session,
the session MUST be requested with an appropriate [=feature descriptor=]. The string "<dfn for="feature descriptor">layers</dfn>" is introduced
by this module as a new valid [=feature descriptor=] for the WebXR Layers feature.
Layers of type {{XRProjectionLayer}} MUST always be supported, regardless if the [=feature descriptor=] was requested.
<div class="example">
The following code requests layers as an optional feature.
<pre highlight="js">
navigator.xr.requestSession('immersive-vr', {
optionalFeatures: ['layers']
}
</pre>
</div>
Layers are only supported for XRSessions created with XRSessionMode of {{XRSessionMode/"immersive-vr"}}
or {{XRSessionMode/"immersive-ar"}}. {{XRSessionMode/"inline"}} sessions MUST NOT support layers.
The "[=feature descriptor/layers=]" [=feature descriptor=] has a [=feature requirement=] that it cannot be enabled when there is an [=active immersive session=].
NOTE: This means that executing the {{Permissions/request(permissionDesc)}} API with "[=feature descriptor/layers=]" will
not enable layers support for the current active session.
Layer types {#xrlayertypes}
===========
Mono and stereo layers {#monovsstereo}
----------------------
A stereo layer MUST supply an {{XRSubImage}} to render to for each view.
A mono layer MUST supply a single {{XRSubImage}} which is shown to each view.
The [=XR Compositor=] MUST ensure that layers are presented correctly in stereo to the observer.
XRLayerLayout {#xrlayerlayouttype}
-------------
The {{XRLayerLayout}} enum defines the layout of the layer.
<pre class="idl">
enum XRLayerLayout {
"default",
"mono",
"stereo",
"stereo-left-right",
"stereo-top-bottom"
};
</pre>
- A layout of <dfn enum-value for="XRLayerLayout">default</dfn> indicates that the layer can accomodate all the views of session’s [=list of views=].
- A layout of <dfn enum-value for="XRLayerLayout">mono</dfn> indicates that the layer is mono.
- A layout of <dfn enum-value for="XRLayerLayout">stereo</dfn> indicates that the layer is stereo.
- A layout of <dfn enum-value for="XRLayerLayout">stereo-left-right</dfn> indicates that the layer is stereo and divided left to right.
- A layout of <dfn enum-value for="XRLayerLayout">stereo-top-bottom</dfn> indicates that the layer is stereo and divided top to bottom.
NOTE: If an {{XRCompositionLayer}} is created with a {{XRLayerLayout/"default"}} or {{XRLayerLayout/"stereo"}} {{XRLayerLayout}}, it is highly recommended
that it is allocated with an {{XRTextureType/"texture-array"}} texture type.
Note: The {{XRLayerLayout/"stereo-left-right"}} and {{XRLayerLayout/"stereo-top-bottom"}} layouts are designed to minimize draw
calls for content that is already in stereo (for example stereo videos or images). Experiences that don't require such assets types
should use the {{XRLayerLayout/"default"}} or {{XRLayerLayout/"stereo"}} layout.
XRLayerQuality {#xrlayerqualitytype}
-------------
The {{XRLayerQuality}} enum defines the display quality of the layer.
<pre class="idl">
enum XRLayerQuality {
"default",
"text-optimized",
"graphics-optimized"
};
</pre>
- A layout of <dfn enum-value for="XRLayerQuality">default</dfn> indicates that the layer is displayed with regular settings.
- A layout of <dfn enum-value for="XRLayerQuality">text-optimized</dfn> indicates that [=XR Compositor=] will try to render the layer so it's most readable.
- A layout of <dfn enum-value for="XRLayerQuality">graphics-optimized</dfn> indicates that [=XR Compositor=] will try to render the layer with additional sharpness.
NOTE: the {{XRLayerQuality/text-optimized}} and {{XRLayerQuality/graphics-optimized}} flags MAY result in additional processing by the [=XR Compositor=] which may affect performance.
XRCompositionLayer {#xrcompositionlayertype}
--------------
XRCompositionLayer defines a set of common attributes and behaviors across certain layer types.
<pre class="idl">
[Exposed=Window] interface XRCompositionLayer : XRLayer {
readonly attribute XRLayerLayout layout;
attribute boolean blendTextureSourceAlpha;
attribute boolean forceMonoPresentation;
attribute float opacity;
readonly attribute unsigned long mipLevels;
attribute XRLayerQuality quality;
readonly attribute boolean needsRedraw;
undefined destroy();
};
</pre>
The <dfn attribute for="XRCompositionLayer">layout</dfn> attribute returns the layout of the layer.
The <dfn attribute for="XRCompositionLayer">blendTextureSourceAlpha</dfn> attribute enables the layer’s texture alpha channel.
The <dfn attribute for="XRCompositionLayer">forceMonoPresentation</dfn> attribute forces the right eye to use the same layer configuration
as the left eye. This MUST send a signal to the [=XR Compositor=] to remove the {{XRLayerLayout/stereo}} effect of this {{XRCompositionLayer}}. Setting this to <code>true</code> on a {{XRLayerLayout/mono}} layer has no effect.
NOTE: this attribute has no other side effects on other information that is returned by the {{XRSession}}. Only the operation of the [=XR Compositor=] is affected by this setting and experiences SHOULD continue to draw to both eyes.
The <dfn attribute for="XRCompositionLayer">opacity</dfn> attribute sets the opacity that is applied to the pixels of the layer. The [=XR Compositor=] MUST multiply each pixel (in premultiplied space) by this value.
{{XRCompositionLayer/opacity}} is <code>1.0</code> by default. Setting {{XRCompositionLayer/opacity}} to a value less than <code>0</code> will set it to <code>0</code> and setting it to a value higher than <code>1.0</code> will set it to <code>1.0</code>.
The <dfn attribute for="XRCompositionLayer">needsRedraw</dfn> attribute signals that the {{XRCompositionLayer}} should be
rerendered in the next [=XR animation frame=]. It MAY be set when [=the underlying resources of a layer are lost=] or
when the [=XR Compositor=] can no longer reproject the layer. Failing to redraw the content in the next [=XR animation frame=]
might cause flickering or other side effects.
The <dfn attribute for="XRCompositionLayer">mipLevels</dfn> attribute returns the depth of the mip chain. This MUST be equal
or smaller than the value requested in {{XRLayerInit/mipLevels}}.
NOTE: some platforms don't support mip levels. Authors should query {{XRCompositionLayer/mipLevels}} to determine if they can
target a certain mip level and not rely on the value they passed in {{XRLayerInit/mipLevels}}.
The <dfn attribute for="XRCompositionLayer">quality</dfn> attribute sets and returns the quality of the {{XRCompositionLayer}}. {{XRLayerQuality/default}} is the initial value.
<div class="algorithm" data-algorithm="redrawLayerAlgo">
When <dfn>the underlying resources of a layer are lost</dfn> for an {{XRCompositionLayer}} |layer|,
the user agent MUST run the following steps:
1. Set |layer|'s {{XRCompositionLayer/needsRedraw}} to <code>true</code>.
1. If |layer| is not an {{XRProjectionLayer}}, [=queue a task=] to [=fire an event=] named {{redraw}} using {{XRLayerEvent}} on |layer|.
</div>
{{destroy()}} will delete the underlying attachments. If there are no attachments, this function does nothing.
<div class="algorithm" data-algorithm="intialization of a composition layer">
To <dfn>intialize a composition layer</dfn> with a {{XRSession}} |session| and an optional instance of a {{WebGLRenderingContext}}
or a {{WebGL2RenderingContext}} |context|, the user agent MUST run the following steps:
1. Set [=this=] [=XRCompositionLayer/session=] to |session|.
1. If |context| is defined, set [=this=] [=XRCompositionLayer/context=] to |context|.
1. Set [=this=] {{XRCompositionLayer/blendTextureSourceAlpha}} to <code>true</code>.
1. Set [=this=] {{XRCompositionLayer/opacity}} to <code>1.0</code>.
</div>
<div class="algorithm" data-algorithm="calling destroy on a layer">
When calling {{destroy()}}, the user agent MUST run the following steps:
1. Set [=this=] [=colorTextures=] array to an empty array.
1. Set [=this=] [=depthStencilTextures=] array to an empty array.
1. Destroy the underlying GL attachments.
</div>
Each {{XRCompositionLayer}} has a <dfn for="XRCompositionLayer">context</dfn> object which is an instance
of either null or a {{WebGLRenderingContext}} or a {{WebGL2RenderingContext}} and a <dfn for="XRCompositionLayer">media</dfn>
object which is an instance of null or a {{HTMLVideoElement}}.
Each {{XRCompositionLayer}} has an associated <dfn for="XRCompositionLayer">session</dfn>, which is the
{{XRSession}} it was created with.
<!--
# we might need this at a later stage.
If the {{XRCompositionLayer}} was created by {{XRWebGLBinding}}, it MUST have a <dfn>list of viewports</dfn> which is a
[=/list=] containing one [=WebGL viewport=] for each {{XRView}} the {{XRSession}} currently exposes. The viewports MUST
have a {{XRViewport/width}} and {{XRViewport/height}} greater than <code>0</code> and MUST describe a rectangle that does
not exceed the bounds of the {{XRCompositionLayer}}.
-->
<div class="algorithm" data-algorithm="setting the space on a layer">
When <dfn>setting the space on a layer</dfn> with {{XRSpace}} |space| and {{XRCompositionLayer}} |layer|, the user agent MUST run the following steps to validate if the |space| is valid:
1. If |space| is <code>null</code>, throw {{TypeError}} and abort these steps.
1. If |space|'s [=XRSpace/session=] is not equal to the |layer|'s [=XRCompositionLayer/session=], throw {{TypeError}} and abort these steps.
</div>
{{XRCompositionLayer}} has an internal boolean <dfn for="XRCompositionLayer">isStatic</dfn> that indicates that the author can only draw
to this layer when {{XRCompositionLayer/needsRedraw}} is <code>true</code>.
NOTE: if [=XRCompositionLayer/isStatic=] is <code>true</code> the author can only draw into the layer once after creation or once after
a redraw event. This allows the UA to only allocate a single GPU buffer.
When a writeable attribute is set on an {{XRCompositionLayer}} or any of its derived classes,
reading that attribute MUST return that value.
At the end of the {{XRSession/requestAnimationFrame()}} callback, the value MUST be sent to
the underlying [=XR Compositor=]. The [=XR Compositor=] MUST apply the value next time it presents
the {{XRFrame}} that was passed to the {{XRSession/requestAnimationFrame()}} callback.
NOTE: this means that the values must be applied when the [=XR Compositor=] redraws the scene using
the new {{XRFrame}}, even if there was no change in the {{XRWebGLSubImage/colorTexture}} associated
with the {{XRCompositionLayer}} or the videoframe associated with a media layer. If the
[=XR Compositor=] redraws the scene with the previous {{XRFrame}}'s state, it must not use the new
values.
XRProjectionLayer {#xrprojectionlayertype}
-----------------
An {{XRProjectionLayer}} is a layer that fills the entire view of the observer.
Projection layers should be refreshed close to the device's native frame rate.
<img alt="representation of a projection layer" src="images/projection-layer.jpg" style="width:50%; height: 50%; border-style: ridge;">
<pre class="idl">
[Exposed=Window] interface XRProjectionLayer : XRCompositionLayer {
readonly attribute unsigned long textureWidth;
readonly attribute unsigned long textureHeight;
readonly attribute unsigned long textureArrayLength;
readonly attribute boolean ignoreDepthValues;
attribute float? fixedFoveation;
attribute XRRigidTransform? deltaPose;
};
</pre>
The <dfn attribute for="XRProjectionLayer">textureWidth</dfn> attribute returns the width in pixels of
the [=colorTextures=] textures of this layer.
The <dfn attribute for="XRProjectionLayer">textureHeight</dfn> attribute returns the height in pixels of
the [=colorTextures=] textures of this layer.
The <dfn attribute for="XRProjectionLayer">textureArrayLength</dfn> attribute returns the number of layers of
the [=colorTextures=] textures of this layer if the {{XRProjectionLayer}} was initialized with a
{{XRProjectionLayerInit/textureType}} of {{"texture-array"}}. Otherwise it will return <code>1</code>.
The <dfn attribute for="XRProjectionLayer">fixedFoveation</dfn> attribute controls the amount of foveation used by the
[=XR Compositor=]. If the user agent or device does not support this attribute, they
should return <code>null</code> on getting, and setting should be a <code>no-op</code>.
Setting {{XRProjectionLayer/fixedFoveation}} to a value less than <code>0</code> will set it to <code>0</code> and setting it to
a value higher than <code>1</code> will set it to <code>1</code>. <code>0</code> sets the minimum amount of foveation while
<code>1</code> set the maximum. It is up to the user agent how the [=XR Compositor=] interprets these values.
If the {{XRProjectionLayer/fixedFoveation}} level was changed, it will take effect at the next {{XRFrame}}.
The <dfn attribute for="XRProjectionLayer">ignoreDepthValues</dfn> attribute, if <code>true</code>, indicates that the
[=XR Compositor=] MUST NOT make use of values in the depth buffer attachment when rendering. When the attribute
is <code>false</code> it indicates that the content of the depth buffer attachment will be used by the
[=XR Compositor=] and is expected to be representative of the scene rendered into the layer.
<div class="unstable">
The <dfn attribute for="XRProjectionLayer">deltaPose</dfn> attribute controls the amount of foveation used by the
[=XR Compositor=]. If the user agent or device does not support this attribute or the
"[=feature descriptor/space-warp=]" [=feature descriptor=] was not requested, they
should return <code>null</code> on getting, and setting should be a <code>no-op</code>. This attribute describes the
incremental application-applied transform, if any, since the previous frame that affects the view. When artificial
locomotion happens, the experience transforms the whole world from one application pose to another pose between frames
and {{XRProjectionLayer/deltaPose}} MUST be populated with the difference in the scene's world position.
The {{XRProjectionLayer/deltaPose}} should be identity when there is no transformation between the previous and the current {{XRFrame}}.
</div>
XRQuadLayer {#xrquadlayertype}
-----------
An {{XRQuadLayer}} renders a layer that takes up a flat rectangular space in the virtual environment.
Only the front of the layer MUST be visible; the back face MUST NOT be drawn by the [=XR Compositor=].
A XRQuadLayer has no thicknes. It is a two-dimensional object positioned and oriented in 3D space. The position
of a quad refers to the center of the quad.
<img alt="representation of a quad layer" src="images/quad-layer.jpg" style="width:50%; height: 50%; border-style: ridge;">
<pre class="idl">
[Exposed=Window] interface XRQuadLayer : XRCompositionLayer {
attribute XRSpace space;
attribute XRRigidTransform transform;
attribute float width;
attribute float height;
// Events
attribute EventHandler onredraw;
};
</pre>
The <dfn attribute for="XRQuadLayer">transform</dfn> attributes sets and returns the offset and orientation relative to the
<dfn attribute for="XRQuadLayer">space</dfn> attribute. The {{XRQuadLayer/transform}} and {{XRQuadLayer/space}} attributes
establish the spatial relationship of the layer within the user’s physical environment.
When setting the {{XRQuadLayer/space}}, first run the steps for [=setting the space on a layer=].
The <dfn attribute for="XRQuadLayer">width</dfn> and <dfn attribute for="XRQuadLayer">height</dfn> attributes
set and return the width and height of the layer in meters.
<div class="algorithm" data-algorithm="initQuadLayerAlgo">
When <dfn lt="initialize a quad layer">initializing an {{XRQuadLayer}} |layer| with an {{XRQuadLayerInit}} |init|</dfn>, the user agent MUST run the following steps:
1. Initialize |layer|'s {{XRQuadLayer/width}} to |init|'s {{XRQuadLayerInit/width}}.
1. Initialize |layer|'s {{XRQuadLayer/height}} to |init|'s {{XRQuadLayerInit/height}}.
1. Let |layer|'s {{XRQuadLayer/space}} be the |init|'s {{XRLayerInit/space}}.
1. Initialize |layer|'s {{XRQuadLayer/transform}} as follows:
<dl class="switch">
<dt class="switch">If |init|'s {{XRQuadLayerInit/transform}} is set
<dd> Let |layer|'s {{XRQuadLayer/transform}} be a [=new=] {{XRRigidTransform}} in the [=relevant realm=] of |layer| initialized with {{XRRigidTransform/position}} and {{XRRigidTransform/orientation}} of |init|'s {{XRQuadLayerInit/transform}}.
<dt> Otherwise
<dd> Let |layer|'s {{XRQuadLayer/transform}} be a [=new=] {{XRRigidTransform}} in the [=relevant realm=] of |layer| initialized with a {{DOMPointInit}} position of <code>{ x: 0.0, y: 0.0, z: 0.0, w: 1.0 }</code>.
</dl>
1. Initialize |layer|'s [=XRCompositionLayer/isStatic=] to |init|'s {{XRLayerInit/isStatic}}
</div>
The <dfn attribute for="XRQuadLayer">onredraw</dfn> attribute is an Event handler IDL attribute for the {{redraw}} event type.
XRCylinderLayer {#xrcylinderayertype}
---------------
An {{XRCylinderLayer}} renders a layer that takes up a curved rectangular space in the virtual environment.
Only the front of the layer MUST be visible; the back face MUST NOT be drawn by the [=XR Compositor=].
<img alt="representation of a cylinder layer" src="images/cylinder-layer.png" style="width:50%; height: 50%; border-style: ridge;">
A XRCylinderLayer has no thicknes. It is a two-dimensional object positioned and oriented in 3D space. The position
of the cylinder refers to the center of the quad.
<pre class="idl">
[Exposed=Window] interface XRCylinderLayer : XRCompositionLayer {
attribute XRSpace space;
attribute XRRigidTransform transform;
attribute float radius;
attribute float centralAngle;
attribute float aspectRatio;
// Events
attribute EventHandler onredraw;
};
</pre>
The <dfn attribute for="XRCylinderLayer">transform</dfn> attribute sets and returns the offset and orientation relative to the
<dfn attribute for="XRCylinderLayer">space</dfn> attribute. The {{XRCylinderLayer/transform}} and {{XRCylinderLayer/space}} attributes
establish the spatial relationship of the layer within the user’s physical environment.
When setting the {{XRCylinderLayer/space}}, first run the steps for [=setting the space on a layer=].
The <dfn attribute for="XRCylinderLayer">radius</dfn> attribute controls the radius in meters of the cylinder.
The <dfn attribute for="XRCylinderLayer">centralAngle</dfn> attribute controls the angle in radians of the visible section of the cylinder.
It grows symmetrically around the 0 angle.
The <dfn attribute for="XRCylinderLayer">aspectRatio</dfn> attribute controls the ratio of the visible cylinder section. It is the ratio of the width of the visible section of the cylinder divided by its height. The width is calculated by multiplying the {{XRCylinderLayer/radius}} with the {{XRCylinderLayer/centralAngle}}.
<img alt="description of the parameters of a cylinder layer" src="images/cylinder_layer_params.png" style="width: 80%; height: 80%;">
<div class="algorithm" data-algorithm="initCylinderLayerAlgo">
When <dfn lt="initialize a cylinder layer">initializing an {{XRCylinderLayer}} |layer| with an {{XRCylinderLayerInit}} |init|</dfn>, the user agent MUST run the following steps:
1. Initialize |layer|'s {{XRCylinderLayer/radius}} to |init|'s {{XRCylinderLayerInit/radius}}.
1. Initialize |layer|'s {{XRCylinderLayer/centralAngle}} to |init|'s {{XRCylinderLayerInit/centralAngle}}.
1. Initialize |layer|'s {{XRCylinderLayer/aspectRatio}} to |init|'s {{XRCylinderLayerInit/aspectRatio}}.
1. Let |layer|'s {{XRCylinderLayer/space}} be the |init|'s {{XRLayerInit/space}}.
1. Initialize |layer|'s {{XRCylinderLayer/transform}} as follows:
<dl class="switch">
<dt class="switch">If |init|'s {{XRCylinderLayerInit/transform}} is set
<dd> Let |layer|'s {{XRCylinderLayer/transform}} be a [=new=] {{XRRigidTransform}} in the [=relevant realm=] of |layer| initialized with {{XRRigidTransform/position}} and {{XRRigidTransform/orientation}} of |init|'s {{XRCylinderLayerInit/transform}}.
<dt> Otherwise
<dd> Let |layer|'s {{XRCylinderLayer/transform}} be a [=new=] {{XRRigidTransform}} in the [=relevant realm=] of |layer| initialized with a {{DOMPointInit}} position of <code>{ x: 0.0, y: 0.0, z: 0.0, w: 1.0 }</code>.
</dl>
1. Initialize |layer|'s [=XRCompositionLayer/isStatic=] to |init|'s {{XRLayerInit/isStatic}}
</div>
The <dfn attribute for="XRCylinderLayer">onredraw</dfn> attribute is an Event handler IDL attribute for the {{redraw}} event type.
XREquirectLayer {#xrequirectlayertype}
---------------
An {{XREquirectLayer}} renders a layer where the [=XR Compositor=] MUST map an equirectangular coded data onto the inside of a sphere.
<img alt="representation of an equirect layer" src="images/equirect-layer.png" style="width:50%; height: 50%; border-style: ridge;">
ISSUE: this section needs clarification
<pre class="idl">
[Exposed=Window] interface XREquirectLayer : XRCompositionLayer {
attribute XRSpace space;
attribute XRRigidTransform transform;
attribute float radius;
attribute float centralHorizontalAngle;
attribute float upperVerticalAngle;
attribute float lowerVerticalAngle;
// Events
attribute EventHandler onredraw;
};
</pre>
The <dfn attribute for="XREquirectLayer">transform</dfn> attribute sets and returns the offset and orientation relative to
{{XREquirectLayer/space}}. The {{XREquirectLayer/transform}} attribute and the {{XREquirectLayer/space}}
establish the spatial relationship of the layer within the user’s physical environment.
The <dfn attribute for="XREquirectLayer">radius</dfn> attribute is the non-negative radius in meters of the sphere. Values of <code>zero</code> or <code>infinity</code> are treated as an infinite sphere.
Setting {{XREquirectLayer/radius}} to a value less than <code>0</code> will set it to <code>0</code>.
The <dfn attribute for="XREquirectLayer">centralHorizontalAngle</dfn>, <dfn attribute for="XREquirectLayer">upperVerticalAngle</dfn>
and <dfn attribute for="XREquirectLayer">lowerVerticalAngle</dfn> attributes set and return how the texture is mapped to the sphere.
Setting {{XREquirectLayer/centralHorizontalAngle}} to a value less than 0 will set it to 0 and setting it to
a value higher than 2π will set it to 2π.
Setting {{XREquirectLayer/upperVerticalAngle}} or {{XREquirectLayer/lowerVerticalAngle}} to a value less than -π/2 will set it
to -π/2 and setting it to a value higher than π/2 will set it to π/2.
<img alt="description of the parameters of an equirect layer" src="images/equirect.png" style="width:50%; height: 50%;">
When assigning an {{XRSpace}} to the {{XREquirectLayer/space}} attribute, first run the following steps.
<div class="algorithm" data-algorithm="setting the space on an equirect layer">
When <var ignore>setting the space on an equirect layer</var> with {{XRSpace}} |space| and {{XREquirectLayer}} |layer|, the user agent MUST run the following steps to validate if the |space| is valid:
1. If |init|'s {{XRLayerInit/space}} is not an instance of type {{XRReferenceSpace}}, throw {{TypeError}} and abort these steps.
1. If |init|'s {{XRLayerInit/space}} has a [=XRReferenceSpace/type=] of {{XRReferenceSpaceType/"viewer"}}, throw {{TypeError}} and abort these steps.
1. Run [=setting the space on a layer=] with |space| and |layer|.
</div>
<div class="algorithm" data-algorithm="initEquirectLayerAlgo">
When <dfn lt="initialize a equirect layer">initializing an {{XREquirectLayer}} |layer| with an {{XREquirectLayerInit}} |init|</dfn>, the user agent MUST run the following steps:
1. Initialize |layer|'s {{XREquirectLayer/radius}} to |init|'s {{XREquirectLayerInit/radius}}.
1. Initialize |layer|'s {{XREquirectLayer/centralHorizontalAngle}} to |init|'s {{XREquirectLayerInit/centralHorizontalAngle}}.
1. Initialize |layer|'s {{XREquirectLayer/upperVerticalAngle}} to |init|'s {{XREquirectLayerInit/upperVerticalAngle}}.
1. Initialize |layer|'s {{XREquirectLayer/lowerVerticalAngle}} to |init|'s {{XREquirectLayerInit/lowerVerticalAngle}}.
1. Let |layer|'s {{XREquirectLayer/space}} be the |init|'s {{XRLayerInit/space}}.
1. Initialize |layer|'s {{XREquirectLayer/transform}} as follows:
<dl class="switch">
<dt class="switch">If |init|'s {{XREquirectLayerInit/transform}} is set
<dd> Let |layer|'s {{XREquirectLayer/transform}} be a [=new=] {{XRRigidTransform}} in the [=relevant realm=] of |layer| initialized with {{XRRigidTransform/position}} and {{XRRigidTransform/orientation}} of |init|'s {{XREquirectLayerInit/transform}}.
<dt> Otherwise
<dd> Let |layer|'s {{XREquirectLayer/transform}} be a [=new=] {{XRRigidTransform}} in the [=relevant realm=] of |layer|.
</dl>
1. Initialize |layer|'s [=XRCompositionLayer/isStatic=] to |init|'s {{XRLayerInit/isStatic}}
</div>
The <dfn attribute for="XREquirectLayer">onredraw</dfn> attribute is an Event handler IDL attribute for the {{redraw}} event type.
XRCubeLayer {#xcubelayertype}
-----------
A {{XRCubeLayer}} renders a layer where the [=XR Compositor=] renders directly from a cubemap.
<img alt="representation of a cube layer" src="images/cube-layer.jpg" style="width:50%; height: 50%; border-style: ridge;">
ISSUE: this section needs clarification
<pre class="idl">
[Exposed=Window] interface XRCubeLayer : XRCompositionLayer {
attribute XRSpace space;
attribute DOMPointReadOnly orientation;
// Events
attribute EventHandler onredraw;
};
</pre>
The <dfn attribute for="XRCubeLayer">orientation</dfn> attribute sets and returns the orientation relative to the
<dfn attribute for="XRCubeLayer">space</dfn> attribute. The {{XRCubeLayer/orientation}} and {{XRCubeLayer/space}} attributes
establish the spatial relationship of the layer within the user’s physical environment.
When placing the {{XRCubeLayer}} only the orientation of the {{XRCubeLayer/space}} is considered. The cube layer will always be rendered
with the view point at the center.
When assigning an {{XRSpace}} to the {{XRCubeLayer/space}} attribute, first run the following steps.
<div class="algorithm" data-algorithm="setting the space on a cube layer">
When <var ignore>setting the space on an cube layer</var> with {{XRSpace}} |space| and {{XRCubeLayer}} |layer|, the user agent MUST run the following steps to validate if the |space| is valid:
1. If |init|'s {{XRLayerInit/space}} is not an instance of type {{XRReferenceSpace}}, throw {{TypeError}} and abort these steps.
1. If |init|'s {{XRLayerInit/space}} has a [=XRReferenceSpace/type=] of {{XRReferenceSpaceType/"viewer"}}, throw {{TypeError}} and abort these steps.
1. Run [=setting the space on a layer=] with |space| and |layer|.
</div>
The <dfn attribute for="XRCubeLayer">onredraw</dfn> attribute is an Event handler IDL attribute for the {{redraw}} event type.
Spaces {#spaces}
======
{{XRProjectionLayer}} and {{XRWebGLLayer}} don't have associated an {{XRSpace}} because they render to the full frame.
{{XRCubeLayer}} and {{XREquirectLayer}} MUST only support {{XRReferenceSpace|XRReferenceSpaces}} that are not of type {{"viewer"}}.
{{XRQuadLayer}} and {{XRCylinderLayer}} MUST support all {{XRSpace}} types.
<section class="non-normative">
Generally, developers should not use of {{"viewer"}} space to stabilize layers, as this will almost always defeat positional or
rotational reprojection and result in a loss in stability of the rendered content relative to the world. The exception being small UI elements
like a gaze cursor or targeting reticle.
Following are some best practices of spaces to use with a layer type:
- {{XRQuadLayer}} with {{"viewer"}} space: Head-locked constant-size reticle in center of screen.
- {{XRQuadLayer}} or {{XRCylinderLayer}} in {{"local"}}, {{"unbounded"}} space: springy body-locked UI.
- {{XRQuadLayer}} or {{XRCylinderLayer}} in {{"local"}}, {{"local-floor"}}, {{"unbounded"}}, {{"bounded-floor"}} or anchor space: world-locked video, placed by the user.
- {{XREquirectLayer}} or {{XRCubeLayer}} in {{"local"}} space: 360-degree video or skybox.
</section>
Rendering {#rendering}
=========
XRSubImage {#xrsubimagetype}
----------
The {{XRSubImage}} object represents what viewport of the GPU texture to use.
<pre class="idl">
[Exposed=Window] interface XRSubImage {
[SameObject] readonly attribute XRViewport viewport;
};
</pre>
NOTE: this class is designed to accomodate future extensions
The <dfn attribute for="XRSubImage">viewport</dfn> attribute returns the {{XRViewport}} to use when rendering the sub image.
XRWebGLSubImage {#xrwebglsubimagetype}
---------------
The {{XRWebGLSubImage}} object is used during rendering of the layer.
<pre class="idl">
[Exposed=Window] interface XRWebGLSubImage : XRSubImage {
[SameObject] readonly attribute WebGLTexture colorTexture;
[SameObject] readonly attribute WebGLTexture? depthStencilTexture;
[SameObject] readonly attribute WebGLTexture? motionVectorTexture;
readonly attribute unsigned long? imageIndex;
readonly attribute unsigned long colorTextureWidth;
readonly attribute unsigned long colorTextureHeight;
readonly attribute unsigned long? depthStencilTextureWidth;
readonly attribute unsigned long? depthStencilTextureHeight;
readonly attribute unsigned long? motionVectorTextureWidth;
readonly attribute unsigned long? motionVectorTextureHeight;
};
</pre>
The <dfn attribute for="XRWebGLSubImage">colorTexture</dfn> attribute returns the color [=opaque texture=] for the {{XRCompositionLayer}}.
The <dfn attribute for="XRWebGLSubImage">depthStencilTexture</dfn> attribute returns the depth/stencil [=opaque texture=] for the {{XRCompositionLayer}}.
If the layer was created without depth/stencil, this attribute returns null.
<div class="unstable">
The <dfn attribute for="XRWebGLSubImage">motionVectorTexture</dfn> attribute returns the motion [=opaque texture=] for the {{XRProjectionLayer}}.
If the {{XRSession}} was created without the [=feature descriptor/space-warp=] [=feature descriptor=] or the layer is not a {{XRProjectionLayer}}, this attribute MUST return null.
</div>
The <dfn attribute for="XRWebGLSubImage">imageIndex</dfn> attribute returns the offset into the texture array. Valid only for layers
that were requested with {{texture-array}}.
The <dfn attribute for="XRWebGLSubImage">colorTextureWidth</dfn> and <dfn attribute for="XRWebGLSubImage">depthStencilTextureHeight</dfn> attributes
return the width and height in pixels of the GL depth attachments
<div class="unstable">
The <dfn attribute for="XRWebGLSubImage">depthStencilTextureWidth</dfn> and <dfn attribute for="XRWebGLSubImage">colorTextureHeight</dfn> attributes
return the width and height in pixels of the GL color attachments. If the layer was created without depth/stencil, this attribute returns null.
The <dfn attribute for="XRWebGLSubImage">motionVectorTextureWidth</dfn> and <dfn attribute for="XRWebGLSubImage">motionVectorTextureHeight</dfn> attributes
return the width and height in pixels of the GL motion vector attachments.
If the {{XRSession}} was created without the [=feature descriptor/space-warp=] [=feature descriptor=] or the layer is not a {{XRProjectionLayer}}, these attributes MUST return null.
</div>
XRTextureType {#xrtexturetype}
-------------
The {{XRTextureType}} enum defines what type of texture is allocated.
<pre class="idl">
enum XRTextureType {
"texture",
"texture-array"
};
</pre>
- A texture type of <dfn enum-value for="XRTextureType">texture</dfn> indicates that the textures of {{XRWebGLSubImage}} MUST be of type {{TEXTURE_2D}}
- A texture type of <dfn enum-value for="XRTextureType">texture-array</dfn> indicates that the textures of {{XRWebGLSubImage}} MUST be of type {{TEXTURE_2D_ARRAY}}
GPU layer and view creation {#gpulayer}
===========================
Overview {#xrgpulayeroverview}
--------
<section class="non-normative">
When a layer is created it is backed by a GPU resource, typically a texture, provided by one of the Web platform's graphics APIs. In order to
specify which API is providing the layer's GPU resources an {{XRWebGLBinding}} for the API in question must be created.
Each graphics API may have unique requirements that must be satisfied before a context can be used in the creation of a layer. For example,
a {{WebGLRenderingContext}} must have its xrCompatible flag set prior to being passed to the constructor of the {{XRWebGLBinding}} instance.
Any interaction between the {{XRSession}} the graphics API, such as allocating or retrieving textures, will go through this {{XRWebGLBinding}} instance, and the exact mechanics
of the interaction will typically be API specific. This allows the rest of the WebXR API to be
graphics API agnostic and more easily adapt to future advances in rendering techniques.
Once an {{XRWebGLBinding}} instance has been acquired, it can be used to create a variety of {{XRCompositionLayer}}. Any layers created by that instance will then be able
to query the associated GPU resources each frame, generally expected to be the native API's texture interface.
The various layer types are created with the create____Layer series of methods on the {{XRWebGLBinding}} instance. Information about the graphics resources required,
such as whether or not to allocate a depth buffer or alpha channel, are passed in at layer creation time and will be immutable for the lifetime of the layer.
The method will return the associated XRCompositionLayer type.
Some layer types may not be supported by the {{XRSession}}. If a layer type isn't supported the method will throw an exception. {{XRProjectionLayer}} MUST be supported by all {{XRSession}}s.
</section>
Opaque textures {#xropaquetextures}
---------------
When using WebXR GPU layers, the {{XRWebGLBinding}} object will return instances of an <dfn>opaque texture</dfn> for the color and depth/stencil attachments.
An [=opaque texture=] functions identically to a standard {{WebGLTexture}} with the following changes:
- An [=opaque texture=] is considered invalid outside of a {{XRSession/requestAnimationFrame()}} callback for its session.
- An [=opaque texture=] is invalid until it is returned by the {{XRWebGLBinding/getSubImage()}} or {{XRWebGLBinding/getViewSubImage()}} calls.
- The [=XR Compositor=] MUST assume that the [=opaque texture=] for the color attachment contains colors with premultiplied alpha.
- At the end of the {{XRSession/requestAnimationFrame()}} callback the texture MUST be unbounded and detached from all {{WebGLShader}} objects.
- An [=opaque texture=] MUST behave as though it was allocated with [=texStorage2D=] or [=texStorage3D=], as appropriate, even when using a WebGL 1.0 context.
- A call to {{deleteTexture}} with an [=opaque texture=] MUST generate an {{INVALID_OPERATION}} error.
The buffers attached to an [=opaque texture=] MUST be cleared to the values in the table below during the processing of the first call to {{XRWebGLBinding/getViewSubImage()}} or {{XRWebGLBinding/getSubImage()}} in each [=XR animation frame=] when {{XRProjectionLayerInit/clearOnAccess}} is <code>true</code>.
If {{XRProjectionLayerInit/clearOnAccess}} is <code>false</code>, the buffers attached to an [=opaque texture=] MUST be cleared the first time that they are accessed. Subsequent accesses in later frames MAY NOT clear the buffers.
<table class="tg">
<thead>
<tr>
<th>Buffer</th>
<th>Clear Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Color</td>
<td>(0, 0, 0, 0)</td>
</tr>
<tr>
<td>Depth</td>
<td>1.0</td>
</tr>
<tr>
<td>Stencil</td>
<td>0</td>
</tr>
</tbody>
</table>
If the [=opaque texture=] was created with <code>2</code> or more {{XRLayerInit/mipLevels}},
the author SHOULD populate all the mip levels. The user agent MUST NOT assume that it should create the mip levels.
NOTE: the [=opaque texture|opaque textures=] are allocated when the layer is contructed using the
[=allocate color textures=] and [=allocate depth textures=] algoritms. The side effect of this pre-allocation is that calling
{{XRWebGLBinding/getSubImage()}} and {{XRWebGLBinding/getViewSubImage()}} with the same parameters will always return the same texture objects.
NOTE: Changes to the dimensions or format of the [=opaque texture|opaque textures=] are not allowed. GL commands
may only alter the texel values and texture parameters. Using any of the following
commands with the WebGLTexture will result in an INVALID_OPERATION error
being generated, even if it does not affect the dimensions or format: TexImage*, CompressedTexImage*, CopyTexImage* and TexStorage*.
The <a href="https://www.khronos.org/registry/OpenGL/specs/es/3.0/es_spec_3.0.pdf#nameddest=section-3.8.4">"Immutable-Format Texture Images"</a>
section in the OpenGL ES 3.0 spec defines these limitations in more detail.
Allocation of the resources for layers (such as memory) MUST be done through the same mechanism as WebGL.
If an {{XRLayer}} is allocated with the {{RGBA}} or {{RGB}} {{XRLayerInit/colorFormat}}, its [=colorTextures=] MUST be exposed as {{RGBA}} or {{RGB}} to the {{WebGLRenderingContext}} context.
However, the [=XR Compositor=] MUST treat the [=colorTextures=]'s pixels as if they were in the {{SRGB8_ALPHA8}} or {{SRGB8}} {{XRLayerInit/colorFormat}}.
NOTE: this means that the [=XR Compositor=] MUST NOT do any gamma conversion from linear {{RGBA}} or {{RGB}} when it processes the [=colorTextures=]. Otherwise, the pixels in the final rendering will appear too bright which will not match the rendering on a regular 2D {{WebGLRenderingContext}} context.
XRProjectionLayerInit {#xrprojectionlayerinittype}
---------------------
The {{XRProjectionLayerInit}} dictionary represents a set of configurable values that describe how an {{XRProjectionLayer}}
is initialized.
<pre class="idl">
dictionary XRProjectionLayerInit {
XRTextureType textureType = "texture";
GLenum colorFormat = 0x1908; // RGBA
GLenum depthFormat = 0x1902; // DEPTH_COMPONENT
double scaleFactor = 1.0;
boolean clearOnAccess = true;
};
</pre>
The <dfn dict-member for="XRProjectionLayerInit">textureType</dfn> attribute defines the type of texture that the layer will have.
The <dfn dict-member for="XRProjectionLayerInit">colorFormat</dfn> attribute defines the data type of the color texture data.
This is the <dfn>list of color formats for projection layers</dfn> that the [=XR Compositor=] MUST support:
- {{RGBA}}
- {{RGB}}
- {{SRGB_EXT}} for contexts with the '{{EXT_sRGB}}' [=extension=] enabled
- {{SRGB_ALPHA_EXT}} for contexts with the '{{EXT_sRGB}}' [=extension=] enabled
For WebGL2 contexts these additional formats are supported:
- {{RGBA8}}
- {{RGB8}}
- {{SRGB8}}
- {{SRGB8_ALPHA8}}
The <dfn dict-member for="XRProjectionLayerInit">depthFormat</dfn> attribute defines the data type of the depth texture data.
If {{XRProjectionLayerInit/depthFormat}} is <code>0</code> the layer will not provide a depth/stencil texture.
This is the <dfn>list of depth formats for projection layers</dfn> that the [=XR Compositor=] MUST support:
For {{WebGLRenderingContext}} contexts with the '{{WEBGL_depth_texture}}' [=extension=] enabled or WebGL2 contexts:
- {{DEPTH_COMPONENT}}
- {{DEPTH_STENCIL}}
If the extension was not enabled, the request for a depth texture is ignored.
NOTE: this could be confusing to authors because they might expect a depth texture. If possible, provide a warning with the reason why the texture was not created.
For {{WebGL2RenderingContext}} contexts these additional formats are supported:
- {{DEPTH_COMPONENT24}}
- {{DEPTH24_STENCIL8}}
The <dfn dict-member for="XRProjectionLayerInit">scaleFactor</dfn> attribute defines the value that the |session|'s
[=recommended WebGL framebuffer resolution=] MUST be multiplied by determining the resolution of the layer's attachments.
The <dfn dict-member for="XRProjectionLayerInit">clearOnAccess</dfn> attribute defines if the texture associated with this layer should be cleared in the initial frame or on every frame.
NOTE: the {{XRProjectionLayerInit}} dictionary does not have support to configure {{XRLayerInit/mipLevels}} like
{{XRLayerInit}}. If a user agent wants to support mipmapping on projection layers, it is free to allocate the texture with mips.
In that case the user agent (and not the author) is responsible for generating all the mip levels.
XRLayerInit {#xrlayerinittype}
---------------------
The {{XRLayerInit}} dictionary represents a set of common configurable values for {{XRQuadLayer}}, {{XRCylinderLayer}},
{{XREquirectLayer}} and {{XRCubeLayer}} .
<pre class="idl">
dictionary XRLayerInit {
required XRSpace space;
GLenum colorFormat = 0x1908; // RGBA
GLenum? depthFormat;
unsigned long mipLevels = 1;
required unsigned long viewPixelWidth;
required unsigned long viewPixelHeight;
XRLayerLayout layout = "mono";
boolean isStatic = false;
boolean clearOnAccess = true;
};
</pre>
The <dfn dict-member for="XRLayerInit">space</dfn> attribute defines the spatial relationship with the user’s physical environment.
The <dfn dict-member for="XRLayerInit">colorFormat</dfn> attribute defines the data type of the color texture data.