UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

58 lines 2.87 kB
import { WebGLHardwareTexture } from "../Engines/WebGL/webGLHardwareTexture.js"; import { InternalTexture } from "../Materials/Textures/internalTexture.js"; import { WebXRLayerRenderTargetTextureProvider } from "./webXRRenderTargetTextureProvider.js"; /** * Provides render target textures for WebGL-backed XR layers. Owns all WebGL-specific * framebuffer/texture wiring so the base provider can stay graphics-API-agnostic. * @internal */ export class WebXRWebGLRenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider { _createInternalTexture(textureSize, texture) { const gl = this._engine._gl; if (!gl) { throw new Error("WebXRWebGLRenderTargetTextureProvider requires a WebGL-capable engine."); } const internalTexture = new InternalTexture(this._engine, 0 /* InternalTextureSource.Unknown */, true); internalTexture.width = textureSize.width; internalTexture.height = textureSize.height; internalTexture._hardwareTexture = new WebGLHardwareTexture(texture, gl); internalTexture.isReady = true; return internalTexture; } _createRenderTargetTexture(width, height, framebuffer, colorTexture, depthStencilTexture, multiview) { if (!this._engine) { throw new Error("Engine is disposed"); } const textureSize = { width, height }; const renderTargetTexture = this._createRenderTargetTextureShell(width, height, !!multiview); const renderTargetWrapper = renderTargetTexture.renderTarget; // Set the framebuffer, make sure it works in all scenarios - emulator, no layers and layers. // This must happen before binding any texture, since setTexture binds it to the framebuffer. if (framebuffer || !colorTexture) { renderTargetWrapper._framebuffer = framebuffer; } // Create internal texture if (colorTexture) { if (multiview) { renderTargetWrapper._colorTextureArray = colorTexture; } else { const internalTexture = this._createInternalTexture(textureSize, colorTexture); renderTargetWrapper.setTexture(internalTexture, 0); renderTargetTexture._texture = internalTexture; } } if (depthStencilTexture) { if (multiview) { renderTargetWrapper._depthStencilTextureArray = depthStencilTexture; } else { renderTargetWrapper._depthStencilTexture = this._createInternalTexture(textureSize, depthStencilTexture); } } renderTargetTexture.disableRescaling(); this._renderTargetTextures.push(renderTargetTexture); return renderTargetTexture; } } //# sourceMappingURL=webXRWebGLRenderTargetTextureProvider.js.map