Files
cocos4/cocos/renderer/core/sampler-lib.ts
T
Weiliang Wang c703443e67 3d stable (#4041)
* 3d (#4036)

* compiler error (#4033)

* add gen decl module

* fix global event and other bug (#4032)

* components such as event-target to ts

* divide CCEvent and CCTouch into game coordinates and ui coordinate mod

* repair editor environment where mask does not take effect bug

* fix render component blendState modification does not take effect bug

* fix bug

* fix ts tip

* sampler from texture (#4037)
2019-03-14 16:05:22 +08:00

36 lines
1.2 KiB
TypeScript

// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
import { GFXDevice } from '../../gfx/device';
import { GFXSampler, IGFXSamplerInfo } from '../../gfx/sampler';
const gfxInfo: IGFXSamplerInfo = {};
class SamplerLib {
protected _cache: Record<string, GFXSampler> = {};
public getSampler (device: GFXDevice, info: number[]) {
const hash = info.toString();
const cache = this._cache[hash];
if (cache) { return cache; }
gfxInfo.minFilter = info[0];
gfxInfo.magFilter = info[1];
gfxInfo.mipFilter = info[2];
gfxInfo.addressU = info[3];
gfxInfo.addressV = info[4];
gfxInfo.addressW = info[5];
gfxInfo.maxAnisotropy = info[6];
if (info.length > 7) {
gfxInfo.cmpFunc = info[7];
gfxInfo.borderColor = { r: info[8], g: info[9], b: info[10], a: info[11] };
gfxInfo.minLOD = info[12];
gfxInfo.maxLOD = info[13];
gfxInfo.mipLODBias = info[14];
}
const sampler = this._cache[hash] = device.createSampler(gfxInfo);
return sampler;
}
}
export const samplerLib = new SamplerLib();
cc.samplerLib = samplerLib;