BlendingState.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import BlendEquation from "./BlendEquation.js";
  2. import BlendFunction from "./BlendFunction.js";
  3. /**
  4. * The blending state combines {@link BlendEquation} and {@link BlendFunction} and the
  5. * <code>enabled</code> flag to define the full blending state for combining source and
  6. * destination fragments when rendering.
  7. * <p>
  8. * This is a helper when using custom render states with {@link Appearance#renderState}.
  9. * </p>
  10. *
  11. * @namespace
  12. */
  13. const BlendingState = {
  14. /**
  15. * Blending is disabled.
  16. *
  17. * @type {object}
  18. * @constant
  19. */
  20. DISABLED: Object.freeze({
  21. enabled: false,
  22. }),
  23. /**
  24. * Blending is enabled using alpha blending, <code>source(source.alpha) + destination(1 - source.alpha)</code>.
  25. *
  26. * @type {object}
  27. * @constant
  28. */
  29. ALPHA_BLEND: Object.freeze({
  30. enabled: true,
  31. equationRgb: BlendEquation.ADD,
  32. equationAlpha: BlendEquation.ADD,
  33. functionSourceRgb: BlendFunction.SOURCE_ALPHA,
  34. functionSourceAlpha: BlendFunction.ONE,
  35. functionDestinationRgb: BlendFunction.ONE_MINUS_SOURCE_ALPHA,
  36. functionDestinationAlpha: BlendFunction.ONE_MINUS_SOURCE_ALPHA,
  37. }),
  38. /**
  39. * Blending is enabled using alpha blending with premultiplied alpha, <code>source + destination(1 - source.alpha)</code>.
  40. *
  41. * @type {object}
  42. * @constant
  43. */
  44. PRE_MULTIPLIED_ALPHA_BLEND: Object.freeze({
  45. enabled: true,
  46. equationRgb: BlendEquation.ADD,
  47. equationAlpha: BlendEquation.ADD,
  48. functionSourceRgb: BlendFunction.ONE,
  49. functionSourceAlpha: BlendFunction.ONE,
  50. functionDestinationRgb: BlendFunction.ONE_MINUS_SOURCE_ALPHA,
  51. functionDestinationAlpha: BlendFunction.ONE_MINUS_SOURCE_ALPHA,
  52. }),
  53. /**
  54. * Blending is enabled using additive blending, <code>source(source.alpha) + destination</code>.
  55. *
  56. * @type {object}
  57. * @constant
  58. */
  59. ADDITIVE_BLEND: Object.freeze({
  60. enabled: true,
  61. equationRgb: BlendEquation.ADD,
  62. equationAlpha: BlendEquation.ADD,
  63. functionSourceRgb: BlendFunction.SOURCE_ALPHA,
  64. functionSourceAlpha: BlendFunction.ONE,
  65. functionDestinationRgb: BlendFunction.ONE,
  66. functionDestinationAlpha: BlendFunction.ONE,
  67. }),
  68. };
  69. export default Object.freeze(BlendingState);