mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 11:02:40 +08:00
dfc3d141f2
* gfx: descriptor sets * gfx: descriptor set, singular * better structure * adapt upper layers: first pass finally all compiler errors cleared. OKAY IT'S HAPPENING EVERYBODY STAY THE ****ING CALM * adapt upper layers: second pass THERE AND BACK AGAIN * unified light pass & shadow shader * gfx: descriptor set & pipeline layout * light pass: better structure * light pass: dynamic uniform * even more type checking for memory pools * Fix particleSystem and lineComponent. * delete comment * guard pool init param * Fix trail module error. * delete space * light pass: instancing & batching support * don't polyfill gfx stuff inside EffectAsset * better light pass structure * fix spot light culling Co-authored-by: caryliu <caryliu1999@gmail.com>
108 lines
4.3 KiB
TypeScript
108 lines
4.3 KiB
TypeScript
/*
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
http://www.cocos.com
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated engine source code (the "Software"), a limited,
|
|
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
|
to use Cocos Creator solely to develop games on your target platforms. You shall
|
|
not use Cocos Creator software for developing other software or tools that's
|
|
used for developing games. You are not granted to publish, distribute,
|
|
sublicense, and/or sell copies of Cocos Creator.
|
|
|
|
The software or tools in this License Agreement are licensed, not sold.
|
|
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
|
|
/**
|
|
* @category material
|
|
*/
|
|
|
|
import { IPassInfo } from '../../assets/effect-asset';
|
|
import { isBuiltinBinding } from '../../pipeline/define';
|
|
import { MaterialInstance } from './material-instance';
|
|
import { Pass, PassOverrides } from './pass';
|
|
import { overrideMacros, MacroRecord } from './pass-utils';
|
|
import { PassView, RasterizerStatePool, DepthStencilStatePool, BlendStatePool, PassPool } from './memory-pools';
|
|
|
|
export class PassInstance extends Pass {
|
|
|
|
get parent () { return this._parent; }
|
|
|
|
private _parent: Pass;
|
|
private _owner: MaterialInstance;
|
|
private _dontNotify = false;
|
|
|
|
constructor (parent: Pass, owner: MaterialInstance) {
|
|
super(parent.root);
|
|
this._parent = parent;
|
|
this._owner = owner;
|
|
this._doInit(this._parent, true); // defines may change now
|
|
for (const u of this._shaderInfo.blocks) {
|
|
if (isBuiltinBinding(u.set)) { continue; }
|
|
const block = this._blocks[u.binding];
|
|
const parentBlock = this._parent.blocks[u.binding];
|
|
block.view.set(parentBlock.view);
|
|
block.dirty = true;
|
|
}
|
|
for (const u of this._shaderInfo.samplers) {
|
|
if (isBuiltinBinding(u.set)) { continue; }
|
|
const sampler = this._samplers[u.binding] = (this._parent as PassInstance)._samplers[u.binding];
|
|
const texture = this._textures[u.binding] = (this._parent as PassInstance)._textures[u.binding];
|
|
this._descriptorSet.bindSampler(u.binding, sampler);
|
|
this._descriptorSet.bindTexture(u.binding, texture);
|
|
}
|
|
super.tryCompile();
|
|
}
|
|
|
|
public overridePipelineStates (original: IPassInfo, overrides: PassOverrides): void {
|
|
BlendStatePool.free(PassPool.get(this._handle, PassView.BLEND_STATE));
|
|
RasterizerStatePool.free(PassPool.get(this._handle, PassView.RASTERIZER_STATE));
|
|
DepthStencilStatePool.free(PassPool.get(this._handle, PassView.DEPTH_STENCIL_STATE));
|
|
PassPool.set(this._handle, PassView.BLEND_STATE, BlendStatePool.alloc());
|
|
PassPool.set(this._handle, PassView.RASTERIZER_STATE, RasterizerStatePool.alloc());
|
|
PassPool.set(this._handle, PassView.DEPTH_STENCIL_STATE, DepthStencilStatePool.alloc());
|
|
|
|
Pass.fillPipelineInfo(this._handle, original);
|
|
Pass.fillPipelineInfo(this._handle, overrides);
|
|
this._onStateChange();
|
|
}
|
|
|
|
public tryCompile (defineOverrides?: MacroRecord) {
|
|
if (defineOverrides) {
|
|
if (!overrideMacros(this._defines, defineOverrides)) {
|
|
return false;
|
|
}
|
|
}
|
|
const res = super.tryCompile();
|
|
this._onStateChange();
|
|
return res;
|
|
}
|
|
|
|
public beginChangeStatesSilently () {
|
|
this._dontNotify = true;
|
|
}
|
|
|
|
public endChangeStatesSilently () {
|
|
this._dontNotify = false;
|
|
}
|
|
|
|
protected _syncBatchingScheme () {
|
|
this._defines.USE_BATCHING = this._defines.USE_INSTANCING = false;
|
|
}
|
|
|
|
protected _onStateChange () {
|
|
PassPool.set(this._handle, PassView.HASH, Pass.getPassHash(this._handle, this._hShaderDefault));
|
|
this._owner.onPassStateChange(this._dontNotify);
|
|
}
|
|
}
|