Comparing version 0.2.5 to 0.2.6
@@ -24,3 +24,3 @@ | ||
jsTemplate: path.join(__dirname, './template/js.handlebars'), | ||
watchTest: true | ||
watchTest: false | ||
}); | ||
@@ -27,0 +27,0 @@ |
{ | ||
"name": "g3d", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "webgl render engine compatible with both browser and gcanvas", | ||
@@ -5,0 +5,0 @@ "main": "dist/g3d.min.js", |
@@ -0,1 +1,10 @@ | ||
<p align="center"> | ||
<a href="https://alibaba.github.io/G3D/"><img src ="https://alibaba.github.io/G3D/assets/logo-g3d.png" /></a> | ||
</p> | ||
<p align="center"> | ||
<a href="https://travis-ci.org/alibaba/G3D"><img src ="https://travis-ci.org/alibaba/G3D.svg?branch=master" /></a> | ||
<a href="https://www.npmjs.com/search?q=g3d"><img src="https://img.shields.io/npm/v/g3d.svg?style=flat"></a> | ||
</p> | ||
# G3D | ||
@@ -2,0 +11,0 @@ |
@@ -28,5 +28,5 @@ import CubeTexture from "../texture/cube-texture"; | ||
this.diffuse = new CubeTexture({ images: diffuse, sRGB: false }); | ||
this.diffuse = new CubeTexture({ images: diffuse, sRGB }); | ||
this.specular = new CubeTexture({ images: specular, sRGB: false }); | ||
this.specular = new CubeTexture({ images: specular, sRGB }); | ||
@@ -33,0 +33,0 @@ this.brdfLUT = new Texture({ image: brdfLUT, sRGB: false, flipY: false, repeat: false }); |
@@ -9,2 +9,3 @@ import BaseOrthographicCamera from "../camera/base-orthographic-camera"; | ||
import Skybox from "./skybox"; | ||
import LineMesh from "../mesh/line-mesh"; | ||
@@ -11,0 +12,0 @@ class Scene { |
@@ -20,3 +20,2 @@ import GL from "../core/gl"; | ||
images: ICubeTextureConfigImages; | ||
size?: number; | ||
flipY?: boolean; | ||
@@ -47,4 +46,4 @@ sRGB?: boolean; | ||
images, | ||
size = images.left.width, | ||
sRGB = false, | ||
flipY = false, | ||
}: ICubeTextureConfig) { | ||
@@ -56,5 +55,2 @@ | ||
this.size = size; | ||
this.sRGB = sRGB; | ||
const texture = this.glTexture = gl.createTexture(); | ||
@@ -69,2 +65,5 @@ | ||
this.size = images.left.width; | ||
this.sRGB = sRGB; | ||
// wrap | ||
@@ -79,16 +78,7 @@ gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | ||
// fill | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0); | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY ? 1 : 0); | ||
const format = sRGB ? extensionSRGB.SRGB_ALPHA_EXT : gl.RGBA; | ||
for (const [key, value] of this.targets) { | ||
if (images[key] instanceof Uint8Array) { | ||
gl.texImage2D(value, 0, format, size, size, 0, format, gl.UNSIGNED_BYTE, images[key]); | ||
} else { | ||
gl.texImage2D(value, 0, format, format, gl.UNSIGNED_BYTE, images[key]); | ||
} | ||
gl.texImage2D(value, 0, format, format, gl.UNSIGNED_BYTE, images[key]); | ||
} | ||
@@ -98,3 +88,3 @@ | ||
this.mipLevel = Math.log2(size); | ||
this.mipLevel = Math.log2(this.size); | ||
@@ -117,9 +107,4 @@ if (images.mip) { | ||
const { gl, extensions } = GL; | ||
const format = this.sRGB ? extensions.get("SRGB").SRGB_ALPHA_EXT : gl.RGBA; | ||
const extensionSRGB = extensions.get("SRGB"); | ||
const sRGB = this.sRGB && extensionSRGB; | ||
const format = sRGB ? extensionSRGB.SRGB_ALPHA_EXT : gl.RGBA; | ||
// fill | ||
@@ -139,6 +124,7 @@ for (let i = 0; i < mips.length; i++) { | ||
const { gl } = GL; | ||
const { gl, textures } = GL; | ||
gl.deleteTexture(this.glTexture); | ||
textures.delete(this); | ||
} | ||
@@ -145,0 +131,0 @@ |
@@ -7,4 +7,2 @@ import GL from "../core/gl"; | ||
image: HTMLImageElement; | ||
width?: number; | ||
height?: number; | ||
sRGB?: boolean; | ||
@@ -14,2 +12,3 @@ flipY?: boolean; | ||
mipmap?: boolean; | ||
mip?: HTMLImageElement[]; | ||
} | ||
@@ -21,6 +20,12 @@ | ||
public mipLevel: number = 0; | ||
private mipmap: boolean; | ||
private sRGB: boolean; | ||
private width: number; | ||
constructor({ | ||
image, | ||
width = image.width, | ||
height = image.height, | ||
sRGB = false, | ||
@@ -30,2 +35,3 @@ flipY = true, | ||
mipmap = true, | ||
mip = null, | ||
}: ITextureConfig) { | ||
@@ -40,2 +46,3 @@ | ||
const { width, height } = image; | ||
const isP2 = (width === height) && isPowerOf2(width) && isPowerOf2(height); | ||
@@ -49,2 +56,6 @@ | ||
this.mipmap = mipmap; | ||
this.sRGB = sRGB; | ||
this.width = width; | ||
// wrap | ||
@@ -64,12 +75,14 @@ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE); | ||
if (image instanceof Uint8Array) { | ||
gl.texImage2D(gl.TEXTURE_2D, 0, format, width, height, 0, format, gl.UNSIGNED_BYTE, image); | ||
} else { | ||
gl.texImage2D(gl.TEXTURE_2D, 0, format, format, gl.UNSIGNED_BYTE, image); | ||
} | ||
gl.texImage2D(gl.TEXTURE_2D, 0, format, format, gl.UNSIGNED_BYTE, image); | ||
if (mipmap) { | ||
gl.generateMipmap(gl.TEXTURE_2D); | ||
this.mipLevel = Math.log2(this.width); | ||
} | ||
if (mipmap && mip) { | ||
this.setMipmaps(mip); | ||
} | ||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0); | ||
@@ -80,7 +93,33 @@ | ||
public setMipmaps(mip: HTMLImageElement[]): void { | ||
if (this.mipmap) { | ||
const { gl, extensions } = GL; | ||
const format = this.sRGB ? extensions.get("SRGB").SRGB_ALPHA_EXT : gl.RGBA; | ||
if (mip.length === Math.log2(this.width)) { | ||
for (let i = 0; i < mip.length; i++) { | ||
const image = mip[i]; | ||
const size = Math.pow(2, mip.length - i - 1); | ||
if (image.width === size && image.height === size) { | ||
gl.texImage2D(gl.TEXTURE_2D, i + 1, format, format, gl.UNSIGNED_BYTE, image); | ||
} else { | ||
throw new Error("Mipmap image size invalid."); | ||
} | ||
} | ||
} else { | ||
throw new Error("Mipmap length invalid."); | ||
} | ||
} | ||
} | ||
public destructor() { | ||
const { gl } = GL; | ||
const { gl, textures } = GL; | ||
gl.deleteTexture(this.glTexture); | ||
textures.delete(this); | ||
} | ||
@@ -87,0 +126,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
416745
90
7494
21
0