Static ReadonlyInvalidInvalid 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 format of the texture
the handle of the texture
attach the ColorBuffer to the FrameBufferObject
attach the ColorBuffer to the FrameBufferObject
attach the ColorBuffer to the FrameBufferObject
attach the DepthBuffer to the FrameBufferObject
attach the depthStencilBuffer to the FrameBufferObject
attach the StencilBuffer to the FrameBufferObject
Clears all cached resources including render pipelines, bind groups, and render bundles. This method should be called when resources need to be recreated or when the rendering context changes.
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
copy Texture Data
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 WebGLResourceHandle for the generated Cube Texture
create a FrameBufferObject
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
Height of each texture layer in pixels
Internal format of the texture
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.
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 buffers 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
Whether to generate mipmaps automatically
Internal format of the texture
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
Whether to generate mipmaps automatically
Height of the texture in pixels
Internal format of the texture
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
Magnification filter mode
Minification filter 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 2D texture view from a texture resource. This view can be used for sampling the texture in shaders.
Handle to the source texture
Handle to the created texture view
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 cube texture view from a cube texture resource. This view exposes all 6 faces of the cube texture for sampling.
Handle to the source cube texture
Handle to the created cube 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
delete a FrameBufferObject
delete a RenderBuffer
Deletes a texture resource and frees associated GPU memory.
Handle to the texture to delete
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
Submits all recorded commands to the GPU queue and resets the command encoder. This method must be called to execute any recorded rendering commands.
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
Gets the current canvas size as a tuple of width and height.
A tuple containing [width, height] of the canvas
Reads pixel data from a specific face of a cube texture. Uses a shader-based approach to sample the cubemap and render to a 2D texture, then copies the result to a buffer for CPU access.
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)
Optional_diffuseCubeMap: RenderTargetTextureCube | CubeTextureOptional_specularCubeMap: RenderTargetTextureCube | CubeTextureOptional_sheenCubeMap: RenderTargetTextureCube | CubeTextureReads pixel data directly from a 2D texture (synchronous version). Note: WebGPU does not support synchronous texture readback. This method throws an error - use getPixelDataFromTextureAsync instead.
Reads pixel data directly from a 2D texture asynchronously. This method uses a render-based approach to avoid requiring COPY_SRC usage on the source texture. It renders the texture to a temporary render target with COPY_SRC, then reads from that.
Handle to the texture to read 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 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
Promise that resolves to the pixel data as Uint8Array
Checks if the implementation supports multi-view VR rendering.
Always false for WebGPU implementation (not yet supported)
Load an image to a specific mip level of a texture
the mip level to load the image to
Recreates the system depth texture with the current canvas dimensions. This is called when the canvas is resized or initialized.
Resizes the canvas and recreates the system depth texture. This method should be called when the window or viewport size changes.
New canvas width in pixels
New canvas height in pixels
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
Array of vertex buffer handles
The primitive containing vertex attribute information
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
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
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
StaticinitReturns the singleton instance of WebGpuResourceRepository. Creates a new instance if one doesn't exist.
The 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