lint
This commit is contained in:
parent
ce7914732e
commit
aef5e53cc3
|
@ -2,6 +2,7 @@
|
||||||
* Initialize a texture and load an image.
|
* Initialize a texture and load an image.
|
||||||
* @param {any} gl the gl context
|
* @param {any} gl the gl context
|
||||||
* @param {string} url the url of the texture
|
* @param {string} url the url of the texture
|
||||||
|
* @return {any} the loaded texture
|
||||||
*/
|
*/
|
||||||
export function loadTexture(gl: any, url: any) {
|
export function loadTexture(gl: any, url: any) {
|
||||||
const texture = gl.createTexture();
|
const texture = gl.createTexture();
|
||||||
|
@ -19,7 +20,7 @@ export function loadTexture(gl: any, url: any) {
|
||||||
const border = 0;
|
const border = 0;
|
||||||
const srcFormat = gl.RGBA;
|
const srcFormat = gl.RGBA;
|
||||||
const srcType = gl.UNSIGNED_BYTE;
|
const srcType = gl.UNSIGNED_BYTE;
|
||||||
const pixel = new Uint8Array([0, 0, 255, 255]); // opaque blue
|
const pixel = new Uint8Array([0, 0, 255, 255]);
|
||||||
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
|
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
|
||||||
width, height, border, srcFormat, srcType,
|
width, height, border, srcFormat, srcType,
|
||||||
pixel);
|
pixel);
|
||||||
|
@ -28,7 +29,7 @@ export function loadTexture(gl: any, url: any) {
|
||||||
image.onload = function() {
|
image.onload = function() {
|
||||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
|
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat,
|
||||||
srcFormat, srcType, image);
|
srcFormat, srcType, image);
|
||||||
|
|
||||||
// WebGL1 has different requirements for power of 2 images
|
// WebGL1 has different requirements for power of 2 images
|
||||||
// vs non power of 2 images so check if the image is a
|
// vs non power of 2 images so check if the image is a
|
||||||
|
@ -39,8 +40,10 @@ export function loadTexture(gl: any, url: any) {
|
||||||
} else {
|
} else {
|
||||||
// No, it's not a power of 2. Turn off mips and set
|
// No, it's not a power of 2. Turn off mips and set
|
||||||
// wrapping to clamp to edge
|
// wrapping to clamp to edge
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
gl.texParameteri(gl.TEXTURE_2D,
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||||
|
gl.texParameteri(gl.TEXTURE_2D,
|
||||||
|
gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -49,6 +52,11 @@ export function loadTexture(gl: any, url: any) {
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if number is power of 2
|
||||||
|
* @param {number} value the number to check
|
||||||
|
* @return {boolean} true if is power of 2 else false
|
||||||
|
*/
|
||||||
function isPowerOf2(value: number) {
|
function isPowerOf2(value: number) {
|
||||||
return (value & (value - 1)) == 0;
|
return (value & (value - 1)) == 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue