Reference Source

src/viewer/scene/webgl/RenderState.js

  1. import {Map} from "../utils/Map.js";
  2.  
  3. const ids = new Map({});
  4.  
  5. /**
  6. * @desc Represents a chunk of state changes applied by the {@link Scene}'s renderer while it renders a frame.
  7. *
  8. * * Contains properties that represent the state changes.
  9. * * Has a unique automatically-generated numeric ID, which the renderer can use to sort these, in order to avoid applying redundant state changes for each frame.
  10. * * Initialize your own properties on a RenderState via its constructor.
  11. *
  12. * @private
  13. */
  14. class RenderState {
  15.  
  16. constructor(cfg) {
  17.  
  18. /**
  19. The RenderState's ID, unique within the renderer.
  20. @property id
  21. @type {Number}
  22. @final
  23. */
  24. this.id = ids.addItem({});
  25. for (const key in cfg) {
  26. if (cfg.hasOwnProperty(key)) {
  27. this[key] = cfg[key];
  28. }
  29. }
  30. }
  31.  
  32. /**
  33. Destroys this RenderState.
  34. */
  35. destroy() {
  36. ids.removeItem(this.id);
  37. }
  38. }
  39.  
  40. export {RenderState};