PickDepthFramebuffer.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import BoundingRectangle from "../Core/BoundingRectangle.js";
  2. import defined from "../Core/defined.js";
  3. import destroyObject from "../Core/destroyObject.js";
  4. import PixelFormat from "../Core/PixelFormat.js";
  5. import Framebuffer from "../Renderer/Framebuffer.js";
  6. import PassState from "../Renderer/PassState.js";
  7. import PixelDatatype from "../Renderer/PixelDatatype.js";
  8. import Texture from "../Renderer/Texture.js";
  9. /**
  10. * @private
  11. */
  12. function PickDepthFramebuffer() {
  13. this._depthStencilTexture = undefined;
  14. this._framebuffer = undefined;
  15. this._passState = undefined;
  16. }
  17. function destroyResources(pickDepth) {
  18. pickDepth._framebuffer =
  19. pickDepth._framebuffer && pickDepth._framebuffer.destroy();
  20. pickDepth._depthStencilTexture =
  21. pickDepth._depthStencilTexture && pickDepth._depthStencilTexture.destroy();
  22. }
  23. function createResources(pickDepth, context) {
  24. var width = context.drawingBufferWidth;
  25. var height = context.drawingBufferHeight;
  26. pickDepth._depthStencilTexture = new Texture({
  27. context: context,
  28. width: width,
  29. height: height,
  30. pixelFormat: PixelFormat.DEPTH_STENCIL,
  31. pixelDatatype: PixelDatatype.UNSIGNED_INT_24_8,
  32. });
  33. pickDepth._framebuffer = new Framebuffer({
  34. context: context,
  35. depthStencilTexture: pickDepth._depthStencilTexture,
  36. destroyAttachments: false,
  37. });
  38. var passState = new PassState(context);
  39. passState.blendingEnabled = false;
  40. passState.scissorTest = {
  41. enabled: true,
  42. rectangle: new BoundingRectangle(),
  43. };
  44. passState.viewport = new BoundingRectangle();
  45. pickDepth._passState = passState;
  46. }
  47. PickDepthFramebuffer.prototype.update = function (
  48. context,
  49. drawingBufferPosition,
  50. viewport
  51. ) {
  52. var width = viewport.width;
  53. var height = viewport.height;
  54. if (
  55. !defined(this._framebuffer) ||
  56. width !== this._depthStencilTexture.width ||
  57. height !== this._depthStencilTexture.height
  58. ) {
  59. destroyResources(this);
  60. createResources(this, context);
  61. }
  62. var framebuffer = this._framebuffer;
  63. var passState = this._passState;
  64. passState.framebuffer = framebuffer;
  65. passState.viewport.width = width;
  66. passState.viewport.height = height;
  67. passState.scissorTest.rectangle.x = drawingBufferPosition.x;
  68. passState.scissorTest.rectangle.y = height - drawingBufferPosition.y;
  69. passState.scissorTest.rectangle.width = 1;
  70. passState.scissorTest.rectangle.height = 1;
  71. return passState;
  72. };
  73. PickDepthFramebuffer.prototype.isDestroyed = function () {
  74. return false;
  75. };
  76. PickDepthFramebuffer.prototype.destroy = function () {
  77. destroyResources(this);
  78. return destroyObject(this);
  79. };
  80. export default PickDepthFramebuffer;