babylon.postProcessManager.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var BABYLON = BABYLON || {};
  2. (function () {
  3. BABYLON.PostProcessManager = function (scene) {
  4. this._scene = scene;
  5. // VBO
  6. var vertices = [];
  7. vertices.push(1, 1);
  8. vertices.push(-1, 1);
  9. vertices.push(-1, -1);
  10. vertices.push(1, -1);
  11. this._vertexDeclaration = [2];
  12. this._vertexStrideSize = 2 * 4;
  13. this._vertexBuffer = scene.getEngine().createVertexBuffer(vertices);
  14. // Indices
  15. var indices = [];
  16. indices.push(0);
  17. indices.push(1);
  18. indices.push(2);
  19. indices.push(0);
  20. indices.push(2);
  21. indices.push(3);
  22. this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
  23. };
  24. // Methods
  25. BABYLON.PostProcessManager.prototype._prepareFrame = function () {
  26. var postProcesses = this._scene.activeCamera.postProcesses;
  27. if (postProcesses.length === 0 || !this._scene.postProcessesEnabled) {
  28. return;
  29. }
  30. postProcesses[0].activate();
  31. };
  32. BABYLON.PostProcessManager.prototype._finalizeFrame = function () {
  33. var postProcesses = this._scene.activeCamera.postProcesses;
  34. if (postProcesses.length === 0 || !this._scene.postProcessesEnabled) {
  35. return;
  36. }
  37. var engine = this._scene.getEngine();
  38. for (var index = 0; index < postProcesses.length; index++) {
  39. if (index < postProcesses.length - 1) {
  40. postProcesses[index + 1].activate();
  41. } else {
  42. engine.restoreDefaultFramebuffer();
  43. }
  44. var effect = postProcesses[index].apply();
  45. if (effect) {
  46. // VBOs
  47. engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, effect);
  48. // Draw order
  49. engine.draw(true, 0, 6);
  50. }
  51. }
  52. };
  53. BABYLON.PostProcessManager.prototype.dispose = function () {
  54. if (this._vertexBuffer) {
  55. this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
  56. this._vertexBuffer = null;
  57. }
  58. if (this._indexBuffer) {
  59. this._scene.getEngine()._releaseBuffer(this._indexBuffer);
  60. this._indexBuffer = null;
  61. }
  62. };
  63. })();