import { MockRenderDevice, RenderDeviceError } from "./RenderDevice.js";
import { WebGL2Device } from "./WebGL2Device.js";
import { WebGPUDevice } from "./WebGPUDevice.js";
export async function createRenderDevice(options = {}) {
    const backend = options.backend ?? "webgl2";
    if (backend === "mock") {
        return new MockRenderDevice();
    }
    if (backend === "webgl2") {
        if (!options.canvas) {
            throw new RenderDeviceError("WebGL2 backend requires a canvas", "MISSING_CANVAS");
        }
        const webglOptions = { canvas: options.canvas };
        if (options.antialias !== undefined) {
            Object.assign(webglOptions, { antialias: options.antialias });
        }
        if (options.alpha !== undefined) {
            Object.assign(webglOptions, { alpha: options.alpha });
        }
        if (options.preserveDrawingBuffer !== undefined) {
            Object.assign(webglOptions, { preserveDrawingBuffer: options.preserveDrawingBuffer });
        }
        if (options.errorCheckMode !== undefined) {
            Object.assign(webglOptions, { errorCheckMode: options.errorCheckMode });
        }
        return WebGL2Device.create(webglOptions);
    }
    if (backend === "webgpu") {
        return WebGPUDevice.create({ gpu: options.webgpu, canvas: options.canvas });
    }
    throw new RenderDeviceError("Unknown render backend", "UNKNOWN_BACKEND", { backend });
}
//# sourceMappingURL=RenderBackend.js.map