-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve resource management performance (#10)
* perf: update ResourceManager * fix resourceManager reset bug * fix typo * update examples & fix something...
- Loading branch information
Showing
6 changed files
with
189 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<title>Hilo3d ResourceManager Test</title> | ||
<link rel="stylesheet" type="text/css" href="./example.css"> | ||
</head> | ||
<body> | ||
<div id="container"></div> | ||
<script src="../build/Hilo3d.js"></script> | ||
<script src="./js/stats.js"></script> | ||
<script src="./js/OrbitControls.js"></script> | ||
<script src="./js/init.js"></script> | ||
<script> | ||
var boxGeometry = new Hilo3d.BoxGeometry(); | ||
boxGeometry.setAllRectUV([[0, 1], [1, 1], [1, 0], [0, 0]]); | ||
|
||
var colorBox = new Hilo3d.Mesh({ | ||
geometry: boxGeometry, | ||
material: new Hilo3d.BasicMaterial({ | ||
diffuse: new Hilo3d.Color(0.8, 0, 0) | ||
}), | ||
x: -1, | ||
onUpdate: function() { | ||
this.rotationX += .5; | ||
this.rotationY += .5; | ||
} | ||
}); | ||
stage.addChild(colorBox); | ||
|
||
var colorBox2 = new Hilo3d.Mesh({ | ||
geometry: boxGeometry, | ||
material: new Hilo3d.BasicMaterial({ | ||
diffuse: new Hilo3d.Color(0.8, 0, 0) | ||
}), | ||
x: -1.2, | ||
onUpdate: function() { | ||
this.rotationX += .5; | ||
this.rotationY += .5; | ||
} | ||
}); | ||
stage.addChild(colorBox2.setScale(0.5)); | ||
|
||
var angle = 0; | ||
var axis = new Hilo3d.Vector3(1, 1, 1).normalize(); | ||
var textureBox = new Hilo3d.Mesh({ | ||
geometry:boxGeometry, | ||
material: new Hilo3d.BasicMaterial({ | ||
diffuse:new Hilo3d.LazyTexture({ | ||
crossOrigin:true, | ||
src:'//gw.alicdn.com/tfs/TB1iNtERXXXXXcBaXXXXXXXXXXX-600-600.png' | ||
}) | ||
}), | ||
x: 1, | ||
onUpdate: function() { | ||
angle += Hilo3d.math.DEG2RAD; | ||
this.quaternion.setAxisAngle(axis, angle); | ||
} | ||
}); | ||
stage.addChild(textureBox); | ||
|
||
const sleep = async (time) => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, time); | ||
}); | ||
}; | ||
(async () => { | ||
stage.renderer.onInit(() => { | ||
stage.renderer.resourceManager.on('destroyResource', (e) => { | ||
console.log(`%c - ${e.detail}`, 'color:red'); | ||
}); | ||
}); | ||
|
||
const WAIT_TIME = 1000; | ||
await sleep(WAIT_TIME); | ||
Hilo3d.logGLResource() | ||
|
||
await sleep(WAIT_TIME); | ||
colorBox.destroy(renderer, true); | ||
console.log("\n----------------------------\ncolorBox destroy"); | ||
await sleep(WAIT_TIME); | ||
Hilo3d.logGLResource(); | ||
|
||
await sleep(WAIT_TIME); | ||
colorBox2.destroy(renderer, true); | ||
console.log("\n----------------------------\ncolorBox2 destroy"); | ||
await sleep(WAIT_TIME); | ||
Hilo3d.logGLResource(); | ||
|
||
await sleep(WAIT_TIME); | ||
textureBox.destroy(renderer, true); | ||
console.log("\n----------------------------\ntextureBox destroy"); | ||
await sleep(WAIT_TIME); | ||
Hilo3d.logGLResource(); | ||
|
||
console.log(` | ||
queryObjects(WebGLBuffer); | ||
queryObjects(WebGLProgram); | ||
queryObjects(Hilo3d.VertexArrayObject); | ||
`); | ||
})(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.