textureSampler.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Class used to store a texture sampler data
  3. */
  4. export class TextureSampler {
  5. /**
  6. * | Value | Type | Description |
  7. * | ----- | ------------------ | ----------- |
  8. * | 0 | CLAMP_ADDRESSMODE | |
  9. * | 1 | WRAP_ADDRESSMODE | |
  10. * | 2 | MIRROR_ADDRESSMODE | |
  11. */
  12. get wrapU() {
  13. return this._cachedWrapU;
  14. }
  15. set wrapU(value) {
  16. this._cachedWrapU = value;
  17. }
  18. /**
  19. * | Value | Type | Description |
  20. * | ----- | ------------------ | ----------- |
  21. * | 0 | CLAMP_ADDRESSMODE | |
  22. * | 1 | WRAP_ADDRESSMODE | |
  23. * | 2 | MIRROR_ADDRESSMODE | |
  24. */
  25. get wrapV() {
  26. return this._cachedWrapV;
  27. }
  28. set wrapV(value) {
  29. this._cachedWrapV = value;
  30. }
  31. /**
  32. * | Value | Type | Description |
  33. * | ----- | ------------------ | ----------- |
  34. * | 0 | CLAMP_ADDRESSMODE | |
  35. * | 1 | WRAP_ADDRESSMODE | |
  36. * | 2 | MIRROR_ADDRESSMODE | |
  37. */
  38. get wrapR() {
  39. return this._cachedWrapR;
  40. }
  41. set wrapR(value) {
  42. this._cachedWrapR = value;
  43. }
  44. /**
  45. * With compliant hardware and browser (supporting anisotropic filtering)
  46. * this defines the level of anisotropic filtering in the texture.
  47. * The higher the better but the slower.
  48. */
  49. get anisotropicFilteringLevel() {
  50. return this._cachedAnisotropicFilteringLevel;
  51. }
  52. set anisotropicFilteringLevel(value) {
  53. this._cachedAnisotropicFilteringLevel = value;
  54. }
  55. /**
  56. * Gets or sets the comparison function (513, 514, etc). Set 0 to not use a comparison function
  57. */
  58. get comparisonFunction() {
  59. return this._comparisonFunction;
  60. }
  61. set comparisonFunction(value) {
  62. this._comparisonFunction = value;
  63. }
  64. /**
  65. * Indicates to use the mip maps (if available on the texture).
  66. * Thanks to this flag, you can instruct the sampler to not sample the mipmaps even if they exist (and if the sampling mode is set to a value that normally samples the mipmaps!)
  67. */
  68. get useMipMaps() {
  69. return this._useMipMaps;
  70. }
  71. set useMipMaps(value) {
  72. this._useMipMaps = value;
  73. }
  74. /**
  75. * Creates a Sampler instance
  76. */
  77. constructor() {
  78. /**
  79. * Gets the sampling mode of the texture
  80. */
  81. this.samplingMode = -1;
  82. this._useMipMaps = true;
  83. /** @internal */
  84. this._cachedWrapU = null;
  85. /** @internal */
  86. this._cachedWrapV = null;
  87. /** @internal */
  88. this._cachedWrapR = null;
  89. /** @internal */
  90. this._cachedAnisotropicFilteringLevel = null;
  91. /** @internal */
  92. this._comparisonFunction = 0;
  93. }
  94. /**
  95. * Sets all the parameters of the sampler
  96. * @param wrapU u address mode (default: TEXTURE_WRAP_ADDRESSMODE)
  97. * @param wrapV v address mode (default: TEXTURE_WRAP_ADDRESSMODE)
  98. * @param wrapR r address mode (default: TEXTURE_WRAP_ADDRESSMODE)
  99. * @param anisotropicFilteringLevel anisotropic level (default: 1)
  100. * @param samplingMode sampling mode (default: 2)
  101. * @param comparisonFunction comparison function (default: 0 - no comparison function)
  102. * @returns the current sampler instance
  103. */
  104. setParameters(wrapU = 1, wrapV = 1, wrapR = 1, anisotropicFilteringLevel = 1, samplingMode = 2, comparisonFunction = 0) {
  105. this._cachedWrapU = wrapU;
  106. this._cachedWrapV = wrapV;
  107. this._cachedWrapR = wrapR;
  108. this._cachedAnisotropicFilteringLevel = anisotropicFilteringLevel;
  109. this.samplingMode = samplingMode;
  110. this._comparisonFunction = comparisonFunction;
  111. return this;
  112. }
  113. /**
  114. * Compares this sampler with another one
  115. * @param other sampler to compare with
  116. * @returns true if the samplers have the same parametres, else false
  117. */
  118. compareSampler(other) {
  119. return (this._cachedWrapU === other._cachedWrapU &&
  120. this._cachedWrapV === other._cachedWrapV &&
  121. this._cachedWrapR === other._cachedWrapR &&
  122. this._cachedAnisotropicFilteringLevel === other._cachedAnisotropicFilteringLevel &&
  123. this.samplingMode === other.samplingMode &&
  124. this._comparisonFunction === other._comparisonFunction &&
  125. this._useMipMaps === other._useMipMaps);
  126. }
  127. }
  128. //# sourceMappingURL=textureSampler.js.map