From fda2473401bc449d0d04ede9d08ab2376ef1623b Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Tue, 22 Jan 2019 11:26:18 +0800 Subject: [PATCH] pass priority --- cocos/3d/assets/effect-asset.ts | 1 + cocos/3d/framework/model-component.js | 4 ++++ cocos/gfx/define.ts | 6 ++++++ cocos/gfx/webgl/webgl-command-allocator.ts | 18 ++++++++--------- cocos/renderer/core/pass.ts | 23 ++++++++++++---------- cocos/renderer/scene/submodel.ts | 12 ++++++++++- 6 files changed, 44 insertions(+), 20 deletions(-) diff --git a/cocos/3d/assets/effect-asset.ts b/cocos/3d/assets/effect-asset.ts index bb98d62d1f..0545c4d194 100644 --- a/cocos/3d/assets/effect-asset.ts +++ b/cocos/3d/assets/effect-asset.ts @@ -12,6 +12,7 @@ export interface IPropertyInfo { export interface IPassInfo { program: string; // effect-writer part + priority?: number; primitive?: GFXPrimitiveMode; stage?: RenderPassStage; rasterizerState?: GFXRasterizerState; diff --git a/cocos/3d/framework/model-component.js b/cocos/3d/framework/model-component.js index 44329e4de6..76a4bb9edc 100644 --- a/cocos/3d/framework/model-component.js +++ b/cocos/3d/framework/model-component.js @@ -163,6 +163,10 @@ export class ModelComponent extends RenderableComponent { this._model = null; } + get model () { + return this._model; + } + onLoad() { } diff --git a/cocos/gfx/define.ts b/cocos/gfx/define.ts index 03a8dd02d0..8f3aa8b544 100644 --- a/cocos/gfx/define.ts +++ b/cocos/gfx/define.ts @@ -791,3 +791,9 @@ export function GFXGetTypeSize (type: GFXType): number { } } } + +export enum GFXPassPriority { + MIN = 0, + MAX = 0xff, + DEFAULT = 0x80, +} diff --git a/cocos/gfx/webgl/webgl-command-allocator.ts b/cocos/gfx/webgl/webgl-command-allocator.ts index 4f106beb8c..25aeffdbd2 100644 --- a/cocos/gfx/webgl/webgl-command-allocator.ts +++ b/cocos/gfx/webgl/webgl-command-allocator.ts @@ -25,23 +25,28 @@ export class WebGLGFXCommandPool { } } + /* */ public alloc (clazz: new() => T): T { return new clazz(); } - - /* + /* * public alloc (clazz: new() => T): T { if (this._count >= this._data.length) { const size = this._data.length * 2; for (let i = this._data.length; i < size; ++i) { this._data[i] = new clazz(); + this._objIdx.set(this._data[i], i); } } return this._data[this._count++]; } - */ + /* */ + /* */ + public free (obj: T) { + } + /* * public freeAt (idx: number) { if (idx >= this._count) { return; @@ -55,18 +60,13 @@ export class WebGLGFXCommandPool { this._objIdx.set(this._data[last], last); this._count -= 1; } - - public free (obj: T) { - } - - /* public free (obj: T) { const idx = this._objIdx.get(obj); if (idx !== undefined) { this.freeAt(idx); } } - */ + /* */ } export class WebGLGFXCommandAllocator extends GFXCommandAllocator { diff --git a/cocos/renderer/core/pass.ts b/cocos/renderer/core/pass.ts index 2a4e29a1ce..8d1299d784 100644 --- a/cocos/renderer/core/pass.ts +++ b/cocos/renderer/core/pass.ts @@ -5,7 +5,7 @@ import { color4, mat2, mat3, mat4, vec2, vec3, vec4 } from '../../core/vmath'; import { GFXBindingLayout, IGFXBinding } from '../../gfx/binding-layout'; import { GFXBuffer } from '../../gfx/buffer'; import { GFXBindingType, GFXBufferUsageBit, GFXDynamicState, - GFXMemoryUsageBit, GFXPrimitiveMode, GFXType } from '../../gfx/define'; + GFXMemoryUsageBit, GFXPassPriority, GFXPrimitiveMode, GFXType } from '../../gfx/define'; import { GFXDevice } from '../../gfx/device'; import { GFXPipelineLayout } from '../../gfx/pipeline-layout'; import { GFXBlendState, GFXBlendTarget, GFXDepthStencilState, @@ -107,6 +107,7 @@ export class Pass { protected _resources: IPassResources[] = []; // internal data protected _programName: string = ''; + protected _priority: GFXPassPriority = GFXPassPriority.DEFAULT; protected _primitive: GFXPrimitiveMode = GFXPrimitiveMode.TRIANGLE_LIST; protected _stage: RenderPassStage = RenderPassStage.DEFAULT; protected _bindings: IGFXBinding[] = []; @@ -312,6 +313,7 @@ export class Pass { } protected _fillinPipelineInfo (info: PassOverrides) { + if (info.priority !== undefined) { this._priority = info.priority; } if (info.primitive !== undefined) { this._primitive = info.primitive; } if (info.stage !== undefined) { this._stage = info.stage; } if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics; } @@ -331,15 +333,16 @@ export class Pass { } get programName () { return this._programName; } - get primitive (): GFXPrimitiveMode { return this._primitive; } - get stage (): RenderPassStage { return this._stage; } - get bindings (): IGFXBinding[] { return this._bindings; } - get blendState (): GFXBlendState { return this._bs; } - get depthStencilState (): GFXDepthStencilState { return this._dss; } - 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; } + get priority () { return this._priority; } + get primitive () { return this._primitive; } + get stage () { return this._stage; } + get bindings () { return this._bindings; } + get blendState () { return this._bs; } + get depthStencilState () { return this._dss; } + get rasterizerState () { return this._rs; } + get shader () { return this._shader; } + get renderPass () { return this._renderPass; } + get dynamics () { return this._dynamics; } } function serializeBlendState (bs: GFXBlendState) { diff --git a/cocos/renderer/scene/submodel.ts b/cocos/renderer/scene/submodel.ts index 0006f0e737..77bd86eee6 100644 --- a/cocos/renderer/scene/submodel.ts +++ b/cocos/renderer/scene/submodel.ts @@ -1,7 +1,7 @@ import { Material } from '../../3d/assets/material'; import { IRenderingSubmesh } from '../../3d/assets/mesh'; import { GFXCommandBuffer } from '../../gfx/command-buffer'; -import { GFXCommandBufferType } from '../../gfx/define'; +import { GFXCommandBufferType, GFXPassPriority } from '../../gfx/define'; import { GFXDevice } from '../../gfx/device'; import { GFXInputAssembler, IGFXInputAssemblerInfo } from '../../gfx/input-assembler'; import { GFXPipelineState } from '../../gfx/pipeline-state'; @@ -14,6 +14,7 @@ export class SubModel { private _cmdBuffers: GFXCommandBuffer[]; private _psos: GFXPipelineState[] | null; private _castShadow: boolean; + private _priority: GFXPassPriority; constructor () { this._subMeshObject = null; @@ -22,6 +23,7 @@ export class SubModel { this._psos = null; this._castShadow = false; this._inputAssembler = null; + this._priority = GFXPassPriority.DEFAULT; } public initialize (subMesh: IRenderingSubmesh, mat: Material, psos: GFXPipelineState[]) { @@ -43,6 +45,14 @@ export class SubModel { } } + set priority (val: GFXPassPriority) { + this._priority = val; + } + + get priority () { + return this._priority; + } + set subMeshData (sm: IRenderingSubmesh) { if (this._inputAssembler) { this._inputAssembler.destroy();