Skip to main content

XR8.GlTextureRenderer.pipelineModule()

XR8.GlTextureRenderer.pipelineModule({ vertexSource, fragmentSource, toTexture, flipY })

Description

Creates a pipeline module that draws the camera feed to the canvas.

Parameters

ParameterTypeDefaultDescription
vertexSource [Optional]StringA no-op vertex shaderThe vertex shader source to use for rendering.
fragmentSource [Optional]StringA no-op fragment shaderThe fragment shader source to use for rendering.
toTexture [Optional]WebGlTextureThe canvasA texture to draw to. If no texture is provided, drawing will be to the canvas.
flipY [Optional]BooleanfalseIf true, flip the rendering upside-down.

Returns

Return value is an object {viewport, shader} made available to onProcessCpu and onUpdate as:

processGpuResult.gltexturerenderer with the following properties:

PropertyTypeDescription
viewport{width, height, offsetX, offsetY}The region of the canvas or output texture to draw to; this can be constructed manually, or using XR8.GlTextureRenderer.fillTextureViewport().
shaderA handle to the shader being used to draw the texture.

processGpuResult.gltexturerenderer.viewport: { width, height, offsetX, offsetY }

PropertyTypeDescription
widthNumberThe width (in pixels) to draw.
heightNumberThe height (in pixels) to draw.
offsetXNumberThe minimum x-coordinate (in pixels) to draw to.
offsetYNumberThe minimum y-coordinate (in pixels) to draw to.

Example

XR8.addCameraPipelineModule(XR8.GlTextureRenderer.pipelineModule())
XR8.addCameraPipelineModule({
name: 'mycamerapipelinemodule',
onProcessCpu: ({ processGpuResult }) => {
const {viewport, shader} = processGpuResult.gltexturerenderer
if (!viewport) {
return
}
const { width, height, offsetX, offsetY } = viewport

// ...
},