Static
Readonly
InvalidCGAPIResourceInvalid resource handle constant used to indicate failed resource creation or invalid resources
Adds a WebGPU device wrapper to the repository and initializes the command encoder. This must be called before using any WebGPU functionality.
The WebGPU device wrapper containing the device and context
allocate a Texture
the handle of the texture
attach the ColorBuffer to the FrameBufferObject
a Framebuffer
a attachment index
a face index
a mip level
a ColorBuffer
attach the ColorBuffer to the FrameBufferObject
a Framebuffer
a attachment index
a ColorBuffer
a layer index
a mip level
attach the ColorBuffer to the FrameBufferObject
a Framebuffer
a attachment index
a ColorBuffer
attach the DepthBuffer to the FrameBufferObject
a Framebuffer
a DepthBuffer
attach the depthStencilBuffer to the FrameBufferObject
a Framebuffer
a depthStencilBuffer
attach the StencilBuffer to the FrameBufferObject
a Framebuffer
a StencilBuffer
Clears the framebuffer with the specified clear values. This method is executed when the render pass has no entities to render, but still needs to perform clear operations.
The render pass containing clear settings and target framebuffer
Create and bind compressed texture object
transcoded texture data for each mipmaps(levels)
create CompressedTextureFromBasis
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 a WebGPU index buffer from an accessor containing index data. Automatically converts UnsignedByte indices to UnsignedShort since WebGPU doesn't support 8-bit index buffers.
Accessor containing the index data to upload
Handle to the created index buffer resource
Creates a render buffer for multisampling (MSAA) or as a render attachment. Render buffers are textures that are only used for rendering and cannot be sampled in shaders.
Width of the render buffer in pixels
Height of the render buffer in pixels
Internal format of the render buffer
Whether to enable multisampling
Number of samples for MSAA (ignored if isMSAA is false)
Handle to the created render buffer resource
Creates a render target texture that can be used as a color attachment in framebuffers. This texture can be rendered to and also used as a texture input in shaders.
Configuration for the render target texture
Texture format for the render target
Height of the texture in pixels
Number of mipmap levels to create
Width of the texture in pixels
Handle to the created render target texture resource
Creates a render target texture array that can hold multiple 2D textures. Useful for techniques like shadow mapping with multiple lights or layered rendering.
Configuration for the render target texture array
Number of texture layers in the array
Pixel format of the data
Height of each texture layer in pixels
Internal format of the texture
Mipmap level (typically 0)
Component type of the data
Width of each texture layer in pixels
Handle to the created render target texture array resource
Creates a render target cube texture for environment mapping or omnidirectional shadow mapping. This creates a cube texture with 6 faces that can be rendered to.
Configuration for the render target cube texture
Texture format for the render target
Height of each cube face in pixels
Number of mipmap levels to create
Width of each cube face in pixels
Handle to the created render target cube texture resource
Creates shader modules (vertex and fragment) from shader source code. This method compiles both vertex and fragment shaders and returns their handles.
Configuration object for shader creation
Names of vertex attributes
Semantic meanings of vertex attributes
WGSL fragment shader source code
The material that will use these shaders
Optional
onOptional error callback function
The primitive that will be rendered with these shaders
WGSL vertex shader source code
Handle to the shader program containing both modules
Creates a storage buffer from a Float32Array and registers it as a WebGPU resource. Storage buffers are used for storing large amounts of data accessible from shaders.
The Float32Array containing the data to store
Handle to the created storage buffer resource
create a TextureArray
texture handle
Creates a WebGPU texture from a data URI string. This method loads the image from the data URI and creates a texture from it.
The data URI string containing the image data
Configuration object containing texture parameters
Border width (must be 0 for WebGPU)
Pixel format of the source data
Whether to generate mipmaps automatically
Internal format of the texture
Mipmap level (typically 0 for base level)
Component type of the source data
Promise that resolves to the texture resource handle
create a Texture
Creates a WebGPU texture from ImageBitmap data with specified parameters. This method handles texture creation, data upload, and optional mipmap generation.
The ImageBitmap data to create the texture from
Configuration object containing texture parameters
Border width (must be 0 for WebGPU)
Pixel format of the source data
Whether to generate mipmaps automatically
Height of the texture in pixels
Internal format of the texture
Mipmap level (typically 0 for base level)
Component type of the source data
Width of the texture in pixels
Promise that resolves to the texture resource handle
Creates a texture sampler with the specified filtering and wrapping parameters. The sampler defines how textures are filtered and wrapped when accessed in shaders.
Configuration object for the sampler
Whether to enable anisotropic filtering
Optional
isWhether the texture has premultiplied alpha (optional)
Magnification filter mode
Minification filter mode
Whether to enable shadow comparison mode
Wrapping mode for R (W) texture coordinate
Wrapping mode for S (U) texture coordinate
Wrapping mode for T (V) texture coordinate
Handle to the created sampler resource
Creates a texture view suitable for use as a render target. This view targets only the base mip level and first array layer.
Handle to the source texture
Handle to the created render target texture view
Creates a WebGPU vertex buffer from an accessor containing vertex data. The buffer is created with the appropriate size and the data is uploaded immediately.
Accessor containing the vertex data to upload
Handle to the created vertex buffer
Creates vertex and index buffers for a primitive and returns their handles. This method processes all vertex attributes and creates appropriate buffers while tracking which attributes are present.
The primitive containing vertex and index data
Object containing buffer handles and attribute flags
Creates a WebGPU vertex buffer from a typed array. This is a more direct method when you have raw typed array data.
The typed array containing vertex data
Handle to the created vertex buffer resource
Deletes all vertex data resources (vertex and index buffers) associated with vertex handles. This method destroys both vertex buffers and index buffers to free GPU memory.
Object containing handles to the vertex data resources to delete
Executes a draw call for rendering a primitive with the specified material and render pass. This is the core rendering method that sets up the render pipeline, bind groups, and executes the actual GPU draw commands.
The geometric primitive to render (vertices, indices, attributes)
The material containing shaders and rendering properties
The render pass defining render targets and clear operations
Identifier for the camera used for rendering
Whether to enable depth writing during rendering
Generates mipmaps for a texture using render passes (including CubeMap support). This is an optimized method adapted from WebGPU best practices that uses a custom shader to generate each mipmap level from the previous one.
The GPU texture to generate mipmaps for
Descriptor containing texture format and dimensions
Adapted from: https://toji.dev/webgpu-best-practices/img-textures#generating-mipmaps
Generates mipmaps for a 2D texture using the specified dimensions. This method creates all mipmap levels from the base texture.
Handle to the texture resource
Width of the base texture level
Height of the base texture level
Generates mipmaps for a cube texture using the specified dimensions. This method creates all mipmap levels for all 6 faces of the cube texture.
Handle to the cube texture resource
Width of the base texture level
Height of the base texture level
Optional
diffuseCubeMap: RenderTargetTextureCube | CubeTextureOptional
specularCubeMap: RenderTargetTextureCube | CubeTextureOptional
sheenCubeMap: RenderTargetTextureCube | CubeTextureReads pixel data from a texture and returns it as a Uint8Array. This method is useful for debugging or post-processing texture data.
Handle to the texture resource
Width of the texture region to read
Height of the texture region to read
Handle to the framebuffer (if applicable)
Index of the color attachment to read from
Promise that resolves to the pixel data as Uint8Array
Returns the WebGPU device wrapper instance.
The WebGPU device wrapper
Load an image to a specific mip level of a texture
Configures vertex data layout for the rendering pipeline. This method sets up vertex buffer layouts including both per-vertex and per-instance data.
Object containing vertex array object, index buffer, and vertex buffer handles
Optional
iboHandle to the index buffer (optional)
Handle to the vertex array object
Array of vertex buffer handles
The primitive containing vertex attribute information
Handle to the instance ID buffer for instanced rendering
Sets the viewport for rendering (currently not implemented in WebGPU version).
Optional
viewport: Vector4Optional viewport rectangle (x, y, width, height)
Updates the data in an existing index buffer with new data from an accessor. Automatically handles conversion of UnsignedByte indices to UnsignedShort if needed.
Accessor containing the new index data
Handle to the existing index buffer to update
Updates an existing storage buffer with new data. Only updates the specified number of components to optimize data transfer.
Handle to the storage buffer to update
New data to write to the buffer
Number of components to update
Updates a portion of a storage buffer with new data at a specific offset. This allows for efficient partial updates of large storage buffers.
Handle to the storage buffer to update
New data to write to the buffer
Byte offset in the storage buffer where to start writing
Element offset in the input array where to start reading
Number of components to update
Updates the data in an existing vertex buffer with new data from an accessor. This method maps the buffer for writing and uploads the new data.
Accessor containing the new vertex data
Handle to the existing vertex buffer to update
Updates the vertex and index buffers for a primitive with new data. This method updates all existing buffers with fresh data from the primitive.
The primitive containing the updated vertex and index data
Object containing the handles to 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
getReturns the singleton instance of WebGpuResourceRepository. Creates a new instance if one doesn't exist.
The singleton instance
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
WebGPU Resource Repository that manages WebGPU resources and provides rendering functionality. This class serves as a central hub for creating, managing, and utilizing WebGPU resources such as textures, buffers, pipelines, and render passes.
Implements
ICGAPIResourceRepository