Static
Readonly
InvalidCGAPIResourceInvalid 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 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
bind Framebuffer
Optional
framebuffer: FrameBufferBinds 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
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)
Pixel format (not used for compressed textures)
Data type (not used for compressed textures)
The handle of the created compressed texture
create a CubeTexture
resource handle
Create Cube Texture from image files.
the base uri to load images;
the number of mip levels (include root level). if no mipmap, the value should be 1;
the WebGLResourceHandle for the generated Cube Texture
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 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
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
The fragment shader source code
The material associated with this shader program
Optional
onOptional 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
Border width (typically 0)
Pixel data format
Whether to automatically generate mipmaps
Internal texture format for GPU storage
Mipmap level (typically 0 for base level)
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
Border width (must be 0 in WebGL)
Pixel format of the source data
Whether to generate mipmaps automatically
Height of the texture
Internal format of the texture
Mipmap level (usually 0 for base level)
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
Border width (must be 0 in WebGL)
Pixel format of the source data
Whether to generate mipmaps automatically
Height of the texture
Internal format of the texture
Mipmap level (usually 0 for base level)
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
Border width (must be 0 in WebGL)
Pixel format of the source data
Whether to generate mipmaps automatically
Height of the texture
Internal format of the texture
Mipmap level (usually 0 for base level)
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
Optional
isWhether alpha is premultiplied (optional)
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 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
Base texture width in pixels
Base texture height in pixels
Generates a new WebGL2 context for the given canvas element.
The HTML canvas element to create the context for
Whether to set this context as the current active context
Optional
webglOption: WebGLContextAttributesOptional WebGL context attributes for context creation
The created WebGL2 rendering context
Reads pixel data from a texture attached to a framebuffer. This allows CPU access to rendered texture data for analysis or processing.
Handle to the texture to read from
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
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
set drawTargets
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
Whether this is the first time setting this 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
Optional
w?: number | booleanFourth value component (optional)
Primary value component
Optional
y?: number | booleanSecond value component (optional)
Optional
z?: number | booleanThird value component (optional)
True if the uniform was successfully set, false if location not found
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
Optional
iboHandle 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)
Sets the viewport for rendering operations. The viewport defines the area of the framebuffer that will be rendered to.
Optional
viewport: Vector4Optional viewport rectangle as [x, y, width, height]. If not provided, uses full framebuffer
Optional
typedArray: 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.
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
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
Static
getGets 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
Static
getGets the singleton instance of WebGLResourceRepository.
The singleton instance of WebGLResourceRepository
Static
getGets the WebGL-specific resource repository instance. Use this method when you specifically need WebGL functionality.
The WebGLResourceRepository singleton instance
Static
getGets the WebGPU-specific resource repository instance. Use this method when you specifically need WebGPU functionality.
The WebGpuResourceRepository singleton instance
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