import {} from "../rendering/index.js";
export class ShaderDiagnostics {
    inspectSources(sources, compileLog = null) {
        return {
            label: sources.label,
            marker: sources.marker,
            markerPresentInVertex: sources.vertex.includes(sources.marker),
            markerPresentInFragment: sources.fragment.includes(sources.marker),
            attributes: extractNames(/\b(?:in|attribute)\s+\w+\s+(\w+)\s*;/g, `${sources.vertex}\n${sources.fragment}`),
            uniforms: extractNames(/\buniform\s+\w+\s+(\w+)(?:\s*\[[^\]]+\])?\s*;/g, `${sources.vertex}\n${sources.fragment}`),
            compileLog
        };
    }
    inspectProgram(program, compileLog = null) {
        return {
            label: program.label,
            marker: program.marker,
            markerPresentInVertex: true,
            markerPresentInFragment: true,
            attributes: [...program.reflection.attributes.keys()],
            uniforms: [...program.reflection.uniforms],
            compileLog
        };
    }
    assertMarker(report) {
        if (!report.markerPresentInVertex || !report.markerPresentInFragment) {
            throw new ShaderDiagnosticError("Shader marker mismatch", report);
        }
    }
}
export class ShaderDiagnosticError extends Error {
    report;
    constructor(message, report) {
        super(message);
        this.report = report;
        this.name = "ShaderDiagnosticError";
    }
}
function extractNames(pattern, source) {
    const names = new Set();
    let match;
    while ((match = pattern.exec(source)) !== null) {
        if (match[1]) {
            names.add(match[1]);
        }
    }
    return [...names];
}
//# sourceMappingURL=ShaderDiagnostics.js.map