PickDepthFramebuffer.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import BoundingRectangle from "../Core/BoundingRectangle.js";
  2. import destroyObject from "../Core/destroyObject.js";
  3. import FramebufferManager from "../Renderer/FramebufferManager.js";
  4. import PassState from "../Renderer/PassState.js";
  5. /**
  6. * @private
  7. */
  8. function PickDepthFramebuffer() {
  9. this._framebuffer = new FramebufferManager({
  10. color: false,
  11. depthStencil: true,
  12. supportsDepthTexture: true,
  13. });
  14. this._passState = undefined;
  15. }
  16. Object.defineProperties(PickDepthFramebuffer.prototype, {
  17. framebuffer: {
  18. get: function () {
  19. return this._framebuffer.framebuffer;
  20. },
  21. },
  22. });
  23. function destroyResources(pickDepth) {
  24. pickDepth._framebuffer.destroy();
  25. }
  26. function createResources(pickDepth, context) {
  27. const width = context.drawingBufferWidth;
  28. const height = context.drawingBufferHeight;
  29. pickDepth._framebuffer.update(context, width, height);
  30. const passState = new PassState(context);
  31. passState.blendingEnabled = false;
  32. passState.scissorTest = {
  33. enabled: true,
  34. rectangle: new BoundingRectangle(),
  35. };
  36. passState.viewport = new BoundingRectangle();
  37. pickDepth._passState = passState;
  38. }
  39. PickDepthFramebuffer.prototype.update = function (
  40. context,
  41. drawingBufferPosition,
  42. viewport
  43. ) {
  44. const width = viewport.width;
  45. const height = viewport.height;
  46. if (this._framebuffer.isDirty(width, height)) {
  47. createResources(this, context);
  48. }
  49. const framebuffer = this.framebuffer;
  50. const passState = this._passState;
  51. passState.framebuffer = framebuffer;
  52. passState.viewport.width = width;
  53. passState.viewport.height = height;
  54. passState.scissorTest.rectangle.x = drawingBufferPosition.x;
  55. passState.scissorTest.rectangle.y = height - drawingBufferPosition.y;
  56. passState.scissorTest.rectangle.width = 1;
  57. passState.scissorTest.rectangle.height = 1;
  58. return passState;
  59. };
  60. PickDepthFramebuffer.prototype.isDestroyed = function () {
  61. return false;
  62. };
  63. PickDepthFramebuffer.prototype.destroy = function () {
  64. destroyResources(this);
  65. return destroyObject(this);
  66. };
  67. export default PickDepthFramebuffer;