babylon.alphaCullingState.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Internals;
  4. (function (Internals) {
  5. var _AlphaState = (function () {
  6. function _AlphaState() {
  7. this._isAlphaBlendDirty = false;
  8. this._isBlendFunctionParametersDirty = false;
  9. this._alphaBlend = false;
  10. this._blendFunctionParameters = new Array(4);
  11. }
  12. Object.defineProperty(_AlphaState.prototype, "isDirty", {
  13. get: function () {
  14. return this._isAlphaBlendDirty || this._isBlendFunctionParametersDirty;
  15. },
  16. enumerable: true,
  17. configurable: true
  18. });
  19. Object.defineProperty(_AlphaState.prototype, "alphaBlend", {
  20. get: function () {
  21. return this._alphaBlend;
  22. },
  23. set: function (value) {
  24. if (this._alphaBlend === value) {
  25. return;
  26. }
  27. this._alphaBlend = value;
  28. this._isAlphaBlendDirty = true;
  29. },
  30. enumerable: true,
  31. configurable: true
  32. });
  33. _AlphaState.prototype.setAlphaBlendFunctionParameters = function (value0, value1, value2, value3) {
  34. if (this._blendFunctionParameters[0] === value0 &&
  35. this._blendFunctionParameters[1] === value1 &&
  36. this._blendFunctionParameters[2] === value2 &&
  37. this._blendFunctionParameters[3] === value3) {
  38. return;
  39. }
  40. this._blendFunctionParameters[0] = value0;
  41. this._blendFunctionParameters[1] = value1;
  42. this._blendFunctionParameters[2] = value2;
  43. this._blendFunctionParameters[3] = value3;
  44. this._isBlendFunctionParametersDirty = true;
  45. };
  46. _AlphaState.prototype.reset = function () {
  47. this._alphaBlend = false;
  48. this._blendFunctionParameters[0] = null;
  49. this._blendFunctionParameters[1] = null;
  50. this._blendFunctionParameters[2] = null;
  51. this._blendFunctionParameters[3] = null;
  52. this._isAlphaBlendDirty = true;
  53. this._isBlendFunctionParametersDirty = false;
  54. };
  55. _AlphaState.prototype.apply = function (gl) {
  56. if (!this.isDirty) {
  57. return;
  58. }
  59. // Alpha blend
  60. if (this._isAlphaBlendDirty) {
  61. if (this._alphaBlend) {
  62. gl.enable(gl.BLEND);
  63. }
  64. else {
  65. gl.disable(gl.BLEND);
  66. }
  67. this._isAlphaBlendDirty = false;
  68. }
  69. // Alpha function
  70. if (this._isBlendFunctionParametersDirty) {
  71. gl.blendFuncSeparate(this._blendFunctionParameters[0], this._blendFunctionParameters[1], this._blendFunctionParameters[2], this._blendFunctionParameters[3]);
  72. this._isBlendFunctionParametersDirty = false;
  73. }
  74. };
  75. return _AlphaState;
  76. }());
  77. Internals._AlphaState = _AlphaState;
  78. })(Internals = BABYLON.Internals || (BABYLON.Internals = {}));
  79. })(BABYLON || (BABYLON = {}));