TextureMergerRenderer
The TextureMergerRenderer class composes multiple input textures into a single merged texture output. It creates its own render buffer and uses the TextureMergerShader to combine textures per-channel.
Constructor
Section titled “Constructor”constructor(renderer: Renderer)Creates the internal TextureMergerShader (singleton via GetUnique()), a merged output texture, and attaches it to a render buffer.
Properties
Section titled “Properties”renderer
Section titled “renderer”The owning Renderer instance.
dirty : boolean
Section titled “dirty : boolean”Indicates whether the merged texture needs regeneration. Set to true automatically whenever a channel texture is modified via setTexture().
mergedTexture : Texture
Section titled “mergedTexture : Texture”The output texture containing the merged result. Uses COLOR_ATTACHMENT_0 with UNSIGNED_BYTE format and REPEAT wrap mode.
isComplete : boolean
Section titled “isComplete : boolean”Forwarded from the shader’s isComplete flag. Indicates if all required textures are loaded and valid.
Methods
Section titled “Methods”setTexture(tex: Texture, channel: TextureChannel, dstChannel?: TextureChannel)
Section titled “setTexture(tex: Texture, channel: TextureChannel, dstChannel?: TextureChannel)”Sets the source texture for a specific input channel and specifies which destination channel the data should map to.
// Set R channel from a grayscale texture, outputting to channel Arenderer.setTexture(grayTex, TextureChannel.R, TextureChannel.A);
// Set G channel from another texture, outputting to channel Rrenderer.setTexture(colorTex, TextureChannel.G, TextureChannel.R);
// Set all four channels to create ARGB outputmerger.setTexture(rTex, TextureChannel.R); // defaults to dst Rmerger.setTexture(gTex, TextureChannel.G); // defaults to dst Gmerger.setTexture(BTex, TextureChannel.B); // defaults to dst Bmerger.setTexture(aTex, TextureChannel.A, TextureChannel.A); // explicit alpha mappingIf tex is null, throws an error. Automatically marks the merger as dirty.
update()
Section titled “update()”Regenerates the merged texture if dirty. Internally calls renderer.presentTexture() twice (a workaround as noted in the source code):
merger.update(); // Only renders if dirty is trueThe implementation:
- Calls
update()on the internal render buffer with a draw callback - Calls
presentTexturetwice — once with clears and once without (debug note about why this is needed) - Resets dirty flag on completion
Internal RenderBuffer Usage
Section titled “Internal RenderBuffer Usage”A render buffer is automatically created and attached to mergedTexture. The merger reuses this buffer for each update cycle, which is why two passes are needed.
Typical Usage Pattern
Section titled “Typical Usage Pattern”const merger = new TextureMergerRenderer(renderer);
merger.setTexture(alphaTexture, TextureChannel.R, TextureChannel.A);merger.update(); // Generates merged result
// Access the outputconst resultTex = merger.mergedTexture;