|
41 | 41 | Tests that applications that use WebGL 2.0 Multisampled Renderbuffers |
42 | 42 | can succesfully blit the result to an XRWebGLLayer. |
43 | 43 | <a class="back" href="./">Back</a> |
| 44 | + <br/> |
| 45 | + <input type="radio" id="useRenderbuffer" name="xrTarget" value="useRenderbuffer" checked> |
| 46 | + <label for="useRenderbuffer">use renderbuffers</label><br> |
| 47 | + <input type="radio" id="useTexture" value="useTexture" name="xrTarget"> |
| 48 | + <label for="useTexture">use textures</label><br> |
| 49 | + <input type="radio" id="useMultisampleTexture" value="useMSTexture" name="xrTarget" disabled> |
| 50 | + <label for="useTexture">use textures with multisampling</label><br> |
| 51 | + <input type="radio" id="useFoveatedTexture" value="useFoveatedTexture" name="xrTarget" disabled> |
| 52 | + <label for="useFoveatedTexture">use foveated textures</label><br> |
44 | 53 | </p> |
45 | 54 | </details> |
46 | 55 | </header> |
|
59 | 68 | let polyfill = new WebXRPolyfill(); |
60 | 69 | } |
61 | 70 |
|
| 71 | + let xrTargets = document.getElementsByName('xrTarget'); |
| 72 | + |
62 | 73 | // WebXR sample app setup |
63 | 74 | class CustomWebXRSampleApp extends WebXRSampleApp { |
| 75 | + getXRTarget() { |
| 76 | + for(let radio of xrTargets) { |
| 77 | + if(radio.checked) return radio.value; |
| 78 | + } |
| 79 | + } |
| 80 | + |
64 | 81 | onCreateGL() { |
65 | 82 | const gl = createWebGLContext({ |
66 | 83 | webgl2: true, |
|
74 | 91 | this.renderbufferWidth = 1024; |
75 | 92 | this.renderbufferHeight = 1024; |
76 | 93 | this.colorRenderbuffer = gl.createRenderbuffer(); |
| 94 | + this.target = this.getXRTarget(); |
77 | 95 | gl.bindRenderbuffer(gl.RENDERBUFFER, this.colorRenderbuffer); |
78 | 96 | gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 4, gl.RGBA8, this.renderbufferWidth, this.renderbufferHeight); |
79 | 97 |
|
|
85 | 103 | gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, this.colorRenderbuffer); |
86 | 104 | gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this.depthRenderbuffer); |
87 | 105 |
|
| 106 | + this.MRTR = gl.getExtension('WEBGL_multisampled_render_to_texture'); |
| 107 | + if (this.MRTR !== null) { |
| 108 | + document.getElementById("useMultisampleTexture").disabled = false; |
| 109 | + document.getElementById("useFoveatedTexture").disabled = false; |
| 110 | + } |
| 111 | + |
88 | 112 | return gl; |
89 | 113 | } |
90 | 114 |
|
|
103 | 127 | // Assumed to be a XRWebGLLayer for now. |
104 | 128 | let layer = session.renderState.baseLayer; |
105 | 129 |
|
| 130 | + // Rather than binding the layer's framebuffer like usual, bind a framebuffer using a |
| 131 | + // multisampled renderbuffer as the color attachment. |
| 132 | + gl.bindFramebuffer(gl.FRAMEBUFFER, this.multisampleFramebuffer); |
| 133 | + |
106 | 134 | // Check to see if we need to resize the renderbuffer |
107 | 135 | if (layer.framebufferWidth != this.renderbufferWidth || |
108 | | - layer.framebufferHeight != this.renderbufferHeight) { |
| 136 | + layer.framebufferHeight != this.renderbufferHeight || |
| 137 | + ((this.target !== this.getXRTarget()) && session.isImmersive)) { |
109 | 138 | this.renderbufferWidth = layer.framebufferWidth; |
110 | 139 | this.renderbufferHeight = layer.framebufferHeight; |
111 | 140 |
|
112 | | - gl.bindRenderbuffer(gl.RENDERBUFFER, this.colorRenderbuffer); |
113 | | - gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 4, gl.RGBA8, this.renderbufferWidth, this.renderbufferHeight); |
| 141 | + this.target = this.getXRTarget(); |
| 142 | + if (this.target === "useRenderbuffer") { |
| 143 | + gl.bindRenderbuffer(gl.RENDERBUFFER, this.colorRenderbuffer); |
| 144 | + gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 4, gl.RGBA8, this.renderbufferWidth, this.renderbufferHeight); |
114 | 145 |
|
115 | | - gl.bindRenderbuffer(gl.RENDERBUFFER, this.depthRenderbuffer); |
116 | | - gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 4, gl.DEPTH_COMPONENT16, this.renderbufferWidth, this.renderbufferHeight); |
117 | | - } |
| 146 | + gl.bindRenderbuffer(gl.RENDERBUFFER, this.depthRenderbuffer); |
| 147 | + gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 4, gl.DEPTH_COMPONENT16, this.renderbufferWidth, this.renderbufferHeight); |
118 | 148 |
|
119 | | - // Rather than binding the layer's framebuffer like usual, bind a framebuffer using a |
120 | | - // multisampled renderbuffer as the color attachment. |
121 | | - gl.bindFramebuffer(gl.FRAMEBUFFER, this.multisampleFramebuffer); |
| 149 | + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, this.colorRenderbuffer); |
| 150 | + gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, this.depthRenderbuffer); |
| 151 | + } else { |
| 152 | + this.colorTexture = gl.createTexture(); |
| 153 | + this.depthTexture = gl.createTexture(); |
| 154 | + |
| 155 | + gl.bindTexture(gl.TEXTURE_2D, this.colorTexture); |
| 156 | + |
| 157 | + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.renderbufferWidth, this.renderbufferHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); |
| 158 | + |
| 159 | + if (this.target === "useFoveatedTexture") { |
| 160 | + let xrGLFactory = new XRWebGLBinding(frame.session, gl); |
| 161 | + if (xrGLFactory.foveateBoundTexture) { |
| 162 | + xrGLFactory.foveateBoundTexture(gl.TEXTURE_2D, 1); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + if (this.target === "useTexture") { |
| 167 | + gl.bindTexture(gl.TEXTURE_2D, this.depthTexture); |
| 168 | + gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT16, this.renderbufferWidth, this.renderbufferHeight, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_SHORT, null); |
| 169 | + |
| 170 | + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.colorTexture, 0); |
| 171 | + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, this.depthTexture, 0); |
| 172 | + } else { |
| 173 | + gl.bindRenderbuffer(gl.RENDERBUFFER, this.depthRenderbuffer); |
| 174 | + gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 4, gl.DEPTH_COMPONENT16, this.renderbufferWidth, this.renderbufferHeight); |
| 175 | + |
| 176 | + this.MRTR.framebufferTexture2DMultisampleEXT(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.colorTexture, 0, 4); |
| 177 | + } |
| 178 | + |
| 179 | + } |
| 180 | + } |
122 | 181 |
|
123 | 182 | gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
124 | 183 |
|
|
0 commit comments