Sampler.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import Check from "../Core/Check.js";
  2. import defaultValue from "../Core/defaultValue.js";
  3. import defined from "../Core/defined.js";
  4. import DeveloperError from "../Core/DeveloperError.js";
  5. import TextureMagnificationFilter from "./TextureMagnificationFilter.js";
  6. import TextureMinificationFilter from "./TextureMinificationFilter.js";
  7. import TextureWrap from "./TextureWrap.js";
  8. /**
  9. * @private
  10. */
  11. function Sampler(options) {
  12. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  13. const wrapS = defaultValue(options.wrapS, TextureWrap.CLAMP_TO_EDGE);
  14. const wrapT = defaultValue(options.wrapT, TextureWrap.CLAMP_TO_EDGE);
  15. const minificationFilter = defaultValue(
  16. options.minificationFilter,
  17. TextureMinificationFilter.LINEAR
  18. );
  19. const magnificationFilter = defaultValue(
  20. options.magnificationFilter,
  21. TextureMagnificationFilter.LINEAR
  22. );
  23. const maximumAnisotropy = defined(options.maximumAnisotropy)
  24. ? options.maximumAnisotropy
  25. : 1.0;
  26. //>>includeStart('debug', pragmas.debug);
  27. if (!TextureWrap.validate(wrapS)) {
  28. throw new DeveloperError("Invalid sampler.wrapS.");
  29. }
  30. if (!TextureWrap.validate(wrapT)) {
  31. throw new DeveloperError("Invalid sampler.wrapT.");
  32. }
  33. if (!TextureMinificationFilter.validate(minificationFilter)) {
  34. throw new DeveloperError("Invalid sampler.minificationFilter.");
  35. }
  36. if (!TextureMagnificationFilter.validate(magnificationFilter)) {
  37. throw new DeveloperError("Invalid sampler.magnificationFilter.");
  38. }
  39. Check.typeOf.number.greaterThanOrEquals(
  40. "maximumAnisotropy",
  41. maximumAnisotropy,
  42. 1.0
  43. );
  44. //>>includeEnd('debug');
  45. this._wrapS = wrapS;
  46. this._wrapT = wrapT;
  47. this._minificationFilter = minificationFilter;
  48. this._magnificationFilter = magnificationFilter;
  49. this._maximumAnisotropy = maximumAnisotropy;
  50. }
  51. Object.defineProperties(Sampler.prototype, {
  52. wrapS: {
  53. get: function () {
  54. return this._wrapS;
  55. },
  56. },
  57. wrapT: {
  58. get: function () {
  59. return this._wrapT;
  60. },
  61. },
  62. minificationFilter: {
  63. get: function () {
  64. return this._minificationFilter;
  65. },
  66. },
  67. magnificationFilter: {
  68. get: function () {
  69. return this._magnificationFilter;
  70. },
  71. },
  72. maximumAnisotropy: {
  73. get: function () {
  74. return this._maximumAnisotropy;
  75. },
  76. },
  77. });
  78. Sampler.equals = function (left, right) {
  79. return (
  80. left === right ||
  81. (defined(left) &&
  82. defined(right) &&
  83. left._wrapS === right._wrapS &&
  84. left._wrapT === right._wrapT &&
  85. left._minificationFilter === right._minificationFilter &&
  86. left._magnificationFilter === right._magnificationFilter &&
  87. left._maximumAnisotropy === right._maximumAnisotropy)
  88. );
  89. };
  90. Sampler.NEAREST = Object.freeze(
  91. new Sampler({
  92. wrapS: TextureWrap.CLAMP_TO_EDGE,
  93. wrapT: TextureWrap.CLAMP_TO_EDGE,
  94. minificationFilter: TextureMinificationFilter.NEAREST,
  95. magnificationFilter: TextureMagnificationFilter.NEAREST,
  96. })
  97. );
  98. export default Sampler;