import { CopyBlitter } from '../blitter/copy.js';
import { getDevice } from '../app/api.js';

const samplerOptions = {
    clamp_linear: {
        addressU: 'clamp',
        addressV: 'clamp',
        magFilter: 'linear',
        minFilter: 'linear',
        mipFilter: 'linear'
    },
    clamp_linear_nomip: {
        addressU: 'clamp',
        addressV: 'clamp',
        magFilter: 'linear',
        minFilter: 'linear',
        mipFilter: 'none'
    },
    clamp_nearest: {
        addressU: 'clamp',
        addressV: 'clamp',
        magFilter: 'nearest',
        minFilter: 'nearest',
        mipFilter: 'nearest'
    },
    clamp_nearest_nomip: {
        addressU: 'clamp',
        addressV: 'clamp',
        magFilter: 'nearest',
        minFilter: 'nearest',
        mipFilter: 'none'
    },
    repeat_linear: {
        addressU: 'repeat',
        addressV: 'repeat',
        magFilter: 'linear',
        minFilter: 'linear',
        mipFilter: 'linear'
    },
    repeat_linear_nomip: {
        addressU: 'repeat',
        addressV: 'repeat',
        magFilter: 'linear',
        minFilter: 'linear',
        mipFilter: 'none'
    },
    repeat_nearest: {
        addressU: 'repeat',
        addressV: 'repeat',
        magFilter: 'nearest',
        minFilter: 'nearest',
        mipFilter: 'nearest'
    },
    repeat_nearest_nomip: {
        addressU: 'repeat',
        addressV: 'repeat',
        magFilter: 'nearest',
        minFilter: 'nearest',
        mipFilter: 'none'
    }
};
const samplers = {};
let copyBlitter = null;
let defaultCopyRenderState = null;
/**
 * Fetch a sampler by type
 * @param type - The sampler type to fetch
 * @returns The sampler for the given type
 * @public
 */ function fetchSampler(type) {
    let sampler = samplers[type];
    if (!sampler) {
        const opt = samplerOptions[type];
        if (opt) {
            sampler = getDevice().createSampler(opt);
            samplers[type] = sampler;
        }
    }
    return sampler ?? null;
}
/**
 * Utility function to copy a texture
 * @param src - Source texture to copy from
 * @param dest - Destination texture to copy to
 * @param sampler - Sampler object use to sample the source texture
 * @param renderState - RenderStateSet object used to copy texture
 * @param layer - Texture layer to copy
 * @param srgbOut - true if output color in sRGB color space
 * @internal
 */ function copyTexture(src, dest, sampler = null, renderState = null, layer = 0, srgbOut = false) {
    if (!renderState && !defaultCopyRenderState) {
        defaultCopyRenderState = src.device.createRenderStateSet();
        defaultCopyRenderState.useDepthState().enableTest(false).enableWrite(false);
        defaultCopyRenderState.useRasterizerState().setCullMode('none');
    }
    if (!copyBlitter) {
        copyBlitter = new CopyBlitter();
    }
    copyBlitter.renderStates = renderState ?? defaultCopyRenderState;
    copyBlitter.srgbOut = srgbOut;
    copyBlitter.blit(src, dest, layer, sampler);
}

export { copyTexture, fetchSampler };
//# sourceMappingURL=misc.js.map
