From ee936231cf332f9ede95cda0b12d6f9b98b86347 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Sat, 29 Dec 2018 18:37:24 +0800 Subject: [PATCH] update pipeline code --- cocos/core/root.ts | 19 +++++++++++++- cocos/renderer/gfx/gfx-device.ts | 6 ++++- cocos/renderer/gfx/webgl/webgl-gfx-device.ts | 8 +++--- .../renderer/pipeline/forward/forward-flow.ts | 16 ++++++++++++ .../pipeline/forward/forward-pipeline.ts | 5 ++++ cocos/renderer/pipeline/render-flow.ts | 7 ++++++ cocos/renderer/pipeline/render-pipeline.ts | 25 +++++++++++++------ 7 files changed, 73 insertions(+), 13 deletions(-) diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 8118d6dee7..7841551e9c 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -6,6 +6,7 @@ import { RenderPipeline } from "../renderer/pipeline/render-pipeline"; import { ForwardPipeline } from "../renderer/pipeline/forward/forward-pipeline"; export interface RootInfo { + device: GFXDevice; }; export class Root { @@ -15,7 +16,14 @@ export class Root { public initialize(info: RootInfo): boolean { - let pipeline = new ForwardPipeline; + if(!info.device) { + console.error("RootInfo.device is null."); + return false; + } + this._device = info.device; + this._mainWindow = this._device.mainWindow; + + let pipeline = new ForwardPipeline(this); if (!pipeline.initialize()) { return false; } @@ -125,6 +133,14 @@ export class Root { this._views = []; } + public get device(): GFXDevice | null { + return this._device; + } + + public get mainWindow(): GFXWindow | null { + return this._mainWindow; + } + public get pipeline(): RenderPipeline | null { return this._pipeline; } @@ -138,6 +154,7 @@ export class Root { } private _device: GFXDevice | null = null; + private _mainWindow: GFXWindow | null = null; private _windows: GFXWindow[] = []; private _pipeline: RenderPipeline | null = null; private _scenes: Scene[] = []; diff --git a/cocos/renderer/gfx/gfx-device.ts b/cocos/renderer/gfx/gfx-device.ts index 81aeccc495..8e2874368a 100644 --- a/cocos/renderer/gfx/gfx-device.ts +++ b/cocos/renderer/gfx/gfx-device.ts @@ -48,13 +48,17 @@ export abstract class GFXDevice { return this._queue; } + public get mainWindow(): GFXWindow | null { + return this._mainWindow; + } + public get maxVertexAttributes(): number { return this._maxVertexAttributes; } protected _deviceName : string = ""; protected _queue : GFXQueue | null = null; - protected _curWindow : GFXWindow | null = null; + protected _mainWindow : GFXWindow | null = null; protected _maxVertexAttributes : number = 0; }; diff --git a/cocos/renderer/gfx/webgl/webgl-gfx-device.ts b/cocos/renderer/gfx/webgl/webgl-gfx-device.ts index a2ea99b647..93a6fb155b 100644 --- a/cocos/renderer/gfx/webgl/webgl-gfx-device.ts +++ b/cocos/renderer/gfx/webgl/webgl-gfx-device.ts @@ -149,7 +149,7 @@ export class WebGLGFXDevice extends GFXDevice { this._ANGLE_instanced_arrays = this._webGLRC.getExtension("ANGLE_instanced_arrays"); // create primary window - this._curWindow = this.createWindow({ + this._mainWindow = this.createWindow({ title: this._webGLRC.canvas.title, left: this._webGLRC.canvas.offsetLeft, top: this._webGLRC.canvas.offsetTop, @@ -162,9 +162,9 @@ export class WebGLGFXDevice extends GFXDevice { public destroy(): void { - if (this._curWindow) { - this._curWindow.destroy(); - this._curWindow = null; + if (this._mainWindow) { + this._mainWindow.destroy(); + this._mainWindow = null; } this._webGLRC = null; diff --git a/cocos/renderer/pipeline/forward/forward-flow.ts b/cocos/renderer/pipeline/forward/forward-flow.ts index 643cc8c202..24db73d32c 100644 --- a/cocos/renderer/pipeline/forward/forward-flow.ts +++ b/cocos/renderer/pipeline/forward/forward-flow.ts @@ -1,7 +1,13 @@ import { RenderFlow, RenderFlowInfo } from "../render-flow"; +import { GFXRenderPass } from "../../gfx/gfx-render-pass"; +import { RenderPipeline } from "../render-pipeline"; export class ForwardFlow extends RenderFlow { + constructor(pipeline: RenderPipeline) { + super(pipeline); + } + public initialize(info: RenderFlowInfo): boolean { if(info.name) { @@ -9,6 +15,14 @@ export class ForwardFlow extends RenderFlow { } this._priority = info.priority; + + let device = this._pipeline.root.device; + if(!device) { + return false; + } + + //this._pipeline.root.mainWindow; + //this._renderPass = return true; } @@ -16,4 +30,6 @@ export class ForwardFlow extends RenderFlow { public destroy(): void { this.destroyStages(); } + + private _renderPass: GFXRenderPass | null = null; }; diff --git a/cocos/renderer/pipeline/forward/forward-pipeline.ts b/cocos/renderer/pipeline/forward/forward-pipeline.ts index cd541a99df..a0f88066d9 100644 --- a/cocos/renderer/pipeline/forward/forward-pipeline.ts +++ b/cocos/renderer/pipeline/forward/forward-pipeline.ts @@ -1,7 +1,12 @@ import { RenderPipeline } from "../render-pipeline"; +import { Root } from "../../../core/root"; export class ForwardPipeline extends RenderPipeline { + constructor(root: Root) { + super(root); + } + public initialize(): boolean { return true; diff --git a/cocos/renderer/pipeline/render-flow.ts b/cocos/renderer/pipeline/render-flow.ts index 3bc363c87d..2e83e6062d 100644 --- a/cocos/renderer/pipeline/render-flow.ts +++ b/cocos/renderer/pipeline/render-flow.ts @@ -1,5 +1,6 @@ import { RenderStage, RenderStageInfo } from "./render-stage"; import { RenderView } from "./render-view"; +import { RenderPipeline } from "./render-pipeline"; export interface RenderFlowInfo { name?: string; @@ -8,6 +9,10 @@ export interface RenderFlowInfo { export abstract class RenderFlow { + constructor(pipeline: RenderPipeline) { + this._pipeline = pipeline; + } + public abstract initialize(info: RenderFlowInfo): boolean; public abstract destroy(); @@ -46,7 +51,9 @@ export abstract class RenderFlow { return this._priority; } + protected _pipeline: RenderPipeline; protected _name: string = ""; protected _priority: number = 0; protected _stages: RenderStage[] = []; + protected _material: null = null; // TODO }; diff --git a/cocos/renderer/pipeline/render-pipeline.ts b/cocos/renderer/pipeline/render-pipeline.ts index 3de6d466ed..3915757ddb 100644 --- a/cocos/renderer/pipeline/render-pipeline.ts +++ b/cocos/renderer/pipeline/render-pipeline.ts @@ -1,29 +1,35 @@ import { RenderView } from "./render-view"; import { RenderFlow, RenderFlowInfo } from "./render-flow"; +import { GFXDevice } from "../gfx/gfx-device"; +import { Root } from "../../core/root"; export abstract class RenderPipeline { + constructor(root: Root) { + this._root = root; + } + public abstract initialize(): boolean; public abstract destroy(); public render(view: RenderView) { - for(let i = 0; i < this._flows.length; ++i) { + for (let i = 0; i < this._flows.length; ++i) { this._flows[i].render(view); } } - + public resize(width, height) { - + } - public createFlow(clazz: new(pipeline: RenderPipeline) => T, info : RenderFlowInfo): RenderFlow | null { + public createFlow(clazz: new (pipeline: RenderPipeline) => T, info: RenderFlowInfo): RenderFlow | null { let flow: RenderFlow = new clazz(this); - if(flow.initialize(info)) { + if (flow.initialize(info)) { this._flows.push(flow); this._flows.sort((a: RenderFlow, b: RenderFlow) => { return a.priority - b.priority; }); - + return flow; } else { return null; @@ -31,15 +37,20 @@ export abstract class RenderPipeline { } public destroyFlows() { - for(let i = 0; i < this._flows.length; ++i) { + for (let i = 0; i < this._flows.length; ++i) { this._flows[i].destroy(); } this._flows = []; } + public get root(): Root { + return this._root; + } + public get flows(): RenderFlow[] { return this._flows; } + protected _root: Root; protected _flows: RenderFlow[] = []; };