import { getDDSMipLevelsInfo } from './dds.js';
import { AbstractTextureLoader } from '../loader.js';
import { getDevice } from '../../../app/api.js';

/**
 * The DDS texture loader
 * @internal
 */ class DDSLoader extends AbstractTextureLoader {
    supportMIMEType(mimeType) {
        return mimeType === 'image/dds' || mimeType === 'image/x-dds';
    }
    async load(mimeType, data, srgb, samplerOptions, texture) {
        const arrayBuffer = data instanceof ArrayBuffer ? data : data.buffer;
        const offset = data instanceof ArrayBuffer ? 0 : data.byteOffset;
        const mipmapLevelData = getDDSMipLevelsInfo(arrayBuffer, offset);
        if (!mipmapLevelData) {
            throw new Error('read DDS file failed');
        }
        const options = {
            texture: texture ?? undefined,
            samplerOptions
        };
        return getDevice().createTextureFromMipmapData(mipmapLevelData, srgb, options);
    }
}

export { DDSLoader };
//# sourceMappingURL=dds_loader.js.map
