var _a;
import { native_, mapState_ } from './Constants';
export class GPUBuffer {
    constructor() {
        this[_a] = 'unmapped';
    }
    get label() {
        return this[native_]?.label ?? '';
    }
    get size() {
        return this[native_]?.size ?? 0;
    }
    get usage() {
        return this[native_]?.usage ?? 0;
    }
    get native() {
        return this[native_];
    }
    destroy() {
        this[native_]?.destroy?.();
    }
    get mapState() {
        return this[mapState_];
    }
    getMappedRange(offset, size) {
        let rangeSize;
        if (size === undefined) {
            rangeSize = Math.max(0, this.size - (offset ?? 0));
        }
        else {
            rangeSize = size;
        }
        return this[native_].getMappedRange(offset, rangeSize);
    }
    mapAsync(mode, offset, size) {
        return this[native_].mapAsync(mode, offset, size).then((value) => {
            this[mapState_] = 'mapped';
            return value;
        });
    }
    unmap() {
        this[native_].unmap();
        this[mapState_] = 'unmapped';
    }
    static fromNative(buffer, mappedAtCreation = false) {
        if (buffer) {
            const ret = new GPUBuffer();
            ret[native_] = buffer;
            if (mappedAtCreation) {
                ret[mapState_] = 'mapped';
            }
            return ret;
        }
        return null;
    }
}
_a = mapState_;
//# sourceMappingURL=GPUBuffer.js.map