babylon.renderingManager.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var RenderingManager = (function () {
  4. function RenderingManager(scene) {
  5. this._renderingGroups = new Array();
  6. this._scene = scene;
  7. }
  8. RenderingManager.prototype._renderParticles = function (index, activeMeshes) {
  9. if (this._scene._activeParticleSystems.length === 0) {
  10. return;
  11. }
  12. // Particles
  13. var beforeParticlesDate = BABYLON.Tools.Now;
  14. for (var particleIndex = 0; particleIndex < this._scene._activeParticleSystems.length; particleIndex++) {
  15. var particleSystem = this._scene._activeParticleSystems.data[particleIndex];
  16. if (particleSystem.renderingGroupId !== index) {
  17. continue;
  18. }
  19. this._clearDepthBuffer();
  20. if (!particleSystem.emitter.position || !activeMeshes || activeMeshes.indexOf(particleSystem.emitter) !== -1) {
  21. this._scene._activeParticles += particleSystem.render();
  22. }
  23. }
  24. this._scene._particlesDuration += BABYLON.Tools.Now - beforeParticlesDate;
  25. };
  26. RenderingManager.prototype._renderSprites = function (index) {
  27. if (this._scene.spriteManagers.length === 0) {
  28. return;
  29. }
  30. // Sprites
  31. var beforeSpritessDate = BABYLON.Tools.Now;
  32. for (var id = 0; id < this._scene.spriteManagers.length; id++) {
  33. var spriteManager = this._scene.spriteManagers[id];
  34. if (spriteManager.renderingGroupId === index) {
  35. this._clearDepthBuffer();
  36. spriteManager.render();
  37. }
  38. }
  39. this._scene._spritesDuration += BABYLON.Tools.Now - beforeSpritessDate;
  40. };
  41. RenderingManager.prototype._clearDepthBuffer = function () {
  42. if (this._depthBufferAlreadyCleaned) {
  43. return;
  44. }
  45. this._scene.getEngine().clear(0, false, true);
  46. this._depthBufferAlreadyCleaned = true;
  47. };
  48. RenderingManager.prototype.render = function (customRenderFunction, activeMeshes, renderParticles, renderSprites) {
  49. for (var index = 0; index < RenderingManager.MAX_RENDERINGGROUPS; index++) {
  50. this._depthBufferAlreadyCleaned = false;
  51. var renderingGroup = this._renderingGroups[index];
  52. if (renderingGroup) {
  53. this._clearDepthBuffer();
  54. if (!renderingGroup.render(customRenderFunction)) {
  55. this._renderingGroups.splice(index, 1);
  56. }
  57. }
  58. if (renderSprites) {
  59. this._renderSprites(index);
  60. }
  61. if (renderParticles) {
  62. this._renderParticles(index, activeMeshes);
  63. }
  64. }
  65. };
  66. RenderingManager.prototype.reset = function () {
  67. for (var index in this._renderingGroups) {
  68. var renderingGroup = this._renderingGroups[index];
  69. renderingGroup.prepare();
  70. }
  71. };
  72. RenderingManager.prototype.dispatch = function (subMesh) {
  73. var mesh = subMesh.getMesh();
  74. var renderingGroupId = mesh.renderingGroupId || 0;
  75. if (!this._renderingGroups[renderingGroupId]) {
  76. this._renderingGroups[renderingGroupId] = new BABYLON.RenderingGroup(renderingGroupId, this._scene);
  77. }
  78. this._renderingGroups[renderingGroupId].dispatch(subMesh);
  79. };
  80. RenderingManager.MAX_RENDERINGGROUPS = 4;
  81. return RenderingManager;
  82. })();
  83. BABYLON.RenderingManager = RenderingManager;
  84. })(BABYLON || (BABYLON = {}));
  85. //# sourceMappingURL=babylon.renderingManager.js.map