All files / engine/Source/Renderer Sampler.js

100% Statements 29/29
100% Branches 27/27
100% Functions 8/8
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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