A class or interface that provide support for WebGL async read pixel/texture data extraction.

Properties

debug: boolean

Debug flag.

pixelBuffer: Uint8ClampedArray

The reference to the pixel buffer.

#renderer: Renderer

The WebGL2 renderer.

#glSync: WebGLSync

The reference to a WebGL2 sync object.

#format: FORMATS

The texture format on which the Texture Extractor must work.

#type: TYPES

The texture type on which the Texture Extractor must work.

#readFormat: FORMATS

The texture format on which the Texture Extractor should read.

#gpuBuffer: WebGLBuffer

The reference to the GPU buffer.

#createBuffer: boolean

To know if we need to create a GPU buffer.

#callerName: string

The caller name associated with this instance of texture extractor (optional, used for debug)

#generatedRenderTexture: RenderTexture

Generated RenderTexture for textures.

#compressor: TextureCompressor

The compressor worker wrapper

#queue: Semaphore = ...

Handling of the concurrency for the extraction (by default a queue of 1)

COMPRESSION_MODES: {
    NONE: number;
    BASE64: number;
} = ...

List of compression that could be applied with extraction

Type declaration

  • NONE: number
  • BASE64: number

Accessors

  • get #readBufferMul(): number
  • Returns the read buffer width/height multiplier.

    Returns number

Methods

  • Extract a rectangular block of pixels from the texture (without un-pre-multiplying).

    Parameters

    Returns Promise<any>

  • Free all the bound objects.

    Returns void

  • Called by the renderer contextChange runner.

    Returns void

  • Extract a rectangular block of pixels from the texture (without un-pre-multiplying).

    Parameters

    Returns Promise<any>

  • Compress the buffer and returns a base64 image.

    Parameters

    • Rest ...args: any

    Returns Promise<string>

  • Compress the buffer into a worker and returns a base64 image

    Parameters

    • buffer: Uint8ClampedArray

      Buffer to convert into a compressed base64 image.

    • width: number

      Width of the image.

    • height: number

      Height of the image.

    • options: {
          type: string;
          quality: number;
      } = {}
      • type: string

        Format of the image.

      • quality: number

        Quality of the compression.

    Returns Promise<string>

  • Compress the buffer locally (but expand the buffer into a worker) and returns a base64 image. The image format is forced to jpeg.

    Parameters

    • buffer: Uint8ClampedArray

      Buffer to convert into a compressed base64 image.

    • width: number

      Width of the image.

    • height: number

      Height of the image.

    • options: {
          quality: number;
      } = {}
      • quality: number

        Quality of the compression.

    Returns Promise<string>

  • Prepare data for the asynchronous readPixel.

    Parameters

    • frame: Rectangle
    • resolution: number

    Returns object

  • Retrieve the content of the GPU buffer and put it pixels. Returns an object with the pixel buffer and dimensions.

    Parameters

    • buffer: Uint8ClampedArray

      The pixel buffer.

    • width: number

      The width of the texture.

    • height: number

      The height of the texture.

    • bufSize: number

      The size of the buffer.

    Returns object

  • Retrieve a pixel buffer of the given length. A cache is provided for the last length passed only (to avoid too much memory consumption)

    Parameters

    • length: number

      Length of the required buffer.

    Returns Uint8ClampedArray

    The cached or newly created buffer.

  • Wait for the synchronization object to resolve.

    Returns Promise<any>

  • Clear some key properties.

    Parameters

    • options: {
          buffer: boolean;
          syncObject: boolean;
          rt: boolean;
      } = {}
      • buffer: boolean
      • syncObject: boolean
      • rt: boolean

    Returns void

  • Convenience method to display the debug messages with the extractor.

    Parameters

    • message: string

      The debug message to display.

    Returns void

  • Convenience method to display the error messages with the extractor.

    Parameters

    • message: string

      The error message to display.

    Returns void