import { Texture } from '@luma.gl/core';
const DEFAULT_TEXTURE_PARAMETERS = {
  minFilter: 'linear',
  mipmapFilter: 'linear',
  magFilter: 'linear',
  addressModeU: 'clamp-to-edge',
  addressModeV: 'clamp-to-edge'
};
const internalTextures = {};
export function createTexture(owner, device, image, sampler) {
  if (image instanceof Texture) {
    return image;
  } else if (image.constructor && image.constructor.name !== 'Object') {
    image = {
      data: image
    };
  }

  let samplerParameters = null;

  if (image.compressed) {
    samplerParameters = {
      minFilter: 'linear',
      mipmapFilter: image.data.length > 1 ? 'nearest' : 'linear'
    };
  }

  const texture = device.createTexture({ ...image,
    sampler: { ...DEFAULT_TEXTURE_PARAMETERS,
      ...samplerParameters,
      ...sampler
    }
  });
  internalTextures[texture.id] = owner;
  return texture;
}
export function destroyTexture(owner, texture) {
  if (!texture || !(texture instanceof Texture)) {
    return;
  }

  if (internalTextures[texture.id] === owner) {
    texture.delete();
    delete internalTextures[texture.id];
  }
}
//# sourceMappingURL=texture.js.map