Comparing version 0.0.113 to 0.0.114
{ | ||
"name": "ogl", | ||
"version": "0.0.113", | ||
"version": "0.0.114", | ||
"description": "WebGL Library", | ||
@@ -5,0 +5,0 @@ "exports": "./src/index.mjs", |
@@ -5,4 +5,4 @@ let supportedFormat; | ||
export class BasisManager { | ||
constructor(workerSrc) { | ||
if (!supportedFormat) supportedFormat = this.getSupportedFormat(); | ||
constructor(workerSrc, canvas) { | ||
if (!supportedFormat) supportedFormat = this.getSupportedFormat(canvas); | ||
this.onMessage = this.onMessage.bind(this); | ||
@@ -13,4 +13,4 @@ this.queue = new Map(); | ||
getSupportedFormat() { | ||
const gl = document.createElement('canvas').getContext('webgl'); | ||
getSupportedFormat(canvas = document.createElement('canvas')) { | ||
const gl = canvas.getContext('webgl'); | ||
/* if (!!gl.getExtension('WEBGL_compressed_texture_etc')) { | ||
@@ -17,0 +17,0 @@ return 'etc2'; |
@@ -9,2 +9,13 @@ import { Texture } from '../core/Texture.js'; | ||
const isCreateImageBitmap = (() => { | ||
const isChrome = navigator.userAgent.toLowerCase().includes('chrome'); | ||
if (!isChrome) return false; | ||
try { | ||
createImageBitmap; | ||
} catch (e) { | ||
return false; | ||
} | ||
return true; | ||
})(); | ||
export class TextureLoader { | ||
@@ -143,7 +154,4 @@ static load( | ||
// Check for WebP support | ||
if (detectWebP()) supportedExtensions.push('webp'); | ||
// Formats supported by all | ||
supportedExtensions.push('png', 'jpg'); | ||
supportedExtensions.push('png', 'jpg', 'webp'); | ||
@@ -185,6 +193,2 @@ return supportedExtensions; | ||
function detectWebP() { | ||
return document.createElement('canvas').toDataURL('image/webp').indexOf('data:image/webp') == 0; | ||
} | ||
function powerOfTwo(value) { | ||
@@ -197,8 +201,6 @@ // (width & (width - 1)) !== 0 | ||
return new Promise((resolve) => { | ||
// Only chrome's implementation of createImageBitmap is fully supported | ||
const isChrome = navigator.userAgent.toLowerCase().includes('chrome'); | ||
if (!!window.createImageBitmap && isChrome) { | ||
if (isCreateImageBitmap) { | ||
fetch(src, { mode: 'cors' }) | ||
.then(r => r.blob()) | ||
.then(b => createImageBitmap(b, { imageOrientation: flipY ? 'flipY' : 'none', premultiplyAlpha: 'none' })) | ||
.then((r) => r.blob()) | ||
.then((b) => createImageBitmap(b, { imageOrientation: flipY ? 'flipY' : 'none', premultiplyAlpha: 'none' })) | ||
.then(resolve); | ||
@@ -205,0 +207,0 @@ } else { |
9196
335541