智慧水务管理系统 - 精河县供水工程综合管理平台

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import Check from "../Core/Check.js";
  2. import Frozen from "../Core/Frozen.js";
  3. import defined from "../Core/defined.js";
  4. import destroyObject from "../Core/destroyObject.js";
  5. import DeveloperError from "../Core/DeveloperError.js";
  6. import ContextLimits from "./ContextLimits.js";
  7. import RenderbufferFormat from "./RenderbufferFormat.js";
  8. /**
  9. * @private
  10. */
  11. function Renderbuffer(options) {
  12. options = options ?? Frozen.EMPTY_OBJECT;
  13. //>>includeStart('debug', pragmas.debug);
  14. Check.defined("options.context", options.context);
  15. //>>includeEnd('debug');
  16. const context = options.context;
  17. const gl = context._gl;
  18. const maximumRenderbufferSize = ContextLimits.maximumRenderbufferSize;
  19. const format = options.format ?? RenderbufferFormat.RGBA4;
  20. const width = defined(options.width)
  21. ? options.width
  22. : context.drawingBufferWidth;
  23. const height = defined(options.height)
  24. ? options.height
  25. : context.drawingBufferHeight;
  26. const numSamples = options.numSamples ?? 1;
  27. //>>includeStart('debug', pragmas.debug);
  28. if (!RenderbufferFormat.validate(format)) {
  29. throw new DeveloperError("Invalid format.");
  30. }
  31. Check.typeOf.number.greaterThan("width", width, 0);
  32. if (width > maximumRenderbufferSize) {
  33. throw new DeveloperError(
  34. `Width must be less than or equal to the maximum renderbuffer size (${maximumRenderbufferSize}). Check maximumRenderbufferSize.`,
  35. );
  36. }
  37. Check.typeOf.number.greaterThan("height", height, 0);
  38. if (height > maximumRenderbufferSize) {
  39. throw new DeveloperError(
  40. `Height must be less than or equal to the maximum renderbuffer size (${maximumRenderbufferSize}). Check maximumRenderbufferSize.`,
  41. );
  42. }
  43. //>>includeEnd('debug');
  44. this._gl = gl;
  45. this._format = format;
  46. this._width = width;
  47. this._height = height;
  48. this._renderbuffer = this._gl.createRenderbuffer();
  49. gl.bindRenderbuffer(gl.RENDERBUFFER, this._renderbuffer);
  50. if (numSamples > 1) {
  51. gl.renderbufferStorageMultisample(
  52. gl.RENDERBUFFER,
  53. numSamples,
  54. format,
  55. width,
  56. height,
  57. );
  58. } else {
  59. gl.renderbufferStorage(gl.RENDERBUFFER, format, width, height);
  60. }
  61. gl.bindRenderbuffer(gl.RENDERBUFFER, null);
  62. }
  63. Object.defineProperties(Renderbuffer.prototype, {
  64. format: {
  65. get: function () {
  66. return this._format;
  67. },
  68. },
  69. width: {
  70. get: function () {
  71. return this._width;
  72. },
  73. },
  74. height: {
  75. get: function () {
  76. return this._height;
  77. },
  78. },
  79. });
  80. Renderbuffer.prototype._getRenderbuffer = function () {
  81. return this._renderbuffer;
  82. };
  83. Renderbuffer.prototype.isDestroyed = function () {
  84. return false;
  85. };
  86. Renderbuffer.prototype.destroy = function () {
  87. this._gl.deleteRenderbuffer(this._renderbuffer);
  88. return destroyObject(this);
  89. };
  90. export default Renderbuffer;