partial handle & Pass.getUniform (#5356)

* linter fix

* partial handle & getUniform
This commit is contained in:
Yun Hsiao Wu
2019-09-10 10:35:02 +08:00
committed by Weiliang Wang
parent 2a8d52f3ab
commit ea923922ba
35 changed files with 451 additions and 344 deletions
+2 -1
View File
@@ -8,7 +8,8 @@ declare namespace wx {
const onTouchMove: IWXEventManager<TouchEvent>;
const onTouchEnd: IWXEventManager<TouchEvent>;
const onTouchCancel: IWXEventManager<TouchEvent>;
function getSystemInfoSync(): any;
function getSystemInfoSync(): any;
function createInnerAudioContext(): InnerAudioContext;
class FileSystemManager {
+1 -1
View File
@@ -27,9 +27,9 @@
* @category component/audio
*/
import { director, Director } from '../../core';
import sys from '../../core/platform/sys';
import { AudioPlayer, IAudioInfo, PlayingState } from './player';
import { director, Director } from '../../core';
const audioSupport = sys.__audioSupport;
+39 -35
View File
@@ -27,74 +27,78 @@
* @category loader
*/
import sys from '../core/platform/sys';
import { log, getError } from '../core/platform/debug';
import { AudioClip, AudioType } from './assets/clip';
import { loader } from '../core/load-pipeline';
import { getError, log } from '../core/platform/debug';
import sys from '../core/platform/sys';
import { AudioClip, AudioType } from './assets/clip';
const __audioSupport = sys.__audioSupport;
const formatSupport = __audioSupport.format;
function loadWXAudio (item, callback) {
var clip = wx.createInnerAudioContext();
const clip = wx.createInnerAudioContext();
clip.src = item.url;
clip.onCanplay(() => callback(null, clip));
}
function loadDomAudio (item, callback) {
var dom = document.createElement('audio');
const dom = document.createElement('audio');
dom.src = item.url;
var clearEvent = function () {
const clearEvent = () => {
clearTimeout(timer);
dom.removeEventListener("canplaythrough", success, false);
dom.removeEventListener("error", failure, false);
if(__audioSupport.USE_LOADER_EVENT)
dom.removeEventListener('canplaythrough', success, false);
dom.removeEventListener('error', failure, false);
if (__audioSupport.USE_LOADER_EVENT) {
dom.removeEventListener(__audioSupport.USE_LOADER_EVENT, success, false);
}
};
var timer = setTimeout(function () {
if (dom.readyState === 0)
const timer = setTimeout(() => {
if (dom.readyState === 0) {
failure();
else
} else {
success();
}
}, 8000);
var success = function () {
const success = () => {
clearEvent();
callback(null, dom);
};
var failure = function () {
const failure = () => {
clearEvent();
var message = 'load audio failure - ' + item.url;
const message = 'load audio failure - ' + item.url;
log(message);
callback(message);
};
dom.addEventListener("canplaythrough", success, false);
dom.addEventListener("error", failure, false);
if(__audioSupport.USE_LOADER_EVENT)
dom.addEventListener('canplaythrough', success, false);
dom.addEventListener('error', failure, false);
if (__audioSupport.USE_LOADER_EVENT) {
dom.addEventListener(__audioSupport.USE_LOADER_EVENT, success, false);
}
}
function loadWebAudio (item, callback) {
const context = __audioSupport.context;
if (!context)
if (!context) {
callback(new Error(getError(4926)));
}
var request = loader.getXMLHttpRequest();
request.open("GET", item.url, true);
request.responseType = "arraybuffer";
const request = loader.getXMLHttpRequest();
request.open('GET', item.url, true);
request.responseType = 'arraybuffer';
// Our asynchronous callback
request.onload = function () {
context["decodeAudioData"](request.response, function(buffer){
//success
request.onload = () => {
context.decodeAudioData(request.response, (buffer) => {
// success
callback(null, buffer);
}, function(){
//error
}, () => {
// error
callback('decode error - ' + item.id, null);
});
};
request.onerror = function(){
request.onerror = () => {
callback('request error - ' + item.id, null);
};
@@ -112,11 +116,11 @@ function downloadAudio (item, callback) {
} else if (!__audioSupport.WEB_AUDIO) {
audioLoader = loadDomAudio; // If WebAudio is not supported, load using DOM mode
} else {
let loadByDeserializedAudio = item._owner instanceof AudioClip;
const loadByDeserializedAudio = item._owner instanceof AudioClip;
if (loadByDeserializedAudio) {
audioLoader = (item._owner.loadMode === AudioType.WEB_AUDIO) ? loadWebAudio : loadDomAudio;
} else {
audioLoader = (item.urlParam && item.urlParam['useDom']) ? loadDomAudio : loadWebAudio;
audioLoader = (item.urlParam && item.urlParam.useDom) ? loadDomAudio : loadWebAudio;
}
}
audioLoader(item, callback);
@@ -124,8 +128,8 @@ function downloadAudio (item, callback) {
loader.downloader.addHandlers({
// Audio
'mp3' : downloadAudio,
'ogg' : downloadAudio,
'wav' : downloadAudio,
'm4a' : downloadAudio,
});
mp3 : downloadAudio,
ogg : downloadAudio,
wav : downloadAudio,
m4a : downloadAudio,
});
-15
View File
@@ -44,7 +44,6 @@ class BuiltinResMgr {
top: new ImageAsset(canvas),
bottom: new ImageAsset(canvas),
};
blackCubeTexture.onLoaded();
resources[blackCubeTexture._uuid] = blackCubeTexture;
// grey texture
@@ -53,7 +52,6 @@ class BuiltinResMgr {
const greyTexture = new Texture2D();
greyTexture._uuid = 'grey-texture';
greyTexture.image = imgAsset;
greyTexture.onLoaded();
resources[greyTexture._uuid] = greyTexture;
// white texture
@@ -62,7 +60,6 @@ class BuiltinResMgr {
const whiteTexture = new Texture2D();
whiteTexture._uuid = 'white-texture';
whiteTexture.image = imgAsset;
whiteTexture.onLoaded();
resources[whiteTexture._uuid] = whiteTexture;
// white cube texture
@@ -77,7 +74,6 @@ class BuiltinResMgr {
top: new ImageAsset(canvas),
bottom: new ImageAsset(canvas),
};
whiteCubeTexture.onLoaded();
resources[whiteCubeTexture._uuid] = whiteCubeTexture;
// normal texture
@@ -99,7 +95,6 @@ class BuiltinResMgr {
const defaultTexture = new Texture2D();
defaultTexture._uuid = 'default-texture';
defaultTexture.image = imgAsset;
defaultTexture.onLoaded();
resources[defaultTexture._uuid] = defaultTexture;
// default cube texture
@@ -114,7 +109,6 @@ class BuiltinResMgr {
top: new ImageAsset(canvas),
bottom: new ImageAsset(canvas),
};
defaultCubeTexture.onLoaded();
resources[defaultCubeTexture._uuid] = defaultCubeTexture;
const spriteFrame = new SpriteFrame();
@@ -135,7 +129,6 @@ class BuiltinResMgr {
standardMtl.initialize({
effectName: 'builtin-standard',
});
standardMtl.onLoaded();
resources[standardMtl._uuid] = standardMtl;
// material indicating missing material (purple)
@@ -146,7 +139,6 @@ class BuiltinResMgr {
defines: { USE_COLOR: true },
});
missingMtl.setProperty('color', cc.color('#ff00ff'));
missingMtl.onLoaded();
resources[missingMtl._uuid] = missingMtl;
// material indicating missing material on skinning model (purple)
@@ -158,7 +150,6 @@ class BuiltinResMgr {
defines: { USE_COLOR: true, CC_USE_SKINNING: type },
});
missingSkinningMtl.setProperty('color', cc.color('#ff00ff'));
missingSkinningMtl.onLoaded();
resources[missingSkinningMtl._uuid] = missingSkinningMtl;
// material indicating missing effect (yellow)
@@ -169,42 +160,36 @@ class BuiltinResMgr {
defines: { USE_COLOR: true },
});
missingEfxMtl.setProperty('color', cc.color('#ffff00'));
missingEfxMtl.onLoaded();
resources[missingEfxMtl._uuid] = missingEfxMtl;
// sprite material
const spriteMtl = new cc.Material();
spriteMtl._uuid = 'ui-base-material';
spriteMtl.initialize({ defines: { USE_TEXTURE: false }, effectName: 'builtin-sprite' });
spriteMtl.onLoaded();
resources[spriteMtl._uuid] = spriteMtl;
// sprite material
const spriteColorMtl = new cc.Material();
spriteColorMtl._uuid = 'ui-sprite-material';
spriteColorMtl.initialize({ defines: { USE_TEXTURE: true }, effectName: 'builtin-sprite' });
spriteColorMtl.onLoaded();
resources[spriteColorMtl._uuid] = spriteColorMtl;
// default particle material
const defaultParticleMtl = new cc.Material();
defaultParticleMtl._uuid = 'default-particle-material';
defaultParticleMtl.initialize({ effectName: 'builtin-particle' });
defaultParticleMtl.onLoaded();
resources[defaultParticleMtl._uuid] = defaultParticleMtl;
// default particle material
const defaultTrailMtl = new cc.Material();
defaultTrailMtl._uuid = 'default-trail-material';
defaultTrailMtl.initialize({ effectName: 'builtin-particle-trail' });
defaultTrailMtl.onLoaded();
resources[defaultTrailMtl._uuid] = defaultTrailMtl;
// default particle material
const defaultBillboardMtl = new cc.Material();
defaultBillboardMtl._uuid = 'default-billboard-material';
defaultBillboardMtl.initialize({ effectName: 'builtin-billboard' });
defaultBillboardMtl.onLoaded();
resources[defaultBillboardMtl._uuid] = defaultBillboardMtl;
}
@@ -27,19 +27,19 @@
*/
import { Filter, PixelFormat } from '../../assets/asset-enum';
import { Mesh } from '../../assets/mesh';
import { Skeleton } from '../../assets/skeleton';
import { Texture2D } from '../../assets/texture-2d';
import { ccclass, executeInEditMode, executionOrder, property } from '../../data/class-decorator';
import { CCInteger, CCString } from '../../data/utils/attribute';
import { Mat4, Vec2 } from '../../math';
import { GFXFormat } from '../../gfx/define';
import { GFXAttributeName, GFXBufferTextureCopy, GFXFormatInfos } from '../../gfx/define';
import { GFXDevice } from '../../gfx/device';
import { Mesh } from '../../assets/mesh';
import { Skeleton } from '../../assets/skeleton';
import { Mat4, Vec2 } from '../../math';
import { Node } from '../../scene-graph/node';
import { INode } from '../../utils/interfaces';
import { LCA, mapBuffer } from '../misc/utils';
import { SkinningModelComponent } from './skinning-model-component';
import { INode } from '../../utils/interfaces';
import { Node } from '../../scene-graph/node';
const _vec2 = new Vec2();
@@ -50,7 +50,7 @@ export class SkeletalAnimationState extends AnimationState {
public onPlay () {
super.onPlay();
let comps = this._targetNode!.getComponentsInChildren(SkinningModelComponent);
const comps = this._targetNode!.getComponentsInChildren(SkinningModelComponent);
for (let i = 0; i < comps.length; ++i) {
const comp = comps[i] as SkinningModelComponent;
if (comp.skinningRoot === this._targetNode) {
+1 -1
View File
@@ -173,7 +173,7 @@ export class Material extends Asset {
else if (info.effectName) { this._effectAsset = EffectAsset.get(info.effectName); }
if (info.defines) { this._prepareInfo(info.defines, this._defines); }
if (info.states) { this._prepareInfo(info.states, this._states); }
this._update();
this.onLoaded();
}
public initialize (info: IMaterialInfo) {
this.reset(info);
+1 -1
View File
@@ -3,8 +3,8 @@
*/
import CCClass from '../../core/data/class';
import { Enum } from '../../core/value-types/enum';
import { clamp, inverseLerp, pingPong, repeat } from '../../core/math/utils';
import { Enum } from '../../core/value-types/enum';
const LOOK_FORWARD = 3;
+6 -7
View File
@@ -5,14 +5,13 @@
import { replaceProperty } from '../utils/deprecated';
import line from './line';
replaceProperty(line.prototype, 'line', [
{
'name': 'mag',
'newName': 'len'
name: 'mag',
newName: 'len',
},
{
'name': 'magnitude',
'newName': 'len'
}
]);
name: 'magnitude',
newName: 'len',
},
]);
+1 -1
View File
@@ -3,9 +3,9 @@
*/
import { Vec3 } from '../math';
import plane from './plane';
import aabb from './aabb';
import obb from './obb';
import plane from './plane';
const X = new Vec3();
const Y = new Vec3();
const Z = new Vec3();
+1 -1
View File
@@ -17,4 +17,4 @@ export { frustum } from './frustum';
export { default as Octree } from './octree';
export { Keyframe, AnimationCurve } from './curve';
import './deprecated';
import './deprecated';
+36 -36
View File
@@ -981,46 +981,46 @@ export function GFXFormatSurfaceSize (
return size;
}
const _type2size = [
0, // UNKNOWN
4, // BOOL
8, // BOOL2
12, // BOOL3
16, // BOOL4
4, // INT
8, // INT2
12, // INT3
16, // INT4
4, // UINT
8, // UINT2
12, // UINT3
16, // UINT4
4, // FLOAT
8, // FLOAT2
12, // FLOAT3
16, // FLOAT4
16, // MAT2
24, // MAT2X3
32, // MAT2X4
24, // MAT3X2
36, // MAT3
48, // MAT3X4
32, // MAT4X2
48, // MAT4X3
64, // MAT4
4, // SAMPLER1D
4, // SAMPLER1D_ARRAY
4, // SAMPLER2D
4, // SAMPLER2D_ARRAY
4, // SAMPLER3D
4, // SAMPLER_CUBE
];
/**
* @zh
* 得到GFX数据类型的大小。
* @param type GFX数据类型。
*/
export function GFXGetTypeSize (type: GFXType): number {
switch (type) {
case GFXType.BOOL:
case GFXType.INT:
case GFXType.UINT:
case GFXType.FLOAT: return 4;
case GFXType.BOOL2:
case GFXType.INT2:
case GFXType.UINT2:
case GFXType.FLOAT2: return 8;
case GFXType.BOOL3:
case GFXType.INT3:
case GFXType.UINT3:
case GFXType.FLOAT3: return 12;
case GFXType.BOOL4:
case GFXType.INT4:
case GFXType.UINT4:
case GFXType.FLOAT4:
case GFXType.MAT2: return 16;
case GFXType.MAT2X3: return 24;
case GFXType.MAT2X4: return 32;
case GFXType.MAT3X2: return 24;
case GFXType.MAT3: return 36;
case GFXType.MAT3X4: return 48;
case GFXType.MAT4X2: return 32;
case GFXType.MAT4X2: return 32;
case GFXType.MAT4: return 64;
case GFXType.SAMPLER1D:
case GFXType.SAMPLER1D_ARRAY:
case GFXType.SAMPLER2D:
case GFXType.SAMPLER2D_ARRAY:
case GFXType.SAMPLER3D:
case GFXType.SAMPLER_CUBE: return 4;
default: {
return 0;
}
}
return _type2size[type] || 0;
}
+21 -44
View File
@@ -179,13 +179,24 @@ export class Color extends ValueType {
* @zh 颜色转数组
* @param ofs 数组起始偏移量
*/
public static array <Out extends IColorLike> (out: IWritableArrayLike<number>, a: Out, ofs = 0) {
public static toArray <Out extends IColorLike> (out: IWritableArrayLike<number>, a: Out, ofs = 0) {
const scale = (a instanceof Color || a.a > 1) ? 1 / 255 : 1;
out[ofs + 0] = a.r * scale;
out[ofs + 1] = a.g * scale;
out[ofs + 2] = a.b * scale;
out[ofs + 3] = a.a * scale;
return out;
}
/**
* @zh 数组转颜色
* @param ofs 数组起始偏移量
*/
public static fromArray <Out extends IColorLike> (arr: IWritableArrayLike<number>, out: Out, ofs = 0) {
out.r = arr[ofs + 0] * 255;
out.g = arr[ofs + 1] * 255;
out.b = arr[ofs + 2] * 255;
out.a = arr[ofs + 3] * 255;
return out;
}
@@ -261,49 +272,15 @@ export class Color extends ValueType {
this._val = ((this._val & 0x00ffffff) | ((alpha << 24) >>> 0)) >>> 0;
}
/**
* 通过除以 255,将当前颜色的各个通道都视为范围 [0, 1] 内,设置 Red 通道的值。
*/
get x () {
return this.r * toFloat;
}
set x (value) {
this.r = value * 255;
}
/**
* 通过除以 255,将当前颜色的各个通道都视为范围 [0, 1] 内,设置 Green 通道的值。
*/
get y () {
return this.g * toFloat;
}
set y (value) {
this.g = value * 255;
}
/**
* 通过除以 255,将当前颜色的各个通道都视为范围 [0, 1] 内,设置 Blue 通道的值。
*/
get z () {
return this.b * toFloat;
}
set z (value) {
this.b = value * 255;
}
/**
* 通过除以 255,将当前颜色的各个通道都视为范围 [0, 1] 内,设置 Alpha 通道的值。
*/
get w () {
return this.a * toFloat;
}
set w (value) {
this.a = value * 255;
}
// compatibility with vector interfaces
get x () { return this.r * toFloat; }
set x (value) { this.r = value * 255; }
get y () { return this.g * toFloat; }
set y (value) { this.g = value * 255; }
get z () { return this.b * toFloat; }
set z (value) { this.b = value * 255; }
get w () { return this.a * toFloat; }
set w (value) { this.a = value * 255; }
public _val = 0;
+17 -1
View File
@@ -481,7 +481,7 @@ export class Mat3 extends ValueType {
* @zh 矩阵转数组
* @param ofs 数组内的起始偏移量
*/
public static array (out: IWritableArrayLike<number>, m: Mat3, ofs = 0) {
public static toArray <Out extends IMat3Like> (out: IWritableArrayLike<number>, m: Out, ofs = 0) {
out[ofs + 0] = m.m00;
out[ofs + 1] = m.m01;
out[ofs + 2] = m.m02;
@@ -491,7 +491,23 @@ export class Mat3 extends ValueType {
out[ofs + 6] = m.m06;
out[ofs + 7] = m.m07;
out[ofs + 8] = m.m08;
return out;
}
/**
* @zh 数组转矩阵
* @param ofs 数组起始偏移量
*/
public static fromArray <Out extends IMat3Like> (out: Out, arr: IWritableArrayLike<number>, ofs = 0) {
out.m00 = arr[ofs + 0];
out.m01 = arr[ofs + 1];
out.m02 = arr[ofs + 2];
out.m03 = arr[ofs + 3];
out.m04 = arr[ofs + 4];
out.m05 = arr[ofs + 5];
out.m06 = arr[ofs + 6];
out.m07 = arr[ofs + 7];
out.m08 = arr[ofs + 8];
return out;
}
+24 -1
View File
@@ -1164,7 +1164,7 @@ export class Mat4 extends ValueType {
* @zh 矩阵转数组
* @param ofs 数组内的起始偏移量
*/
public static array <Out extends IMat4Like> (out: IWritableArrayLike<number>, m: Out, ofs = 0) {
public static toArray <Out extends IMat4Like> (out: IWritableArrayLike<number>, m: Out, ofs = 0) {
out[ofs + 0] = m.m00;
out[ofs + 1] = m.m01;
out[ofs + 2] = m.m02;
@@ -1181,7 +1181,30 @@ export class Mat4 extends ValueType {
out[ofs + 13] = m.m13;
out[ofs + 14] = m.m14;
out[ofs + 15] = m.m15;
return out;
}
/**
* @zh 数组转矩阵
* @param ofs 数组起始偏移量
*/
public static fromArray <Out extends IMat4Like> (out: Out, arr: IWritableArrayLike<number>, ofs = 0) {
out.m00 = arr[ofs + 0];
out.m01 = arr[ofs + 1];
out.m02 = arr[ofs + 2];
out.m03 = arr[ofs + 3];
out.m04 = arr[ofs + 4];
out.m05 = arr[ofs + 5];
out.m06 = arr[ofs + 6];
out.m07 = arr[ofs + 7];
out.m08 = arr[ofs + 8];
out.m09 = arr[ofs + 9];
out.m10 = arr[ofs + 10];
out.m11 = arr[ofs + 11];
out.m12 = arr[ofs + 12];
out.m13 = arr[ofs + 13];
out.m14 = arr[ofs + 14];
out.m15 = arr[ofs + 15];
return out;
}
+12 -1
View File
@@ -577,12 +577,23 @@ export class Quat extends ValueType {
* @zh 四元数转数组
* @param ofs 数组内的起始偏移量
*/
public static array <Out extends IQuatLike> (out: IWritableArrayLike<number>, q: Out, ofs = 0) {
public static toArray <Out extends IQuatLike> (out: IWritableArrayLike<number>, q: Out, ofs = 0) {
out[ofs + 0] = q.x;
out[ofs + 1] = q.y;
out[ofs + 2] = q.z;
out[ofs + 3] = q.w;
return out;
}
/**
* @zh 数组转四元数
* @param ofs 数组起始偏移量
*/
public static fromArray <Out extends IQuatLike> (out: Out, arr: IWritableArrayLike<number>, ofs = 0) {
out.x = arr[ofs + 0];
out.y = arr[ofs + 1];
out.z = arr[ofs + 2];
out.w = arr[ofs + 3];
return out;
}
+89 -83
View File
@@ -46,89 +46,6 @@ let _h: number = 0.0;
* 矩形的宽度定义为 xMax - xMin;高度定义为 yMax - yMin。
*/
export class Rect extends ValueType {
/**
* 获取或设置矩形在 x 轴上的最小值。
*/
get xMin () {
return this.x;
}
set xMin (value) {
this.width += this.x - value;
this.x = value;
}
/**
* 获取或设置矩形在 y 轴上的最小值。
*/
get yMin () {
return this.y;
}
set yMin (value) {
this.height += this.y - value;
this.y = value;
}
/**
* 获取或设置矩形在 x 轴上的最大值。
*/
get xMax () {
return this.x + this.width;
}
set xMax (value) {
this.width = value - this.x;
}
/**
* 获取或设置矩形在 y 轴上的最大值。
*/
get yMax () {
return this.y + this.height;
}
set yMax (value) {
this.height = value - this.y;
}
/**
* 获取或设置矩形中心点的坐标。
*/
get center () {
return new Vec2(this.x + this.width * 0.5,
this.y + this.height * 0.5);
}
set center (value) {
this.x = value.x - this.width * 0.5;
this.y = value.y - this.height * 0.5;
}
/**
* 获取或设置矩形最小点的坐标。
*/
get origin () {
return new cc.Vec2(this.x, this.y);
}
set origin (value) {
this.x = value.x;
this.y = value.y;
}
/**
* 获取或设置矩形的尺寸。
*/
get size () {
return new Size(this.width, this.height);
}
set size (value) {
this.width = value.width;
this.height = value.height;
}
/**
* 由任意两个点创建一个矩形,目标矩形即是这两个点各向 x、y 轴作线所得到的矩形。
* @param v1 指定的点。
@@ -214,6 +131,95 @@ export class Rect extends ValueType {
return out;
}
/**
* 获取或设置矩形在 x 轴上的最小值。
*/
get xMin () {
return this.x;
}
set xMin (value) {
this.width += this.x - value;
this.x = value;
}
/**
* 获取或设置矩形在 y 轴上的最小值。
*/
get yMin () {
return this.y;
}
set yMin (value) {
this.height += this.y - value;
this.y = value;
}
/**
* 获取或设置矩形在 x 轴上的最大值。
*/
get xMax () {
return this.x + this.width;
}
set xMax (value) {
this.width = value - this.x;
}
/**
* 获取或设置矩形在 y 轴上的最大值。
*/
get yMax () {
return this.y + this.height;
}
set yMax (value) {
this.height = value - this.y;
}
/**
* 获取或设置矩形中心点的坐标。
*/
get center () {
return new Vec2(this.x + this.width * 0.5,
this.y + this.height * 0.5);
}
set center (value) {
this.x = value.x - this.width * 0.5;
this.y = value.y - this.height * 0.5;
}
/**
* 获取或设置矩形最小点的坐标。
*/
get origin () {
return new cc.Vec2(this.x, this.y);
}
set origin (value) {
this.x = value.x;
this.y = value.y;
}
/**
* 获取或设置矩形的尺寸。
*/
get size () {
return new Size(this.width, this.height);
}
set size (value) {
this.width = value.width;
this.height = value.height;
}
// compatibility with vector interfaces
set z (val) { this.width = val; }
get z () { return this.width; }
set w (val) { this.height = val; }
get w () { return this.height; }
/**
* 获取或设置矩形最小点的 x 坐标。
*/
+6
View File
@@ -58,6 +58,12 @@ export class Size extends ValueType {
return out;
}
// compatibility with vector interfaces
set x (val) { this.width = val; }
get x () { return this.width; }
set y (val) { this.height = val; }
get y () { return this.height; }
/**
* 宽度。
*/
+11 -1
View File
@@ -337,12 +337,22 @@ export class Vec2 extends ValueType {
* @zh 向量转数组
* @param ofs 数组起始偏移量
*/
public static array <Out extends IVec2Like> (out: IWritableArrayLike<number>, v: Out, ofs = 0) {
public static toArray <Out extends IVec2Like> (out: IWritableArrayLike<number>, v: Out, ofs = 0) {
out[ofs + 0] = v.x;
out[ofs + 1] = v.y;
return out;
}
/**
* @zh 数组转向量
* @param ofs 数组起始偏移量
*/
public static fromArray <Out extends IVec2Like> (out: Out, arr: IWritableArrayLike<number>, ofs = 0) {
out.x = arr[ofs + 0];
out.y = arr[ofs + 1];
return out;
}
/**
* @zh 向量等价判断
*/
+12 -1
View File
@@ -528,7 +528,7 @@ export class Vec3 extends ValueType {
* @zh 向量转数组
* @param ofs 数组起始偏移量
*/
public static array <Out extends IVec3Like> (out: IWritableArrayLike<number>, v: Out, ofs = 0) {
public static toArray <Out extends IVec3Like> (out: IWritableArrayLike<number>, v: Out, ofs = 0) {
out[ofs + 0] = v.x;
out[ofs + 1] = v.y;
out[ofs + 2] = v.z;
@@ -536,6 +536,17 @@ export class Vec3 extends ValueType {
return out;
}
/**
* @zh 数组转向量
* @param ofs 数组起始偏移量
*/
public static fromArray <Out extends IVec3Like> (out: Out, arr: IWritableArrayLike<number>, ofs = 0) {
out.x = arr[ofs + 0];
out.y = arr[ofs + 1];
out.z = arr[ofs + 2];
return out;
}
/**
* @zh 向量等价判断
*/
+13 -1
View File
@@ -415,7 +415,7 @@ export class Vec4 extends ValueType {
* @zh 向量转数组
* @param ofs 数组起始偏移量
*/
public static array <Out extends IVec4Like> (out: IWritableArrayLike<number>, v: Out, ofs = 0) {
public static toArray <Out extends IVec4Like> (out: IWritableArrayLike<number>, v: Out, ofs = 0) {
out[ofs + 0] = v.x;
out[ofs + 1] = v.y;
out[ofs + 2] = v.z;
@@ -423,6 +423,18 @@ export class Vec4 extends ValueType {
return out;
}
/**
* @zh 数组转向量
* @param ofs 数组起始偏移量
*/
public static fromArray <Out extends IVec4Like> (out: Out, arr: IWritableArrayLike<number>, ofs = 0) {
out.x = arr[ofs + 0];
out.y = arr[ofs + 1];
out.z = arr[ofs + 2];
out.w = arr[ofs + 3];
return out;
}
/**
* @zh 向量等价判断
*/
+3
View File
@@ -91,6 +91,9 @@ export enum UniformBinding {
CUSTOM_SAMPLER_BINDING_START_POINT = MAX_BINDING_SUPPORTED + 6,
}
export const isBuiltinBinding = (binding: number) =>
binding >= UniformBinding.CUSTUM_UBO_BINDING_END_POINT && binding < UniformBinding.CUSTOM_SAMPLER_BINDING_START_POINT;
/**
* @zh
* 全局 UBO。
@@ -213,7 +213,7 @@ export class ForwardPipeline extends RenderPipeline {
}
const sphereLit = light as SphereLight;
Vec3.array(_vec4Array, sphereLit.position);
Vec3.toArray(_vec4Array, sphereLit.position);
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPHERE_LIGHT_POS_OFFSET + sphereNum * 4);
_vec4Array[0] = sphereLit.size;
@@ -221,7 +221,7 @@ export class ForwardPipeline extends RenderPipeline {
_vec4Array[2] = 0.0;
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPHERE_LIGHT_SIZE_RANGE_OFFSET + sphereNum * 4);
Vec3.array(_vec4Array, light.color);
Vec3.toArray(_vec4Array, light.color);
if (light.useColorTemperature) {
const tempRGB = light.colorTemperatureRGB;
_vec4Array[0] *= tempRGB.x;
@@ -244,7 +244,7 @@ export class ForwardPipeline extends RenderPipeline {
const spotLit = light as SpotLight;
Vec3.array(_vec4Array, spotLit.position);
Vec3.toArray(_vec4Array, spotLit.position);
_vec4Array[3] = spotLit.size;
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPOT_LIGHT_POS_OFFSET + spotNum * 4);
@@ -253,10 +253,10 @@ export class ForwardPipeline extends RenderPipeline {
_vec4Array[2] = spotLit.spotAngle;
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPOT_LIGHT_SIZE_RANGE_ANGLE_OFFSET + spotNum * 4);
Vec3.array(_vec4Array, spotLit.direction);
Vec3.toArray(_vec4Array, spotLit.direction);
this._uboLights.view.set(_vec4Array, UBOForwardLight.SPOT_LIGHT_DIR_OFFSET + spotNum * 4);
Vec3.array(_vec4Array, light.color);
Vec3.toArray(_vec4Array, light.color);
if (light.useColorTemperature) {
const tempRGB = light.colorTemperatureRGB;
_vec4Array[0] *= tempRGB.x;
+10 -10
View File
@@ -1384,14 +1384,14 @@ export abstract class RenderPipeline {
fv[UBOGlobal.NATIVE_SIZE_OFFSET + 2] = 1.0 / fv[UBOGlobal.NATIVE_SIZE_OFFSET];
fv[UBOGlobal.NATIVE_SIZE_OFFSET + 3] = 1.0 / fv[UBOGlobal.NATIVE_SIZE_OFFSET + 1];
Mat4.array(fv, camera.matView, UBOGlobal.MAT_VIEW_OFFSET);
Mat4.toArray(fv, camera.matView, UBOGlobal.MAT_VIEW_OFFSET);
Mat4.array(fv, camera.node.worldMatrix, UBOGlobal.MAT_VIEW_INV_OFFSET);
Mat4.array(fv, camera.matProj, UBOGlobal.MAT_PROJ_OFFSET);
Mat4.array(fv, camera.matProjInv, UBOGlobal.MAT_PROJ_INV_OFFSET);
Mat4.array(fv, camera.matViewProj, UBOGlobal.MAT_VIEW_PROJ_OFFSET);
Mat4.array(fv, camera.matViewProjInv, UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET);
Vec3.array(fv, camera.position, UBOGlobal.CAMERA_POS_OFFSET);
Mat4.toArray(fv, camera.node.worldMatrix, UBOGlobal.MAT_VIEW_INV_OFFSET);
Mat4.toArray(fv, camera.matProj, UBOGlobal.MAT_PROJ_OFFSET);
Mat4.toArray(fv, camera.matProjInv, UBOGlobal.MAT_PROJ_INV_OFFSET);
Mat4.toArray(fv, camera.matViewProj, UBOGlobal.MAT_VIEW_PROJ_OFFSET);
Mat4.toArray(fv, camera.matViewProjInv, UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET);
Vec3.toArray(fv, camera.position, UBOGlobal.CAMERA_POS_OFFSET);
const exposure = camera.exposure;
fv[UBOGlobal.EXPOSURE_OFFSET] = exposure;
@@ -1399,10 +1399,10 @@ export abstract class RenderPipeline {
fv[UBOGlobal.EXPOSURE_OFFSET + 2] = this._isHDR ? 1.0 : 0.0;
fv[UBOGlobal.EXPOSURE_OFFSET + 3] = this._fpScale / exposure;
Vec3.array(fv, mainLight.direction, UBOGlobal.MAIN_LIT_DIR_OFFSET);
Vec3.toArray(fv, mainLight.direction, UBOGlobal.MAIN_LIT_DIR_OFFSET);
if (mainLight.enabled) {
Vec3.array(fv, mainLight.color, UBOGlobal.MAIN_LIT_COLOR_OFFSET);
Vec3.toArray(fv, mainLight.color, UBOGlobal.MAIN_LIT_COLOR_OFFSET);
if (mainLight.useColorTemperature) {
const colorTempRGB = mainLight.colorTemperatureRGB;
fv[UBOGlobal.MAIN_LIT_COLOR_OFFSET] *= colorTempRGB.x;
@@ -1416,7 +1416,7 @@ export abstract class RenderPipeline {
fv[UBOGlobal.MAIN_LIT_COLOR_OFFSET + 3] = mainLight.illuminance * exposure;
}
} else {
Vec4.array(fv, _v4Zero, UBOGlobal.MAIN_LIT_COLOR_OFFSET);
Vec4.toArray(fv, _v4Zero, UBOGlobal.MAIN_LIT_COLOR_OFFSET);
}
_vec4Array.set(ambient.skyColor);
+115 -72
View File
@@ -43,7 +43,7 @@ import { GFXSampler } from '../../gfx/sampler';
import { GFXShader } from '../../gfx/shader';
import { GFXTextureView } from '../../gfx/texture-view';
import { Mat3, Mat4, Vec2, Vec3, Vec4 } from '../../math';
import { RenderPassStage, RenderPriority, UniformBinding } from '../../pipeline/define';
import { isBuiltinBinding, RenderPassStage, RenderPriority } from '../../pipeline/define';
import { getPhaseID } from '../../pipeline/pass-phase';
import { Root } from '../../root';
import { programLib } from './program-lib';
@@ -58,50 +58,64 @@ export interface IPassInfoFull extends IPassInfo {
}
export type PassOverrides = RecursivePartial<IPassStates>;
const _type2fn = {
[GFXType.INT]: (a: Float32Array, v: any, idx: number = 0) => a[idx] = v,
[GFXType.INT2]: (a: Float32Array, v: any, idx: number = 0) => Vec2.array(a, v, idx * 2),
[GFXType.INT3]: (a: Float32Array, v: any, idx: number = 0) => Vec3.array(a, v, idx * 3),
[GFXType.INT4]: (a: Float32Array, v: any, idx: number = 0) => Vec4.array(a, v, idx * 4),
[GFXType.FLOAT]: (a: Float32Array, v: any, idx: number = 0) => a[idx] = v,
[GFXType.FLOAT2]: (a: Float32Array, v: any, idx: number = 0) => Vec2.array(a, v, idx * 2),
[GFXType.FLOAT3]: (a: Float32Array, v: any, idx: number = 0) => Vec3.array(a, v, idx * 3),
[GFXType.FLOAT4]: (a: Float32Array, v: any, idx: number = 0) => Vec4.array(a, v, idx * 4),
[GFXType.MAT3]: (a: Float32Array, v: any, idx: number = 0) => Mat3.array(a, v, idx * 9),
[GFXType.MAT4]: (a: Float32Array, v: any, idx: number = 0) => Mat4.array(a, v, idx * 16),
const _type2writer = {
[GFXType.UNKNOWN]: (a: Float32Array, v: any, idx: number = 0) => console.warn('illegal uniform handle'),
[GFXType.INT]: (a: Float32Array, v: any, idx: number = 0) => a[idx] = v,
[GFXType.INT2]: (a: Float32Array, v: any, idx: number = 0) => Vec2.toArray(a, v, idx),
[GFXType.INT3]: (a: Float32Array, v: any, idx: number = 0) => Vec3.toArray(a, v, idx),
[GFXType.INT4]: (a: Float32Array, v: any, idx: number = 0) => Vec4.toArray(a, v, idx),
[GFXType.FLOAT]: (a: Float32Array, v: any, idx: number = 0) => a[idx] = v,
[GFXType.FLOAT2]: (a: Float32Array, v: any, idx: number = 0) => Vec2.toArray(a, v, idx),
[GFXType.FLOAT3]: (a: Float32Array, v: any, idx: number = 0) => Vec3.toArray(a, v, idx),
[GFXType.FLOAT4]: (a: Float32Array, v: any, idx: number = 0) => Vec4.toArray(a, v, idx),
[GFXType.MAT3]: (a: Float32Array, v: any, idx: number = 0) => Mat3.toArray(a, v, idx),
[GFXType.MAT4]: (a: Float32Array, v: any, idx: number = 0) => Mat4.toArray(a, v, idx),
};
const _type2reader = {
[GFXType.UNKNOWN]: (a: Float32Array, v: any, idx: number = 0) => console.warn('illegal uniform handle'),
[GFXType.INT]: (a: Float32Array, v: any, idx: number = 0) => a[idx],
[GFXType.INT2]: (a: Float32Array, v: any, idx: number = 0) => Vec2.fromArray(v, a, idx),
[GFXType.INT3]: (a: Float32Array, v: any, idx: number = 0) => Vec3.fromArray(v, a, idx),
[GFXType.INT4]: (a: Float32Array, v: any, idx: number = 0) => Vec4.fromArray(v, a, idx),
[GFXType.FLOAT]: (a: Float32Array, v: any, idx: number = 0) => a[idx],
[GFXType.FLOAT2]: (a: Float32Array, v: any, idx: number = 0) => Vec2.fromArray(v, a, idx),
[GFXType.FLOAT3]: (a: Float32Array, v: any, idx: number = 0) => Vec3.fromArray(v, a, idx),
[GFXType.FLOAT4]: (a: Float32Array, v: any, idx: number = 0) => Vec4.fromArray(v, a, idx),
[GFXType.MAT3]: (a: Float32Array, v: any, idx: number = 0) => Mat3.fromArray(v, a, idx),
[GFXType.MAT4]: (a: Float32Array, v: any, idx: number = 0) => Mat4.fromArray(v, a, idx),
};
const _type2default = {
[GFXType.INT]: [0],
[GFXType.INT2]: [0, 0],
[GFXType.INT3]: [0, 0, 0],
[GFXType.INT4]: [0, 0, 0, 0],
[GFXType.FLOAT]: [0],
[GFXType.FLOAT2]: [0, 0],
[GFXType.FLOAT3]: [0, 0, 0],
[GFXType.FLOAT4]: [0, 0, 0, 0],
[GFXType.MAT3]: [1, 0, 0, 0, 1, 0, 0, 0, 1],
[GFXType.MAT4]: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[GFXType.SAMPLER2D]: 'default-texture',
[GFXType.SAMPLER_CUBE]: 'default-cube-texture',
[GFXType.INT]: [0],
[GFXType.INT2]: [0, 0],
[GFXType.INT3]: [0, 0, 0],
[GFXType.INT4]: [0, 0, 0, 0],
[GFXType.FLOAT]: [0],
[GFXType.FLOAT2]: [0, 0],
[GFXType.FLOAT3]: [0, 0, 0],
[GFXType.FLOAT4]: [0, 0, 0, 0],
[GFXType.MAT3]: [1, 0, 0, 0, 1, 0, 0, 0, 1],
[GFXType.MAT4]: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[GFXType.SAMPLER2D]: 'default-texture',
[GFXType.SAMPLER_CUBE]: 'default-cube-texture',
};
const btMask = 0xf0000000; // 4 bits, 16 slots
const typeMask = 0x0fc00000; // 6 bits, 64 slots
const bindingMask = 0x003ff800; // 11 bits, 2048 slots
const indexMask = 0x000007ff; // 11 bits, 2048 slots
const btMask = 0xf0000000; // 4 bits => 16 binding types
const typeMask = 0x0fc00000; // 6 bits => 64 types
const bindingMask = 0x003fc000; // 8 bits => 256 bindings
const offsetMask = 0x00003fff; // 14 bits => 4096 vectors
const genHandle = (bt: GFXBindingType, binding: number, type: GFXType, index: number = 0) =>
((bt << 28) & btMask) | ((type << 22) & typeMask) | ((binding << 11) & bindingMask) | (index & indexMask);
((bt << 28) & btMask) | ((type << 22) & typeMask) | ((binding << 14) & bindingMask) | (index & offsetMask);
const getBindingTypeFromHandle = (handle: number) => (handle & btMask) >>> 28;
const getTypeFromHandle = (handle: number) => (handle & typeMask) >>> 22;
const getBindingFromHandle = (handle: number) => (handle & bindingMask) >>> 11;
const getIndexFromHandle = (handle: number) => (handle & indexMask);
const isBuiltin = (binding: number) => binding >= UniformBinding.CUSTUM_UBO_BINDING_END_POINT;
const getBindingFromHandle = (handle: number) => (handle & bindingMask) >>> 14;
const getOffsetFromHandle = (handle: number) => (handle & offsetMask);
const customizeType = (handle: number, type: GFXType) => (handle & ~typeMask) | ((type << 22) & typeMask);
interface IBlock {
buffer: ArrayBuffer;
views: Float32Array[];
view: Float32Array;
dirty: boolean;
}
@@ -164,7 +178,7 @@ export class Pass {
return passes;
}
protected static getIndexFromHandle = getIndexFromHandle;
protected static getOffsetFromHandle = getOffsetFromHandle;
// internal resources
protected _buffers: Record<number, GFXBuffer> = {};
protected _samplers: Record<number, GFXSampler> = {};
@@ -214,7 +228,7 @@ export class Pass {
this._fillinPipelineInfo(info.states);
for (const u of this._shaderInfo.blocks) {
if (isBuiltin(u.binding)) { continue; }
if (isBuiltinBinding(u.binding)) { continue; }
const blockSize = u.members.reduce((s, m) => s + GFXGetTypeSize(m.type) * m.count, 0);
// create gfx buffer resource
@@ -225,21 +239,15 @@ export class Pass {
});
// non-builtin UBO data pools, note that the effect compiler
// guarantees these bindings to be consecutive, starting from 0
const block: IBlock = this._blocks[u.binding] = {
buffer: new ArrayBuffer(blockSize),
dirty: false,
views: [],
};
u.members.reduce((acc, cur, idx) => {
const size = GFXGetTypeSize(cur.type) * cur.count;
// create property-specific buffer views
const view = new Float32Array(block.buffer, acc, size / Float32Array.BYTES_PER_ELEMENT);
block.views.push(view);
const buffer = new ArrayBuffer(blockSize);
this._blocks[u.binding] = { buffer, dirty: false, view: new Float32Array(buffer) };
u.members.reduce((acc, cur) => {
// store handle map
this._handleMap[cur.name] = genHandle(GFXBindingType.UNIFORM_BUFFER, u.binding, cur.type, idx);
this._handleMap[cur.name] = genHandle(GFXBindingType.UNIFORM_BUFFER, u.binding, cur.type, acc);
// proceed the counter
return acc + size;
}, 0); // === blockSize
return acc + (GFXGetTypeSize(cur.type) >> 2) * cur.count;
}, 0);
}
for (const u of this._shaderInfo.samplers) {
this._handleMap[u.name] = genHandle(GFXBindingType.SAMPLER, u.binding, u.type);
@@ -252,11 +260,27 @@ export class Pass {
/**
* @zh
* 获取指定 uniform 的 handle。
* @param name 目标 uniform 名。
* 获取指定 UBO 成员,或其更具体分量的读写句柄。默认以成员自身的类型为目标读写类型(即读写时必须传入与成员类型相同的变量)。
* @param name 目标 UBO 成员名
* @param offset 目标分量在成员内的偏移量
* @param targetType 目标读写类型,用于定制化在使用此句柄时,将以什么类型进行读写操作
* @example
* ```
* // say 'pbrParams' is a uniform vec4
* const hParams = pass.getHandle('pbrParams'); // get the default handle
* pass.setUniform(hAlbedo, cc.v3(1, 0, 0)); // wrong! pbrParams.w is NaN now
*
* // say 'albedoScale' is a uniform vec4, and we only want to modify the w component in the form of a single float
* const hThreshold = pass.getHandle('albedoScale', 3, cc.GFXType.FLOAT);
* pass.setUniform(hThreshold, 0.5); // now, albedoScale.w = 0.5
* ```
*/
public getHandle (name: string): number | undefined {
return this._handleMap[name];
public getHandle (name: string, offset = 0, targetType = GFXType.UNKNOWN): number | undefined {
let handle = this._handleMap[name];
if (!handle) { return; }
if (targetType) { handle = customizeType(handle, targetType); }
else if (offset) { handle = customizeType(handle, getTypeFromHandle(handle) - offset); }
return handle + offset;
}
/**
@@ -279,12 +303,26 @@ export class Pass {
public setUniform (handle: number, value: any) {
const binding = Pass.getBindingFromHandle(handle);
const type = Pass.getTypeFromHandle(handle);
const idx = Pass.getIndexFromHandle(handle);
const ofs = Pass.getOffsetFromHandle(handle);
const block = this._blocks[binding];
_type2fn[type](block.views[idx], value);
_type2writer[type](block.view, value, ofs);
block.dirty = true;
}
/**
* @zh
* 获取指定普通向量类 uniform 的值。
* @param handle 目标 uniform 的 handle。
* @param out 输出向量。
*/
public getUniform (handle: number, out: any) {
const binding = Pass.getBindingFromHandle(handle);
const type = Pass.getTypeFromHandle(handle);
const ofs = Pass.getOffsetFromHandle(handle);
const block = this._blocks[binding];
return _type2reader[type](block.view, out, ofs);
}
/**
* @zh
* 设置指定数组类 uniform 的值,如果需要频繁更新请尽量使用此接口。
@@ -294,11 +332,12 @@ export class Pass {
public setUniformArray (handle: number, value: any[]) {
const binding = Pass.getBindingFromHandle(handle);
const type = Pass.getTypeFromHandle(handle);
const idx = Pass.getIndexFromHandle(handle);
const stride = GFXGetTypeSize(type) >> 2;
const block = this._blocks[binding];
for (let i = 0; i < value.length; i++) {
let ofs = Pass.getOffsetFromHandle(handle);
for (let i = 0; i < value.length; i++, ofs += stride) {
if (value[i] === null) { continue; }
_type2fn[type](block.views[idx], value[i], i);
_type2writer[type](block.view, value[i], ofs);
}
block.dirty = true;
}
@@ -407,7 +446,7 @@ export class Pass {
*/
public destroy () {
for (const u of this._shaderInfo.blocks) {
if (isBuiltin(u.binding)) { continue; }
if (isBuiltinBinding(u.binding)) { continue; }
this._buffers[u.binding].destroy();
}
this._buffers = {};
@@ -422,15 +461,17 @@ export class Pass {
*/
public resetUBOs () {
for (const u of this._shaderInfo.blocks) {
if (isBuiltin(u.binding)) { continue; }
if (isBuiltinBinding(u.binding)) { continue; }
const block: IBlock = this._blocks[u.binding];
let ofs = 0;
for (let i = 0; i < u.members.length; i++) {
const cur = u.members[i];
const view = block.views[i];
const inf = this._properties[cur.name];
const givenDefault = inf && inf.value;
const value: number[] = givenDefault ? givenDefault : _type2default[cur.type];
for (let j = 0; j < cur.count; j++) { view.set(value, j * value.length); }
const value = givenDefault ? givenDefault : _type2default[cur.type];
const stride = GFXGetTypeSize(cur.type) >> 2;
for (let j = 0; j < cur.count; j++) { block.view.set(value, ofs + j * stride); }
ofs += stride * cur.count;
}
block.dirty = true;
}
@@ -441,19 +482,21 @@ export class Pass {
* 重置所有 texture 和 sampler 为初始默认值。
*/
public resetTextures () {
const device = this._device;
for (const u of this._shaderInfo.samplers) {
if (isBuiltinBinding(u.binding)) { continue; }
const inf = this._properties[u.name];
if (inf && (inf.samplerHash !== undefined)) { this._samplers[u.binding] = samplerLib.getSampler(device, inf.samplerHash); }
const texName = inf && inf.value ? inf.value + '-texture' : _type2default[u.type];
const texture = builtinResMgr.get<TextureBase>(texName);
if (texture) {
this._textureViews[u.binding] = texture.getGFXTextureView()!;
const samplerHash = texture.getSamplerHash();
if (!this._samplers[u.binding] || samplerHash > 0) {
this._samplers[u.binding] = samplerLib.getSampler(device, samplerHash);
}
} else { console.warn('illegal texture default value ' + texName); }
const textureView = texture && texture.getGFXTextureView();
if (!textureView) { console.warn('illegal texture default value: ' + texName); continue; }
this._textureViews[u.binding] = textureView;
const samplerHash = inf && (inf.samplerHash !== undefined) ? inf.samplerHash : texture.getSamplerHash();
const sampler = this._samplers[u.binding] = samplerLib.getSampler(this._device, samplerHash);
for (let i = 0; i < this._resources.length; i++) {
const res = this._resources[i];
res.bindingLayout.bindSampler(u.binding, sampler);
res.bindingLayout.bindTextureView(u.binding, textureView);
}
}
}
+2 -2
View File
@@ -242,9 +242,9 @@ export class Model {
if (this._transformUpdated) {
// @ts-ignore
const worldMatrix = this._transform._mat; const rot = this._transform._rot;
Mat4.array(this._uboLocal.view, worldMatrix, UBOLocal.MAT_WORLD_OFFSET);
Mat4.toArray(this._uboLocal.view, worldMatrix, UBOLocal.MAT_WORLD_OFFSET);
Mat4.fromQuat(m4_1, rot);
Mat4.array(this._uboLocal.view, m4_1, UBOLocal.MAT_WORLD_IT_OFFSET);
Mat4.toArray(this._uboLocal.view, m4_1, UBOLocal.MAT_WORLD_IT_OFFSET);
const commonLocal = this._localBindings.get(UBOLocal.BLOCK.name);
if (commonLocal && commonLocal.buffer) {
+3 -3
View File
@@ -48,7 +48,7 @@ export class PlanarShadows {
}
set shadowColor (color: Color) {
Color.array(this._data, color, UBOShadow.SHADOW_COLOR_OFFSET);
Color.toArray(this._data, color, UBOShadow.SHADOW_COLOR_OFFSET);
this._globalBindings.buffer!.update(this.data);
}
@@ -118,7 +118,7 @@ export class PlanarShadows {
m.m13 = ly * d;
m.m14 = lz * d;
m.m15 = NdL;
Mat4.array(this.data, this._matLight);
Mat4.toArray(this.data, this._matLight);
this._globalBindings.buffer!.update(this.data);
}
@@ -146,7 +146,7 @@ export class PlanarShadows {
m.m13 = ly * d;
m.m14 = lz * d;
m.m15 = 1;
Mat4.array(this.data, this._matLight, UBOShadow.MAT_LIGHT_PLANE_PROJ_OFFSET);
Mat4.toArray(this.data, this._matLight, UBOShadow.MAT_LIGHT_PLANE_PROJ_OFFSET);
this._globalBindings.buffer!.update(this.data);
}
+4 -4
View File
@@ -1,12 +1,12 @@
import { IBArray } from '../../assets/mesh';
import { aabb, intersect, ray, triangle } from '../../geom-utils';
import { RecyclePool } from '../../memop';
import { Mat4, Vec3 } from '../../math';
import { Root } from '../../root';
import { INode } from '../../utils/interfaces';
import { GFXPrimitiveMode } from '../../gfx/define';
import { Mat4, Vec3 } from '../../math';
import { RecyclePool } from '../../memop';
import { Root } from '../../root';
import { Layers } from '../../scene-graph/layers';
import { Node } from '../../scene-graph/node';
import { INode } from '../../utils/interfaces';
import { JointsTexturePool } from '../models/joints-texture-utils';
import { Ambient } from './ambient';
import { Camera, ICameraInfo } from './camera';
+1 -1
View File
@@ -1,8 +1,8 @@
import { aabb } from '../../geom-utils';
import { Vec3 } from '../../math';
import { INode } from '../../utils/interfaces';
import { Light, LightType, nt2lm } from './light';
import { RenderScene } from './render-scene';
import { INode } from '../../utils/interfaces';
export class SphereLight extends Light {
+1 -1
View File
@@ -1,8 +1,8 @@
import { aabb, frustum } from '../../geom-utils';
import { Mat4, Quat, Vec3 } from '../../math';
import { INode } from '../../utils/interfaces';
import { Light, LightType, nt2lm } from './light';
import { RenderScene } from './render-scene';
import { INode } from '../../utils/interfaces';
const _forward = new Vec3(0, 0, -1);
const _v3 = new Vec3();
+2 -2
View File
@@ -61,7 +61,7 @@ export class AmbientInfo {
@property({ type: Color })
set skyColor (val: Color) {
this._skyColor.set(val);
if (this._resource) { Color.array(this._resource.skyColor, this.skyColor); }
if (this._resource) { Color.toArray(this._resource.skyColor, this.skyColor); }
}
get skyColor () {
return this._skyColor;
@@ -85,7 +85,7 @@ export class AmbientInfo {
@property({ type: Color })
set groundAlbedo (val: Color) {
this._groundAlbedo.set(val);
if (this._resource) { Color.array(this._resource.groundAlbedo, this.groundAlbedo); }
if (this._resource) { Color.toArray(this._resource.groundAlbedo, this.groundAlbedo); }
}
get groundAlbedo () {
return this._groundAlbedo;
@@ -800,7 +800,7 @@ export const graphicsAssembler: IAssembler = {
vData[dataOffset++] = 0;
vData[dataOffset++] = 1;
vData[dataOffset++] = 1;
Color.array(vData!, _curColor, dataOffset);
Color.toArray(vData!, _curColor, dataOffset);
meshbuffer.vertexStart ++;
},
};
+1 -1
View File
@@ -56,7 +56,7 @@ export const ttf: IAssembler = {
vData[4] = vData[12] = vData[13] = vData[30] = 1;
let offset = 5;
for (let i = 0; i < 4; i++) {
Color.array(vData, WHITE, offset);
Color.toArray(vData, WHITE, offset);
offset += 9;
}
return renderData;
+1 -1
View File
@@ -155,7 +155,7 @@ export const sliced: IAssembler = {
vbuf![vertexOffset++] = vert.z;
vbuf![vertexOffset++] = uvs.u;
vbuf![vertexOffset++] = uvs.v;
Color.array(vbuf!, sprite.color, vertexOffset);
Color.toArray(vbuf!, sprite.color, vertexOffset);
vertexOffset += 4;
// uintbuf[vertexOffset++] = color;
}
+3 -3
View File
@@ -40,7 +40,7 @@ export function fillVertices3D (node: INode, renderer: UI, renderData: RenderDat
vbuf[vertexOffset++] = vec3_temp.z;
vbuf[vertexOffset++] = vert.u;
vbuf[vertexOffset++] = vert.v;
Color.array(vbuf!, color, vertexOffset);
Color.toArray(vbuf!, color, vertexOffset);
vertexOffset += 4;
}
@@ -83,7 +83,7 @@ export function fillMeshVertices3D (node: INode, renderer: UI, renderData: Rende
vbuf[vertexOffset++] = vec3_temp.z;
vbuf[vertexOffset++] = vert.u;
vbuf[vertexOffset++] = vert.v;
Color.array(vbuf!, color, vertexOffset);
Color.toArray(vbuf!, color, vertexOffset);
vertexOffset += 4;
}
@@ -126,7 +126,7 @@ export function fillVerticesWithoutCalc3D (node: INode, renderer: UI, renderData
vbuf[vertexOffset++] = vert.z;
vbuf[vertexOffset++] = vert.u;
vbuf[vertexOffset++] = vert.v;
Color.array(vbuf!, color, vertexOffset);
Color.toArray(vbuf!, color, vertexOffset);
vertexOffset += 4;
}