/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module WebGL
 */
import { dispose } from "@itwin/core-bentley";
import { System } from "./System";
import { addClipping } from "./glsl/Clipping";
function createClippingBuilder(src) {
    const builder = src.clone();
    builder.vert.headerComment += "-Clip";
    builder.frag.headerComment += "-Clip";
    addClipping(builder);
    return builder;
}
/** @internal */
export class ClippingProgram {
    compile() {
        return undefined === this._program || 0 /* CompileStatus.Success */ === this._program.compile();
    }
    constructor(src) {
        const builder = createClippingBuilder(src);
        this._program = builder.buildProgram(System.instance.context);
    }
    getProgram(numPlanes) {
        return numPlanes > 0 ? this._program : undefined;
    }
    dispose() {
        this._program = dispose(this._program);
    }
}
/** @internal */
export function createClippingProgram(builder) {
    return new ClippingProgram(builder);
}
//# sourceMappingURL=ClippingProgram.js.map