GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

XRWebGLSubImage: colorTexture property

WebXR Device API

WebXR Device API

The read-only **`colorTexture`** property of the XRWebGLSubImage interface represents the color WebGLTexture object for the XRCompositionLayer to render.

## Value

An opaque WebGLTexture. See [WebXR opaque textures](/docs/Web/API/WebGLTexture#webxr_opaque_textures) for details.

## Examples

### Using `colorTexture`

The `colorTexture` property can be passed to WebGL2RenderingContext.framebufferTextureLayer() to attach the color texture to a framebuffer.

```js
const xrGlBinding = new XRWebGLBinding(xrSession, gl);
const layer = xrGlBinding.createProjectionLayer({
textureType: "texture-array",
});
const framebuffer = gl.createFramebuffer();

xrSession.updateRenderState({ layers: [layer] });
xrSession.requestAnimationFrame(onXRFrame);

function onXRFrame(time, xrFrame) {
xrSession.requestAnimationFrame(onXRFrame);

gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
const viewport = xrGlBinding.getSubImage(layer, xrFrame).viewport;
gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

for (const view in xrViewerPose.views) {
const subImage = xrGlBinding.getViewSubImage(layer, view);
gl.framebufferTextureLayer(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
subImage.colorTexture,
0,
subImage.imageIndex,
);
gl.framebufferTextureLayer(
gl.FRAMEBUFFER,
gl.DEPTH_ATTACHMENT,
subImage.depthStencilTexture,
0,
subImage.imageIndex,
);

// Render from the viewpoint of xrView
}
}
```

## Specifications

## Browser compatibility

## See also

- WebGL2RenderingContext.framebufferTextureLayer()

source: MDN Web Docs mirror · page

Cite this

"XRWebGLSubImage: colorTexture property". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/XRWebGLSubImage/colorTexture

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·