From 5eec422d86715378da2abe8af6c4d42b6c6302e6 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Fri, 18 Jan 2019 19:22:10 +0800 Subject: [PATCH] dynamic states --- cocos/renderer/core/pass.ts | 20 ++++- cocos/renderer/scene/model.ts | 5 +- playground/gizmo.html | 153 ++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 5 deletions(-) create mode 100644 playground/gizmo.html diff --git a/cocos/renderer/core/pass.ts b/cocos/renderer/core/pass.ts index 07933d0658..2a4e29a1ce 100644 --- a/cocos/renderer/core/pass.ts +++ b/cocos/renderer/core/pass.ts @@ -88,6 +88,13 @@ interface IPassResources { pipelineState: GFXPipelineState; } +interface IPassDynamics { + [type: string]: { + dirty: boolean, + value: number[], + }; +} + export class Pass { public static getBindingTypeFromHandle = getBindingTypeFromHandle; public static getTypeFromHandle = getTypeFromHandle; @@ -106,7 +113,8 @@ export class Pass { protected _bs: GFXBlendState = new GFXBlendState(); protected _dss: GFXDepthStencilState = new GFXDepthStencilState(); protected _rs: GFXRasterizerState = new GFXRasterizerState(); - protected _dynamics: GFXDynamicState[] = []; + protected _dynamicStates: GFXDynamicState[] = []; + protected _dynamics: IPassDynamics = {}; protected _handleMap: Record = {}; protected _blocks: IBlock[] = []; // external references @@ -217,6 +225,12 @@ export class Pass { } } + public setDynamicState (state: GFXDynamicState, value: any) { + const ds = this._dynamics[state]; + if (ds && ds.value === value) { return; } + ds.value = value; ds.dirty = true; + } + public overridePipelineStates (original: IPassInfo, overrides: PassOverrides) { this._bs = new GFXBlendState(); this._dss = new GFXDepthStencilState(); @@ -268,6 +282,7 @@ export class Pass { const pipelineState = this._device.createPipelineState({ bs: this._bs, dss: this._dss, + dynamicStates: this._dynamicStates, is: new GFXInputState(), layout: pipelineLayout, primitive: this._primitive, @@ -299,7 +314,7 @@ export class Pass { protected _fillinPipelineInfo (info: PassOverrides) { if (info.primitive !== undefined) { this._primitive = info.primitive; } if (info.stage !== undefined) { this._stage = info.stage; } - if (info.dynamics !== undefined) { this._dynamics = info.dynamics; } + if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics; } const bs = this._bs; if (info.blendState) { @@ -324,6 +339,7 @@ export class Pass { get rasterizerState (): GFXRasterizerState { return this._rs; } get shader (): GFXShader | null { return this._shader; } get renderPass (): GFXRenderPass | null { return this._renderPass; } + get dynamics (): IPassDynamics { return this._dynamics; } } function serializeBlendState (bs: GFXBlendState) { diff --git a/cocos/renderer/scene/model.ts b/cocos/renderer/scene/model.ts index 8ff0eadc50..6b785fdb5a 100644 --- a/cocos/renderer/scene/model.ts +++ b/cocos/renderer/scene/model.ts @@ -93,10 +93,9 @@ export class Model { } public _updateTransform () { - if (!this._node.hasChanged || !this._modelBounds) { - return; - } + if (!this._node.hasChanged) { return; } this._node.updateWorldTransformFull(); + if (!this._modelBounds) { return; } this._modelBounds.transform( // @ts-ignore diff --git a/playground/gizmo.html b/playground/gizmo.html new file mode 100644 index 0000000000..faf583c1dc --- /dev/null +++ b/playground/gizmo.html @@ -0,0 +1,153 @@ + + + + + gizmo + + + + + + + + + + + + + + + +