Static ReadonlyInvalidInvalid resource handle constant used to indicate failed resource creation or invalid resources
Gets the current WebGL context wrapper.
The current WebGLContextWrapper instance or undefined if none is set
Adds an existing WebGL2 context to the repository.
The configuration for the WebGL context
The WebGL2 rendering context to add
The HTML canvas element associated with the context
Whether to set this context as the current active context
Allocates texture storage without uploading any image data. This method creates an empty texture with the specified format and dimensions.
Configuration object for texture allocation
Internal format of the texture
Height of the texture
Number of mipmap levels to allocate
Width of the texture
The handle of the allocated texture
Attaches a specific face of a cube texture to a framebuffer object. This method is used for rendering to individual faces of cube maps.
The framebuffer to attach to
The color attachment index (0-based)
The cube face index (0-5: +X, -X, +Y, -Y, +Z, -Z)
The mip level to attach
The cube texture to attach
Attaches a specific layer of a texture array to a framebuffer object. This method is useful for rendering to individual layers of a texture array.
The framebuffer to attach to
The color attachment index (0-based)
The texture array to attach
The layer index within the texture array
The mip level to attach
Attaches a color buffer (texture or renderbuffer) to a framebuffer object. This method supports both regular textures and multiview VR textures.
The framebuffer to attach to
The color attachment index (0-based)
The texture or renderbuffer to attach
Attaches a depth buffer to a framebuffer object.
The framebuffer to attach to
The depth texture or renderbuffer to attach
Attaches a combined depth-stencil buffer to a framebuffer object.
The framebuffer to attach to
The depth-stencil texture or renderbuffer to attach
Attaches a stencil buffer to a framebuffer object.
The framebuffer to attach to
The stencil texture or renderbuffer to attach
Binds textures and samplers based on the composition type information. This method handles different texture types including 2D, cube, and texture arrays.
The shader semantics info containing composition type details
Array containing texture slot, texture object, and sampler
Binds a 2D texture to the specified texture slot.
The texture slot index to bind to
The handle of the texture to bind
Binds a 2D texture array to the specified texture slot.
The texture slot index to bind to
The handle of the 2D texture array to bind
Binds a cube texture to the specified texture slot.
The texture slot index to bind to
The handle of the cube texture to bind
Binds a texture sampler to the specified texture slot.
The texture slot index to bind to
The handle of the sampler to bind, or -1 to unbind
Clears the framebuffer associated with the given render pass. This operation clears color, depth, and/or stencil buffers as configured in the render pass.
The render pass containing clear configuration
Creates a compressed texture from pre-transcoded texture data for multiple mip levels. This method handles various compressed texture formats and uploads the data to GPU.
Array of texture data for each mipmap level
The compression format type (e.g., DXT, ETC, ASTC)
Promise that resolves to the handle of the created compressed texture
Creates a compressed texture from a Basis Universal file. This method automatically detects the best compression format supported by the hardware and transcodes the Basis file accordingly.
The Basis Universal file containing the compressed texture data
Configuration object for texture creation
Border width (must be 0 in WebGL)
The handle of the created compressed texture
create a CubeTexture
resource handle
Create Cube Texture from image files.
the WebGLResourceHandle for the generated Cube Texture
Creates a new framebuffer object for off-screen rendering. Framebuffers are used for render-to-texture operations and post-processing effects.
The handle of the created framebuffer object
Creates an index buffer from the provided accessor data.
The accessor containing index data
The handle of the created index buffer
Creates or returns an existing texture sampler with clamp-to-edge wrapping and linear filtering. This method implements a singleton pattern for commonly used sampler configurations.
The handle of the clamp-to-edge linear sampler
Creates or returns an existing texture sampler with clamp-to-edge wrapping and nearest filtering. This method implements a singleton pattern for commonly used sampler configurations.
The handle of the clamp-to-edge nearest sampler
Creates or returns an existing texture sampler with repeat wrapping, anisotropic filtering, and linear filtering. This method implements a singleton pattern for commonly used sampler configurations.
The handle of the repeat anisotropy linear sampler
Creates or returns an existing texture sampler with repeat wrapping and linear filtering. This method implements a singleton pattern for commonly used sampler configurations.
The handle of the repeat linear sampler
Creates or returns an existing texture sampler with repeat wrapping and nearest filtering. This method implements a singleton pattern for commonly used sampler configurations.
The handle of the repeat nearest sampler
Creates or returns an existing texture sampler with repeat wrapping and trilinear filtering. This method implements a singleton pattern for commonly used sampler configurations.
The handle of the repeat trilinear sampler
Creates or returns an existing texture sampler configured for shadow mapping. This sampler uses nearest filtering and enables shadow comparison functionality.
The handle of the shadow sampler
create Renderbuffer
create a RenderTargetTexture
create a RenderTargetTextureArray
create a RenderTargetTextureCube
Creates and compiles a shader program from vertex and fragment shader source code. This method handles shader compilation, linking, and error reporting.
Configuration object for shader program creation
Array of vertex attribute names
Array of vertex attribute semantics
Configuration for the shader program
The engine instance
The fragment shader source code
The material associated with this shader program
OptionalonError?: (message: string) => voidOptional error callback function
The primitive that will use this shader program
The vertex shader source code
The handle of the created shader program, or InvalidCGAPIResourceUid on failure
Creates a 2D texture with immutable storage using texStorage2D. This method allocates texture storage with the specified parameters.
Configuration object for texture creation
Height of the texture
Internal format of the texture
Number of mipmap levels to allocate
Width of the texture
The handle of the created texture
Creates a 2D texture array with specified dimensions and format. Texture arrays allow storing multiple texture layers in a single texture object.
Width of each texture layer
Height of each texture layer
Number of texture layers in the array
Number of mipmap levels
Internal format of the texture
Pixel format of the source data
Data type of the source data
Typed array containing the texture data
The handle of the created texture array
Creates a texture from a data URI string. This method decodes base64-encoded image data and creates a GPU texture.
The data URI string containing encoded image data
Texture creation parameters
Pixel data format
Whether to automatically generate mipmaps
Internal texture format for GPU storage
Component data type
Promise resolving to the texture resource handle
Creates a 2D texture from an HTML image element with specified parameters. This method allocates texture storage and uploads the image data to the GPU.
The HTML image element containing the image data
Configuration object for texture creation
Pixel format of the source data
Whether to generate mipmaps automatically
Height of the texture
Internal format of the texture
Data type of the source data
Width of the texture
Promise that resolves to the handle of the created texture
Creates a 2D texture from ImageBitmap data with specified parameters. This method allocates texture storage and uploads the image data to the GPU.
The ImageBitmap or ImageBitmapSource data to upload
Configuration object for texture creation
Pixel format of the source data
Whether to generate mipmaps automatically
Height of the texture
Internal format of the texture
Data type of the source data
Width of the texture
Promise that resolves to the handle of the created texture
Creates a 2D texture from a typed array with specified parameters. This method is useful for creating textures from raw pixel data.
The typed array containing the pixel data
Configuration object for texture creation
Pixel format of the source data
Whether to generate mipmaps automatically
Height of the texture
Internal format of the texture
Data type of the source data
Width of the texture
The handle of the created texture
Creates a new texture sampler with the specified filtering and wrapping parameters.
Configuration object for sampler creation
Whether to enable anisotropic filtering
Magnification filter mode
Minification filter mode
Whether to enable shadow comparison mode
Wrapping mode for R coordinate
Wrapping mode for S coordinate
Wrapping mode for T coordinate
The handle of the created sampler
Creates a vertex buffer from the provided accessor data.
The accessor containing vertex data
The handle of the created vertex buffer
Creates vertex buffers and index buffers for a primitive and returns handles for them. This method processes all vertex attributes of the primitive and creates corresponding VBOs.
The primitive object containing vertex and index data
VertexHandles object containing all created buffer handles and metadata
Creates a vertex buffer directly from a typed array.
The typed array containing vertex data
The handle of the created vertex buffer
Deletes a framebuffer object and frees associated resources.
Handle to the framebuffer to delete
Deletes a renderbuffer resource and frees associated GPU memory.
Handle to the renderbuffer to delete
Deletes a texture resource and frees associated GPU memory.
Handle to the texture to delete
Deletes a specific vertex buffer resource.
Deletes all vertex-related resources (vertex buffers, index buffers, VAOs). This method ensures proper cleanup of all resources associated with vertex data.
Object containing handles to all vertex-related resources to delete
Generates mipmaps for a 2D texture. Mipmaps improve rendering quality and performance by providing pre-filtered texture versions.
Handle to the texture
Base texture width in pixels
Base texture height in pixels
Generates mipmaps for a cube texture. This creates mipmaps for all six faces of the cube texture.
Handle to the cube texture
Generates a new WebGL2 context for the given canvas element.
The configuration for the WebGL context
The HTML canvas element to create the context for
Whether to set this context as the current active context
OptionalwebglOption: WebGLContextAttributesOptional WebGL context attributes for context creation
The created WebGL2 rendering context
Retrieves the current canvas dimensions.
A tuple containing [width, height] of the canvas
Reads pixel data from a specific face of a cube texture. This creates a temporary framebuffer, attaches the cube face, and reads the pixels. For floating-point textures (HDR), it uses a shader-based approach to sample and convert.
Handle to the cube texture
Width of the face texture
Height of the face texture
Index of the cube face (0=+X, 1=-X, 2=+Y, 3=-Y, 4=+Z, 5=-Z)
Promise resolving to the pixel data as a Uint8Array (RGBA format)
Reads pixel data directly from a 2D texture without requiring a framebuffer. Creates a temporary framebuffer internally to read the texture data. This is useful for reading texture data from textures that are not attached to a framebuffer.
X offset to start reading from
Y offset to start reading from
Width of the region to read
Height of the region to read
The pixel data as a Uint8Array in RGBA format
Reads pixel data directly from a 2D texture asynchronously. This is the async version of getPixelDataFromTexture for API consistency with WebGPU.
Handle to the texture to read from
X offset to start reading from
Y offset to start reading from
Width of the region to read
Height of the region to read
Promise resolving to the pixel data as a Uint8Array in RGBA format
Reads pixel data from a texture attached to a framebuffer. This allows CPU access to rendered texture data for analysis or processing.
Width of the region to read
Height of the region to read
Handle to the framebuffer containing the texture
Index of the color attachment to read from
Promise resolving to the pixel data as a Uint8Array
Retrieves a WebGL resource by its handle.
The handle of the resource to retrieve
The WebGL resource or null if not found
Checks if the current graphics API supports multi-view VR rendering. Multi-view rendering allows efficient stereo rendering for VR applications.
True if multi-view VR rendering is supported, false otherwise
Loads image data to a specific mip level of an existing 2D texture. This method supports uploading data with row padding, extracting only the relevant pixels.
Configuration object for image loading
The typed array containing the image data
The format of the image
Height of the image to copy
The mip level to load the image to
Size of each row in pixels (including padding)
The handle of the target texture
The data type of the image
Width of the image to copy
X offset of the copy region
Y offset of the copy region
Resizes the canvas to the specified dimensions. This operation may trigger viewport adjustments and resource reallocation.
The new canvas width in pixels
The new canvas height in pixels
Sets a uniform value for texture binding and binds the texture to the appropriate slot.
The shader program to set the uniform for
The semantic string identifying the uniform
The value array containing texture slot index and texture data
Sets a uniform value in the shader program with automatic type detection and conversion. This method handles various composition types including matrices, vectors, and textures.
The shader program to set the uniform for
The semantic string identifying the uniform
The value to set (can be scalar, vector, matrix, or texture data)
True if the uniform was successfully set, false otherwise
Internal method for setting uniform values with proper WebGL calls based on data type. This method handles the actual WebGL uniform* calls with appropriate type conversion.
The shader program to set the uniform for
The semantic string identifying the uniform
The shader semantics information
Whether the value is a matrix
Number of components in the value
Whether the value is a vector/array
Object containing the value components
Optionalw?: number | booleanFourth value component (optional)
Primary value component
Optionaly?: number | booleanSecond value component (optional)
Optionalz?: number | booleanThird value component (optional)
True if the uniform was successfully set, false if location not found
Sets up basic uniform locations required for data texture operations.
The handle of the shader program to configure
OptionaltypedArray: TypedArraySets up uniform locations for a shader program based on shader semantics information. This method extracts uniform locations from the compiled shader program and stores them for efficient access during rendering.
Configuration for the shader program
The handle of the shader program
Array of shader semantics information
Whether to set up only uniform locations
The WebGL program object with configured uniform locations
Configures vertex data for rendering by setting up VAO with VBOs and IBO. This method binds vertex arrays, index buffers, and configures vertex attribute pointers.
Object containing VAO, IBO, and VBO handles
OptionaliboHandle?: numberHandle to the index buffer object (optional)
Handle to the vertex array object
Array of vertex buffer object handles
The primitive object containing vertex attribute information
Handle to instance ID buffer for instanced rendering (optional)
unbind Framebuffer
Updates an existing index buffer with new data from the accessor.
The accessor containing new index data
The handle of the index buffer to update
Updates an existing vertex buffer with new data from the accessor.
The accessor containing new vertex data
The handle of the vertex buffer to update
Updates existing vertex buffers and index buffers with new data from a primitive.
The primitive object containing updated vertex and index data
The handles of the buffers to update
StaticgetGets the appropriate Computer Graphics API Resource Repository instance based on the current process approach. Automatically selects between WebGL and WebGPU implementations.
The active ICGAPIResourceRepository implementation
StaticgetGets the WebGL-specific resource repository instance. Use this method when you specifically need WebGL functionality.
The WebGLResourceRepository singleton instance
StaticgetGets the WebGPU-specific resource repository instance. Use this method when you specifically need WebGPU functionality.
The WebGpuResourceRepository singleton instance
StaticinitGets the singleton instance of WebGLResourceRepository.
The singleton instance of WebGLResourceRepository
A comprehensive repository for managing WebGL resources including buffers, textures, shaders, and framebuffers. This class provides a centralized interface for creating, managing, and disposing of WebGL resources while maintaining resource handles for efficient memory management.
Example