import { Asset } from "../../Asset.js";
import { cloneTexture } from "./cloneTexture.js";
import { TextureLoader as ThreeTextureLoader } from "three";

const textureLoader = new ThreeTextureLoader();

/**
 *
 * @param {Texture} texture
 * @return {number}
 */
export function computeTextureByteSize(texture) {
    const image = texture.image;
    if (image instanceof ImageData) {
        return image.array.length;
    } else {
        //TODO do actual computation
        //don't know
        return 1;
    }
}
export function loadStandardImageTexture(path, success, failure, progress) {



    textureLoader.load(path, function (texture) {

        texture.flipY = false;

        const byteSize = computeTextureByteSize(texture);

        const asset = new Asset(function () {
            return cloneTexture(texture);
        }, byteSize);

        success(asset);
    }, progress, failure);
}
