webGLHardwareTexture.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /** @internal */
  2. export class WebGLHardwareTexture {
  3. get underlyingResource() {
  4. return this._webGLTexture;
  5. }
  6. constructor(existingTexture = null, context) {
  7. // There can be multiple buffers for a single WebGL texture because different layers of a 2DArrayTexture / 3DTexture
  8. // or different faces of a cube texture can be bound to different render targets at the same time.
  9. // eslint-disable-next-line @typescript-eslint/naming-convention
  10. this._MSAARenderBuffers = null;
  11. this._context = context;
  12. if (!existingTexture) {
  13. existingTexture = context.createTexture();
  14. if (!existingTexture) {
  15. throw new Error("Unable to create webGL texture");
  16. }
  17. }
  18. this.set(existingTexture);
  19. }
  20. setUsage() { }
  21. set(hardwareTexture) {
  22. this._webGLTexture = hardwareTexture;
  23. }
  24. reset() {
  25. this._webGLTexture = null;
  26. this._MSAARenderBuffers = null;
  27. }
  28. addMSAARenderBuffer(buffer) {
  29. if (!this._MSAARenderBuffers) {
  30. this._MSAARenderBuffers = [];
  31. }
  32. this._MSAARenderBuffers.push(buffer);
  33. }
  34. releaseMSAARenderBuffers() {
  35. if (this._MSAARenderBuffers) {
  36. for (const buffer of this._MSAARenderBuffers) {
  37. this._context.deleteRenderbuffer(buffer);
  38. }
  39. this._MSAARenderBuffers = null;
  40. }
  41. }
  42. getMSAARenderBuffer(index = 0) {
  43. return this._MSAARenderBuffers?.[index] ?? null;
  44. }
  45. release() {
  46. this.releaseMSAARenderBuffers();
  47. if (this._webGLTexture) {
  48. this._context.deleteTexture(this._webGLTexture);
  49. }
  50. this.reset();
  51. }
  52. }
  53. //# sourceMappingURL=webGLHardwareTexture.js.map