import { Scene } from "../../scene/index.js";
import { Renderer } from "../../rendering/index.js";
import { A3DScene } from "./A3DScene.js";
export class A3DRenderer {
    renderer;
    constructor(renderer) {
        this.renderer = renderer;
    }
    static async create(options = {}) {
        return new A3DRenderer(await Renderer.create(options));
    }
    get device() {
        return this.renderer.device;
    }
    resize(width, height) {
        this.renderer.resize(width, height);
    }
    resizeToDisplay(options = {}) {
        return this.renderer.resizeToDisplay(options);
    }
    startAnimationLoop(callback) {
        return this.renderer.startAnimationLoop((timeMs) => callback(timeMs, this));
    }
    render(sourceOrInput, camera) {
        if (isRendererInput(sourceOrInput)) {
            return this.renderer.render({
                ...sourceOrInput,
                source: normalizeSource(sourceOrInput.source)
            });
        }
        return this.renderer.render(normalizeSource(sourceOrInput), camera);
    }
    renderAsync(sourceOrInput, camera) {
        if (isRendererInput(sourceOrInput)) {
            return this.renderer.renderAsync({
                ...sourceOrInput,
                source: normalizeSource(sourceOrInput.source)
            });
        }
        return this.renderer.renderAsync(normalizeSource(sourceOrInput), camera);
    }
    renderFrame(input) {
        const diagnostics = this.render({ source: input.source, camera: input.camera });
        return {
            backend: this.device.kind === "webgpu" ? "webgpu" : "webgl2",
            diagnostics,
            features: createPublicFrameFeatures(diagnostics, input)
        };
    }
    captureFrame(source, camera) {
        return this.renderer.captureFrame(source ? normalizeSource(source) : undefined, camera);
    }
    getDiagnostics() {
        return this.renderer.getDiagnostics();
    }
    dispose() {
        this.renderer.dispose();
    }
}
function normalizeSource(source) {
    return source instanceof A3DScene ? source.toRenderSource() : source;
}
function isRendererInput(value) {
    return typeof value === "object" && value !== null && "source" in value;
}
function createPublicFrameFeatures(diagnostics, input) {
    return [
        {
            id: "public-a3d-renderer-frame",
            state: "supported",
            detail: "Frame rendered through @aura3d/engine/advanced-runtime A3DRenderer."
        },
        {
            id: "render-source",
            state: input.metadata.primitiveCount > 0 ? "supported" : "partial",
            detail: `${input.metadata.assetId}: ${input.metadata.primitiveCount} primitives`
        },
        {
            id: "draw-call-diagnostics",
            state: diagnostics.drawCalls > 0 ? "supported" : "partial",
            detail: `${diagnostics.drawCalls} draw calls`
        }
    ];
}
//# sourceMappingURL=A3DRenderer.js.map