melonJS
    Preparing search index...

    Class QuadBatcher

    A WebGL Compositor object. This class handles all of the WebGL state
    Pushes texture regions or shape geometry into WebGL buffers, automatically flushes to GPU

    Hierarchy (View Summary)

    Index
    _onCacheReset: (() => void) | null | undefined
    attributes: Object[] | undefined

    an array of vertex attribute properties

    WebGLBatcher.addAttribute

    currentSamplerUnit: number | undefined
    currentShader: GLShader | undefined

    the shader currently used by this batcher

    defaultShader: GLShader | undefined

    the default shader created by this batcher

    gl: any
    projectionUniform: string | undefined

    the name of the projection matrix uniform in the shader

    renderer: Renderer | undefined

    the renderer this batcher is bound to

    stride: number | undefined

    the stride of a single vertex in bytes (will automatically be calculated as attributes definitions are added)

    WebGLBatcher.addAttribute

    useIndexBuffer: boolean | undefined

    whether this batcher uses indexed drawing

    validatedShaders: WeakSet<object> | undefined
    vertexData: VertexArrayBuffer | undefined

    the vertex data buffer used by this batcher

    vertexSize: number | undefined

    the size of a single vertex in floats (will automatically be calculated as attributes definitions are added)

    WebGLBatcher.addAttribute

    vertexState: WebGLVertexState | null | undefined
    viewMatrix: Matrix3d | undefined
    • Add a vertex attribute to this batcher's layout.

      Accepts either vocabulary. The backend-neutral form names the component type and count in one token, which is what a non-WebGL backend can consume directly and what lets a layout be written without a live rendering context:

      batcher.addAttribute({ name: "aColor", format: "unorm8x4", offset: 20 });
      batcher.addAttribute("aColor", "unorm8x4", 20);

      The GL form is supported indefinitely and behaves exactly as before:

      batcher.addAttribute("aColor", 4, gl.UNSIGNED_BYTE, true, 20);
      

      Records keep both spellings, so existing readers of size / type / normalized are unaffected. A GL combination with no portable name — three-component 8- and 16-bit types, which the neutral vocabulary does not define — is stored with format: undefined rather than an invented name that a backend could not honour.

      The layout is frozen once init() has built the vertex state, and each record is frozen on insertion: a batcher rebuilds its vertex state from these records after a context loss, so a later mutation would take effect at restore time rather than where it was written.

      Parameters

      • name: string | object

        attribute name, or a descriptor object

      • Optionalsize: number | VertexFormat

        component count (GL form), or the format (neutral form)

      • Optionaltype: number

        component type (GL form), or the byte offset (neutral form)

      • Optionalnormalized: boolean

        whether integers are scaled into [0, 1] / [-1, 1] (GL form only)

      • Optionaloffset: number

        byte offset of the attribute within a vertex (GL form)

      • ...args: any[]

      Returns void

      when the layout is frozen, the format or GL type is unknown, or a descriptor contradicts itself

    • Add index values to the index buffer (only for indexed batchers). Indices are rebased relative to the current vertex count.

      Parameters

      • indices: number[]

        array of index values to add

      Returns void

    • Add a textured quad

      Parameters

      • texture: TextureAtlas

        Source texture atlas

      • x: number

        Destination x-coordinate

      • y: number

        Destination y-coordinate

      • w: number

        Destination width

      • h: number

        Destination height

      • u0: number

        Texture UV (u0) value.

      • v0: number

        Texture UV (v0) value.

      • u1: number

        Texture UV (u1) value.

      • v1: number

        Texture UV (v1) value.

      • tint: number

        tint color to be applied to the texture in UINT32 (argb) format

      • Optionalreupload: boolean = false

        Force the texture to be reuploaded even if already bound

      Returns void

    • assign the given WebGL texture to the current batch

      Parameters

      • texture: WebGLTexture

        a WebGL texture

      • unit: number

        Texture unit to which the given texture is bound

      • flush: boolean = true

      Returns void

    • Draw a screen-aligned quad with the given raw WebGL texture through the given shader. Binds the texture to unit 0, pushes 4 vertices (Y-flipped UVs), flushes, then unbinds the texture.

      Parameters

      • source: WebGLTexture

        the raw GL texture to blit

      • x: number

        destination x

      • y: number

        destination y

      • width: number

        destination width

      • height: number

        destination height

      • shader: any

        the shader effect to apply

      Returns void

    • Create a WebGL texture from an image

      Parameters

      • unit: number

        Destination texture unit

      • Optionalpixels:
            | ImageData
            | HTMLCanvasElement
            | (new (width?: number, height?: number) => HTMLImageElement)
            | Uint8Array<ArrayBufferLike>[]
            | Float32Array<ArrayBufferLike>[] = null

        Source image

      • filter: number

        gl.LINEAR or gl.NEAREST

      • Optionalrepeat: string = "no-repeat"

        Image repeat behavior

      • Optionalw: number = pixels.width

        Source image width

      • Optionalh: number = pixels.height

        Source image height

      • OptionalpremultipliedAlpha: boolean = true

        Multiplies the alpha channel into the other color channels

      • Optionalmipmap: boolean = true

        Whether mipmap levels should be generated

      • texture: any
      • flush: boolean = true

      Returns WebGLTexture

      a WebGL texture

    • returns the WebGL texture associated to the given texture unit

      Parameters

      • unit: number

        Texture unit to which a texture is bound

      Returns WebGLTexture

      texture a WebGL texture

    • called by the WebGL renderer when this batcher is being replaced by another. Attribute state no longer needs disabling — it lives in this batcher's vertex-state object and the incoming batcher's bind() replaces the binding wholesale. Kept as a lifecycle hook: subclasses override it to restore mode-specific GL state (see MeshBatcher's blend/depth restore).

      Returns void

    • Select the shader to use for compositing. Multi-texture batching is automatically enabled when the default shader is active, and disabled for custom ShaderEffect shaders.

      Parameters

      • shader: any

        a reference to a GLShader or ShaderEffect instance

      Returns void

      • GLShader
      • ShaderEffect