Skip to main content

XR8.GlTextureRenderer.create()

XR8.GlTextureRenderer.create({ GLctx, vertexSource, fragmentSource, toTexture, flipY, mirroredDisplay })

Description​

Creates an object for rendering from a texture to a canvas or another texture.

Parameters​

ParameterTypeDefaultDescription
GLctxWebGlRenderingContext or WebGl2RenderingContextThe WebGlRenderingContext (or WebGl2RenderingContext) to use for rendering. If no toTexture is specified, content will be drawn to this context's canvas.
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]WebGlTextureGLctx's 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.
mirroredDisplay [Optional]BooleanfalseIf true, flip the rendering left-right.

Returns​

Returns an object: {render, destroy, shader}

PropertyDescription
render({ renderTexture, viewport })A function that renders the renderTexture to the specified viewport. Depending on if toTexture is supplied, the viewport is either on the canvas that created GLctx, or it's relative to the render texture provided.
destroyClean up resources associated with this GlTextureRenderer.
shaderGets a handle to the shader being used to draw the texture.

The render function has the following parameters:

ParameterDescription
renderTextureA WebGlTexture (source) to draw.
viewportThe region of the canvas or output texture to draw to; this can be constructed manually, or using XR8.GlTextureRenderer.fillTextureViewport().

The viewport is specified by { width, height, offsetX, offsetY } :

PropertyTypeDescription
widthNumberThe width (in pixels) to draw.
heightNumberThe height (in pixels) to draw.
offsetX [Optional]NumberThe minimum x-coordinate (in pixels) to draw to.
offsetY [Optional]NumberThe minimum y-coordinate (in pixels) to draw to.