This commit is contained in:
Yun Hsiao Wu
2019-01-08 14:17:30 +08:00
parent 3e9fb16273
commit 87a6672db5
6 changed files with 60 additions and 15 deletions
+6 -6
View File
@@ -95,15 +95,15 @@ export class Material extends Asset {
this._props[passIdx][name] = val;
const pass = this._passes[passIdx];
const handle = pass.getHandleFromName(name);
pass.setUniformMember(handle, val);
pass.setUniform(handle, val);
}
public setTexture(name: string, val: TextureBase, passIdx = 0) {
console.assert(passIdx < this._passes.length, 'illegal pass index.');
this._textures[passIdx][name] = val;
const pass = this._passes[passIdx];
const handle = pass.getHandleFromName(name);
pass.setTextureView(handle, val._texView);
const binding = pass.getBindingFromName(name);
pass.bindTextureView(binding, val._texView);
}
public copy(mat: Material) {
@@ -146,13 +146,13 @@ export class Material extends Asset {
if (!props) { props = this._props[i] = {}; }
for (const p of Object.keys(props)) {
const handle = pass.getHandleFromName(p);
pass.setUniformMember(handle, props[p]);
pass.setUniform(handle, props[p]);
}
let textures = this._textures[i];
if (!textures) { textures = this._textures[i] = {}; }
for (const t of Object.keys(textures)) {
const handle = pass.getHandleFromName(t);
pass.setTextureView(handle, textures[t]._texView);
const binding = pass.getBindingFromName(t);
pass.bindTextureView(binding, textures[t]._texView);
}
});
} else {
+13
View File
@@ -26,5 +26,18 @@
import { RawAsset } from "./raw-asset";
export class Asset extends RawAsset {
protected _native: string;
protected loaded: boolean;
public _nativeAsset: any;
public nativeUrl: string;
static preventDeferredLoadDependents: boolean;
static preventPreloadNativeObject: boolean;
static deserialize(data: string): object;
public createNode: (err: string, node: object) => void | null;
public toString(): string;
public serialize(): string;
protected _setRawAsset(filename: string, inLibrary: boolean): void;
}
+1
View File
@@ -28,4 +28,5 @@ import { CCObject } from '../core/data/object';
export class RawAsset extends CCObject {
_uuid: string;
static isRawAssetType(ctor: Function): boolean;
}
+20 -2
View File
@@ -24,6 +24,24 @@
****************************************************************************/
export class CCObject {
_name: string;
name: string;
protected _name: string;
protected _objFlags: number;
static _deferredDestroy(): void;
public name: string;
public isValid: boolean;
public isRealValid: boolean;
public destroy(): boolean;
public realDestroyInEditor(): void;
public _clearDeferredDestroyTimer(): void;
protected _destruct(): void;
protected _destroyImmediate(): void;
protected _serialize: (exporting: boolean) => object | null;
protected _deserialize: (data: object, ctx: object) => object | null;
protected _onPreDestroy: () => void | null;
protected Flags: object;
}
@@ -74,10 +74,10 @@ export class TestMaterialStage extends RenderStage {
// material
this._material.effectName = 'test'; // parsed-effect file is embedded in cocos/3d/builtin/effects.js
const pass = this._material.passes[0];
const handle1 = pass.getHandleFromName('u_sampler');
pass.setTextureView(handle1, <GFXTextureView>this._texView);
const handle2 = pass.getHandleFromName('u_color');
pass.setUniformMember(handle2, cc.color('#ffffff'));
const texBinding = pass.getBindingFromName('u_sampler');
pass.bindTextureView(texBinding, <GFXTextureView>this._texView);
const colorHandle = pass.getHandleFromName('u_color');
pass.setUniform(colorHandle, cc.color('#ffffff'));
pass.update();
this._material.inited = true;
}
+16 -3
View File
@@ -156,7 +156,11 @@ export class Pass {
return this._handleMap[name];
}
public setUniformMember(handle: number, value: any) {
public getBindingFromName(name: string) {
return parseHandle(this.getHandleFromName(name))[0];
}
public setUniform(handle: number, value: any) {
const [ binding, idx ] = parseHandle(handle);
const block = this._blocks[binding];
const type = this._typeMap[handle];
@@ -164,8 +168,7 @@ export class Pass {
block.dirty = true;
}
public setTextureView(handle: number, value: GFXTextureView) {
const [ binding ] = parseHandle(handle);
public bindTextureView(binding: number, value: GFXTextureView) {
const bl = this._bindingLayout;
if (bl && bl.getBindingUnit(binding).texView !== value) {
bl.bindTextureView(binding, value);
@@ -173,6 +176,14 @@ export class Pass {
}
}
public bindSampler(binding: number, value: GFXSampler) {
const bl = this._bindingLayout;
if (bl && bl.getBindingUnit(binding).sampler !== value) {
bl.bindSampler(binding, value);
this._layoutDirty = true;
}
}
public setStates(info: PassInfoBase) {
if (this._pipelineState) { this._pipelineState.destroy(); }
this.createPipelineState(info);
@@ -192,10 +203,12 @@ export class Pass {
const block = this._blocks[i];
if (block.dirty) {
this._buffers[i].update(block.buffer);
block.dirty = false;
}
}
if (this._bindingLayout && this._layoutDirty) {
this._bindingLayout.update();
this._layoutDirty = false;
}
}