|
44 | 44 | controllers or menu systems/other UI elements. |
45 | 45 | <a class="back" href="./index.html">Back</a> |
46 | 46 | </p> |
| 47 | + <input type="checkbox" id="texture-array">Use Texture Array</input> |
47 | 48 | </details> |
48 | 49 | </header> |
49 | 50 | <main style='text-align: center;'> |
|
65 | 66 | } |
66 | 67 |
|
67 | 68 | // XR globals. |
| 69 | + let textureArrayCheck = document.getElementById('texture-array'); |
68 | 70 | let xrButton = null; |
69 | 71 | let xrSession = null; |
70 | 72 | let xrRefSpace = null; |
|
80 | 82 |
|
81 | 83 | // Layer globals |
82 | 84 | let proj_layer = null; |
| 85 | + let usingTextureArray = false; |
83 | 86 |
|
84 | 87 | function initXR() { |
85 | 88 | xrButton = new WebXRButton({ |
|
144 | 147 |
|
145 | 148 | session.requestReferenceSpace('local').then((refSpace) => { |
146 | 149 | xrRefSpace = refSpace; |
147 | | - proj_layer = xrGLFactory.createProjectionLayer({ space: refSpace, stencil: false }); |
| 150 | + usingTextureArray = textureArrayCheck.checked; |
| 151 | + proj_layer = xrGLFactory.createProjectionLayer({ |
| 152 | + textureType: usingTextureArray ? 'texture-array' : 'texture', |
| 153 | + space: refSpace, stencil: false }); |
148 | 154 | session.updateRenderState({ layers: [proj_layer] }); |
149 | 155 |
|
150 | 156 | session.requestAnimationFrame(onXRFrame); |
|
183 | 189 | glLayer.framebuffer = xrFramebuffer; |
184 | 190 | viewport = glLayer.viewport; |
185 | 191 | gl.bindFramebuffer(gl.FRAMEBUFFER, xrFramebuffer); |
186 | | - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glLayer.colorTexture, 0); |
187 | | - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, glLayer.depthStencilTexture, 0); |
188 | | - |
189 | | - gl.enable(gl.SCISSOR_TEST); |
190 | | - gl.scissor(viewport.x, viewport.y, viewport.width, viewport.height); |
191 | | - gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
192 | | - gl.disable(gl.SCISSOR_TEST); |
193 | | - |
194 | | - // Gather all the values needed for one view and push it into the |
195 | | - // array of views to be drawn. WebXRView is a utility class that |
196 | | - // holds all the necessary values for drawing a single view. |
197 | | - |
198 | | - // In future samples we'll hide this part away as well by using the |
199 | | - // scene.drawXRViews() function, which handles gathering these |
200 | | - // values internally. |
201 | | - views.push(new WebXRView(view, glLayer, viewport)); |
| 192 | + |
| 193 | + if (usingTextureArray) { |
| 194 | + gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, glLayer.colorTexture, 0, glLayer.imageIndex); |
| 195 | + gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, glLayer.depthStencilTexture, 0, glLayer.imageIndex); |
| 196 | + |
| 197 | + // No need to set the scissor when clearing a layered texture, since only one layer is exposed at a time. |
| 198 | + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 199 | + |
| 200 | + scene.drawViewArray([new WebXRView(view, glLayer, viewport)]); |
| 201 | + } else { |
| 202 | + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, glLayer.colorTexture, 0); |
| 203 | + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, glLayer.depthStencilTexture, 0); |
| 204 | + |
| 205 | + // If you need to clear a non-layered texture you must set the scissor to the sub image viewport. Otherwise |
| 206 | + // you will clear sections of the texture that have already been drawn to by previous views. |
| 207 | + gl.enable(gl.SCISSOR_TEST); |
| 208 | + gl.scissor(viewport.x, viewport.y, viewport.width, viewport.height); |
| 209 | + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 210 | + gl.disable(gl.SCISSOR_TEST); |
| 211 | + |
| 212 | + // Gather all the values needed for one view and push it into the |
| 213 | + // array of views to be drawn. WebXRView is a utility class that |
| 214 | + // holds all the necessary values for drawing a single view. |
| 215 | + |
| 216 | + // In future samples we'll hide this part away as well by using the |
| 217 | + // scene.drawXRViews() function, which handles gathering these |
| 218 | + // values internally. |
| 219 | + views.push(new WebXRView(view, glLayer, viewport)); |
| 220 | + } |
| 221 | + } |
| 222 | + if (!usingTextureArray) { |
| 223 | + scene.drawViewArray(views); |
202 | 224 | } |
203 | | - scene.drawViewArray(views); |
204 | 225 | } |
205 | 226 | scene.endFrame(); |
206 | 227 | } |
|
0 commit comments