PickDepthFramebuffer.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 = pickDepth._framebuffer && pickDepth._framebuffer.destroy();
  19. pickDepth._depthStencilTexture = pickDepth._depthStencilTexture && pickDepth._depthStencilTexture.destroy();
  20. }
  21. function createResources(pickDepth, context) {
  22. var width = context.drawingBufferWidth;
  23. var height = context.drawingBufferHeight;
  24. pickDepth._depthStencilTexture = new Texture({
  25. context : context,
  26. width : width,
  27. height : height,
  28. pixelFormat : PixelFormat.DEPTH_STENCIL,
  29. pixelDatatype : PixelDatatype.UNSIGNED_INT_24_8
  30. });
  31. pickDepth._framebuffer = new Framebuffer({
  32. context : context,
  33. depthStencilTexture : pickDepth._depthStencilTexture,
  34. destroyAttachments : false
  35. });
  36. var passState = new PassState(context);
  37. passState.blendingEnabled = false;
  38. passState.scissorTest = {
  39. enabled : true,
  40. rectangle : new BoundingRectangle()
  41. };
  42. passState.viewport = new BoundingRectangle();
  43. pickDepth._passState = passState;
  44. }
  45. PickDepthFramebuffer.prototype.update = function(context, drawingBufferPosition, viewport) {
  46. var width = viewport.width;
  47. var height = viewport.height;
  48. if (!defined(this._framebuffer) || width !== this._depthStencilTexture.width || height !== this._depthStencilTexture.height) {
  49. destroyResources(this);
  50. createResources(this, context);
  51. }
  52. var framebuffer = this._framebuffer;
  53. var passState = this._passState;
  54. passState.framebuffer = framebuffer;
  55. passState.viewport.width = width;
  56. passState.viewport.height = height;
  57. passState.scissorTest.rectangle.x = drawingBufferPosition.x;
  58. passState.scissorTest.rectangle.y = height - drawingBufferPosition.y;
  59. passState.scissorTest.rectangle.width = 1;
  60. passState.scissorTest.rectangle.height = 1;
  61. return passState;
  62. };
  63. PickDepthFramebuffer.prototype.isDestroyed = function() {
  64. return false;
  65. };
  66. PickDepthFramebuffer.prototype.destroy = function() {
  67. destroyResources(this);
  68. return destroyObject(this);
  69. };
  70. export default PickDepthFramebuffer;