commit ui render pipeline

This commit is contained in:
jerrywwl
2019-01-16 16:30:57 +08:00
parent d62f4e6244
commit 96a7c65382
7 changed files with 108 additions and 27 deletions
+15 -2
View File
@@ -27,6 +27,10 @@ export class Root {
return this._mainWindow;
}
public get curWindow (): GFXWindow | null {
return this._curWindow;
}
public get windows (): GFXWindow[] {
return this._windows;
}
@@ -57,6 +61,7 @@ export class Root {
private _device: GFXDevice;
private _windows: GFXWindow[] = [];
private _mainWindow: GFXWindow | null = null;
private _curWindow: GFXWindow | null = null;
private _pipeline: RenderPipeline | null = null;
private _ui: UI | null = null;
private _scenes: RenderScene[] = [];
@@ -77,6 +82,7 @@ export class Root {
}
this._mainWindow = this._device.mainWindow;
this._curWindow = this._mainWindow;
const pipeline = new ForwardPipeline(this);
if (!pipeline.initialize()) {
@@ -108,6 +114,9 @@ export class Root {
this._ui.destroy();
this._ui = null;
}
this._curWindow = null;
this._mainWindow = null;
}
public resize (width: number, height: number) {
@@ -116,19 +125,23 @@ export class Root {
}
}
public activeWindow (window: GFXWindow) {
this._curWindow = window;
}
public frameMove (deltaTime: number) {
this._frameTime = deltaTime;
for (const view of this._views) {
if (view.isEnable()) {
if (view.isEnable() && view.window === this._mainWindow) {
this._pipeline!.render(view);
}
}
this._ui!.update(deltaTime);
( this._device as GFXDevice).present();
this._device.present();
}
public createWindow (info: IGFXWindowInfo): GFXWindow | null {
+3 -1
View File
@@ -42,6 +42,8 @@ export class ForwardStage extends RenderStage {
public render (view: RenderView) {
const framebuffer = view.window!.framebuffer;
const cmdBuff = this._cmdBuff!;
const queue = this._pipeline.queue;
@@ -51,7 +53,7 @@ export class ForwardStage extends RenderStage {
this._renderArea.height = camera.height;
cmdBuff.begin();
cmdBuff.beginRenderPass(this._framebuffer as GFXFramebuffer, this._renderArea,
cmdBuff.beginRenderPass(framebuffer, this._renderArea,
[camera.clearColor], camera.clearDepth, camera.clearStencil);
cmdBuff.execute(queue.cmdBuffs.array, queue.cmdBuffCount);
-2
View File
@@ -138,8 +138,6 @@ export abstract class RenderPipeline {
for (const flow of this._flows) {
flow.render(view);
}
// TODO : add ui render pipeline
}
public addRenderPass (stage: number, renderPass: GFXRenderPass) {
+11 -17
View File
@@ -5,31 +5,25 @@ import { Pass } from '../renderer/core/pass';
import { Camera } from '../renderer/scene/camera';
import { Model } from '../renderer/scene/model';
export class RenderItem {
public hash: number = 0;
public depth: number = 0;
public shaderId: number = 0;
public model: Model;
public pass: Pass;
public cmdBuff: GFXCommandBuffer;
constructor (model: Model, pass: Pass, cmdBuff: GFXCommandBuffer) {
this.model = model;
this.pass = pass;
this.cmdBuff = cmdBuff;
}
export interface IRenderItem {
hash: number;
depth: number;
shaderId: number;
model: Model;
pass: Pass;
cmdBuff: GFXCommandBuffer;
}
export class RenderQueue {
public opaques: CachedArray<RenderItem>;
public transparents: CachedArray<RenderItem>;
public opaques: CachedArray<IRenderItem>;
public transparents: CachedArray<IRenderItem>;
public cmdBuffs: CachedArray<GFXCommandBuffer>;
public cmdBuffCount: number = 0;
constructor () {
// Opaque objects are sorted by depth front to back -> pass priority -> shader id.
const opaqueCompareFn = (a: RenderItem, b: RenderItem) => {
const opaqueCompareFn = (a: IRenderItem, b: IRenderItem) => {
if (a.hash === b.hash) {
if (a.depth === b.depth) {
return a.shaderId - b.shaderId;
@@ -42,7 +36,7 @@ export class RenderQueue {
};
// Transparent objects are sorted by depth back to front -> pass priority -> shader id.
const transparentCompareFn = (a: RenderItem, b: RenderItem) => {
const transparentCompareFn = (a: IRenderItem, b: IRenderItem) => {
if (a.hash === b.hash) {
if (a.depth === b.depth) {
return a.shaderId - b.shaderId;
+1 -1
View File
@@ -1,4 +1,4 @@
import { Model } from "../scene/model";
import { Model } from '../scene/model';
export class UIBatchModel extends Model {
+17
View File
@@ -0,0 +1,17 @@
import { CachedArray } from '../../core/memop/cached-array';
import { Camera } from '../scene/camera';
import { UIBatchModel } from './ui-batch-model';
export interface IUIRenderItem {
camera: Camera;
batchModel: UIBatchModel;
}
export class UIRenderQueue {
public items: CachedArray<IUIRenderItem>;
constructor () {
this.items = new CachedArray(64);
}
}
+61 -4
View File
@@ -1,10 +1,22 @@
// import { vfmt3D } from '../../2d/renderer/webgl/vertex-format';
import RecyclePool from '../../3d/memop/recycle-pool';
import { CachedArray } from '../../core/memop/cached-array';
import { Root } from '../../core/root';
import { GFXCommandBuffer } from '../../gfx/command-buffer';
import { GFXCommandBufferType, IGFXRect } from '../../gfx/define';
import { GFXDevice } from '../../gfx/device';
import { GFXFramebuffer } from '../../gfx/framebuffer';
import { Camera } from '../scene/camera';
import { RenderScene } from '../scene/render-scene';
import { UIBatchModel } from './ui-batch-model';
export interface IUIRenderItem {
camera: Camera;
batchModel: UIBatchModel;
cmdBuff: GFXCommandBuffer;
}
export class UI {
// private _buffer: MeshBuffer | null = new MeshBuffer(this, vfmt3D);
private _batchedModels: UIBatchModel[] = [];
@@ -13,23 +25,41 @@ export class UI {
// });
});
private _modelPool: RecyclePool | null = new RecyclePool(16, () => {
private _modelPool: RecyclePool = new RecyclePool(16, () => {
return this._scene.createModel(UIBatchModel);
});
private _device: GFXDevice;
private _cmdBuff: GFXCommandBuffer | null = null;
private _renderArea: IGFXRect = { x: 0, y: 0, width: 0, height: 0 };
private _scene: RenderScene;
private _items: CachedArray<IUIRenderItem>;
constructor (private _root: Root) {
this._device = _root.device;
this._scene = this._root.createScene({
name: 'GUIScene',
});
this._items = new CachedArray(64);
}
public initialize () {
this._cmdBuff = this._device.createCommandBuffer({
allocator: this._device.commandAllocator,
type: GFXCommandBufferType.PRIMARY,
});
return true;
}
public destroy () {
// this._reset();
if (this._cmdBuff) {
this._cmdBuff.destroy();
this._cmdBuff = null;
}
}
public addScreen (comp) {
@@ -39,15 +69,42 @@ export class UI {
}
public update (dt: number) {
const models = this._emit();
this._render(models);
this._items.clear();
// TODO: Merge batch here.
this.render();
}
private _emit (): UIBatchModel[] {
return this._batchedModels;
}
private _render (models: UIBatchModel[]) {
private render () {
if (this._items.length) {
const framebuffer = this._root.curWindow!.framebuffer;
const cmdBuff = this._cmdBuff!;
cmdBuff.begin();
for (let i = 0; i < this._items.length; ++i) {
const item = this._items.array[i];
const camera = item.camera;
this._renderArea.width = camera.width;
this._renderArea.height = camera.height;
cmdBuff.beginRenderPass(framebuffer, this._renderArea,
[camera.clearColor], camera.clearDepth, camera.clearStencil);
cmdBuff.execute([item.cmdBuff], 1);
cmdBuff.endRenderPass();
}
cmdBuff.end();
this._device.queue.submit([cmdBuff]);
}
}
}