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

    Constructors

    • Parameters

      • renderer: WebGLRenderer

        the current WebGL renderer session

      • settings: {
            attributes: {
                name: string;
                normalized: boolean;
                offset: number;
                size: number;
                type: number;
            }[];
            indexed?: boolean;
            maxVertices?: number;
            projectionUniform?: string;
            shader: { fragment: string; vertex: string };
        }

        additional settings to initialize this batcher

        • attributes: {
              name: string;
              normalized: boolean;
              offset: number;
              size: number;
              type: number;
          }[]

          an array of attributes definition

        • Optionalindexed?: boolean

          whether this batcher uses an index buffer for indexed drawing (drawElements)

        • OptionalmaxVertices?: number

          the maximum number of vertices this batcher can hold

        • OptionalprojectionUniform?: string

          the name of the projection matrix uniform in the shader

        • shader: { fragment: string; vertex: string }

          shader definition

          • fragment: string

            a string containing the GLSL source code to set

          • vertex: string

            a string containing the GLSL source code to set

      Returns QuadBatcher

    Properties

    attributes: Object[] | undefined

    an array of vertex attribute properties

    Batcher.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
    mode: number | undefined

    primitive type to render (gl.POINTS, gl.LINE_STRIP, gl.LINE_LOOP, gl.LINES, gl.TRIANGLE_STRIP, gl.TRIANGLE_FAN, gl.TRIANGLES)

    gl.TRIANGLES
    
    projectionUniform: string | undefined

    the name of the projection matrix uniform in the shader

    renderer: any
    stride: number | undefined

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

    Batcher.addAttribute

    useIndexBuffer: boolean | undefined

    whether this batcher uses indexed drawing

    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)

    Batcher.addAttribute

    viewMatrix: any

    Methods

    • add vertex attribute property definition to the batcher

      Parameters

      • name: string

        name of the attribute in the vertex shader

      • size: number

        number of components per vertex attribute. Must be 1, 2, 3, or 4.

      • type: number

        data type of each component in the array

      • normalized: boolean

        whether integer data values should be normalized into a certain range when being cast to a float

      • offset: number

        offset in bytes of the first component in the vertex attribute array

      Returns void

    • 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

      • reupload: 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

      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

      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

    • unbind the given WebGL texture, forcing it to be reuploaded

      Parameters

      • Optionaltexture: WebGLTexture

        a WebGL texture

      • Optionalunit: number

        Texture unit to unbind from

      Returns number

      unit the unit number that was associated with the given texture