mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 19:42:39 +08:00
update pipeline code
This commit is contained in:
+18
-1
@@ -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[] = [];
|
||||
|
||||
@@ -48,13 +48,17 @@ export abstract class GFXDevice {
|
||||
return <GFXQueue>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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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<T extends RenderFlow>(clazz: new(pipeline: RenderPipeline) => T, info : RenderFlowInfo): RenderFlow | null {
|
||||
public createFlow<T extends RenderFlow>(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[] = [];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user