babylon.renderingManager.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 = new Date().getTime();
  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 += new Date().getTime() - beforeParticlesDate;
  25. };
  26. RenderingManager.prototype._renderSprites = function (index) {
  27. if (this._scene.spriteManagers.length === 0) {
  28. return;
  29. }
  30. // Sprites
  31. var beforeSpritessDate = new Date().getTime();
  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 += new Date().getTime() - 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. var _this = this;
  50. for (var index = 0; index < BABYLON.RenderingManager.MAX_RENDERINGGROUPS; index++) {
  51. this._depthBufferAlreadyCleaned = index == 0;
  52. var renderingGroup = this._renderingGroups[index];
  53. if (renderingGroup) {
  54. this._clearDepthBuffer();
  55. if (!renderingGroup.render(customRenderFunction, function () {
  56. if (renderSprites) {
  57. _this._renderSprites(index);
  58. }
  59. })) {
  60. this._renderingGroups.splice(index, 1);
  61. }
  62. } else if (renderSprites) {
  63. this._renderSprites(index);
  64. }
  65. if (renderParticles) {
  66. this._renderParticles(index, activeMeshes);
  67. }
  68. }
  69. };
  70. RenderingManager.prototype.reset = function () {
  71. for (var index in this._renderingGroups) {
  72. var renderingGroup = this._renderingGroups[index];
  73. renderingGroup.prepare();
  74. }
  75. };
  76. RenderingManager.prototype.dispatch = function (subMesh) {
  77. var mesh = subMesh.getMesh();
  78. var renderingGroupId = mesh.renderingGroupId || 0;
  79. if (!this._renderingGroups[renderingGroupId]) {
  80. this._renderingGroups[renderingGroupId] = new BABYLON.RenderingGroup(renderingGroupId, this._scene);
  81. }
  82. this._renderingGroups[renderingGroupId].dispatch(subMesh);
  83. };
  84. RenderingManager.MAX_RENDERINGGROUPS = 4;
  85. return RenderingManager;
  86. })();
  87. BABYLON.RenderingManager = RenderingManager;
  88. })(BABYLON || (BABYLON = {}));
  89. //# sourceMappingURL=babylon.renderingManager.js.map