import { COORDINATE_SYSTEM, Layer, project32 } from "@deck.gl/core";
import { Geometry, Model } from "@luma.gl/engine";
import { precisionForTests } from "../shader_modules/test-precision/precisionForTests";
import fragmentShader from "./box.fs.glsl";
import vertexShader from "./box.vs.glsl";
const defaultProps = {
    name: "Box",
    id: "box-layer",
    coordinateSystem: COORDINATE_SYSTEM.CARTESIAN,
    lines: [],
    color: [0, 0, 0, 1],
};
export default class BoxLayer extends Layer {
    initializeState(context) {
        this.setState(this._getModels(context.device));
    }
    shouldUpdateState() {
        return true;
    }
    updateState({ context }) {
        this.setState(this._getModels(context.device));
    }
    setShaderModuleProps(args) {
        var _a;
        const color = ((_a = this.props.color) !== null && _a !== void 0 ? _a : defaultProps.color).map((x, i) => i < 3 ? (x !== null && x !== void 0 ? x : 0) / 255 : 1);
        super.setShaderModuleProps(Object.assign(Object.assign({}, args), { box: {
                uColor: color,
            } }));
    }
    _getModels(device) {
        const grids = new Model(device, Object.assign(Object.assign({ id: `${this.props.id}-grids` }, super.getShaders({
            vs: vertexShader,
            fs: fragmentShader,
            modules: [project32, precisionForTests, boxUniforms],
        })), { geometry: new Geometry({
                topology: "line-list",
                attributes: {
                    positions: new Float32Array(this.props.lines),
                },
                vertexCount: this.props.lines.length / 3,
            }), isInstanced: false }));
        return {
            model: grids,
            models: [grids].filter(Boolean),
            modelsByName: { grids },
        };
    }
}
BoxLayer.layerName = "BoxLayer";
BoxLayer.defaultProps = defaultProps;
const boxUniformsBlock = `\
uniform boxUniforms {
    uniform vec4 uColor;
} box;
`;
// NOTE: this must exactly the same name than in the uniform block
const boxUniforms = {
    name: "box",
    vs: boxUniformsBlock,
    fs: undefined,
    uniformTypes: {
        uColor: "vec4<f32>",
    },
};
//# sourceMappingURL=boxLayer.js.map