diff --git a/cocos/core/root.ts b/cocos/core/root.ts index e9496722b4..3e73cb8f83 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -3,12 +3,13 @@ import { GFXWindow, IGFXWindowInfo } from '../gfx/window'; import { ForwardPipeline } from '../pipeline/forward/forward-pipeline'; import { RenderPipeline } from '../pipeline/render-pipeline'; import { IRenderViewInfo, RenderView } from '../pipeline/render-view'; -import { GUI } from '../renderer/gui/gui'; import { IRenderSceneInfo, RenderScene } from '../renderer/scene/render-scene'; +import { UI } from '../renderer/ui/ui'; export let _createSceneFun; export let _createViewFun; +// tslint:disable-next-line:no-empty-interface export interface IRootInfo { } @@ -34,8 +35,8 @@ export class Root { return this._pipeline as RenderPipeline; } - public get gui (): GUI { - return this._gui as GUI; + public get ui (): UI { + return this._ui as UI; } public get scenes (): RenderScene[] { @@ -57,7 +58,7 @@ export class Root { private _windows: GFXWindow[] = []; private _mainWindow: GFXWindow | null = null; private _pipeline: RenderPipeline | null = null; - private _gui: GUI | null = null; + private _ui: UI | null = null; private _scenes: RenderScene[] = []; private _views: RenderView[] = []; private _frameTime: number = 0; @@ -79,12 +80,17 @@ export class Root { const pipeline = new ForwardPipeline(this); if (!pipeline.initialize()) { + this.destroy(); return false; } this._pipeline = pipeline; - this._gui = new GUI(this); + this._ui = new UI(this); + if (!this._ui.initialize()) { + this.destroy(); + return false; + } return true; } @@ -97,6 +103,11 @@ export class Root { this._pipeline.destroy(); this._pipeline = null; } + + if (this._ui) { + this._ui.destroy(); + this._ui = null; + } } public frameMove (deltaTime: number) { @@ -106,6 +117,7 @@ export class Root { for (const view of this._views) { if (view.isEnable()) { ( this._pipeline as RenderPipeline).render(view); + ( this._ui as UI).render(view); } } diff --git a/cocos/gfx/webgl/webgl-gpu-objects.ts b/cocos/gfx/webgl/webgl-gpu-objects.ts index 6691d777e0..ddd993a09c 100644 --- a/cocos/gfx/webgl/webgl-gpu-objects.ts +++ b/cocos/gfx/webgl/webgl-gpu-objects.ts @@ -43,16 +43,6 @@ export class WebGLGPUObject { } } -export interface IWebGLIndirectBuffer { - vertexCount: number; - firstVertex: number; - indexCount: number; - firstIndex: number; - vertexOffset: number; - instanceCount: number; - firstInstance: number; -} - export class WebGLGPUBuffer extends WebGLGPUObject { public usage: GFXBufferUsage = GFXBufferUsageBit.NONE; public memUsage: GFXMemoryUsage = GFXMemoryUsageBit.NONE; diff --git a/cocos/renderer/gui/gui.ts b/cocos/renderer/gui/gui.ts deleted file mode 100644 index 9e1f0a59a4..0000000000 --- a/cocos/renderer/gui/gui.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Root } from '../../core/root'; -import { RenderScene } from '../scene/render-scene'; -import { RenderView } from '../../pipeline/render-view'; - -export class GUI { - - public get root (): Root { - return this._root; - } - - public get scene (): RenderScene { - return this._scene; - } - - private _root: Root; - private _scene: RenderScene; - - constructor (root: Root) { - this._root = root; - this._scene = this._root.createScene({ - name: 'GUIScene', - }); - } - - public render (view: RenderView) { - - } -} diff --git a/cocos/renderer/ui/label-widget.ts b/cocos/renderer/ui/label-widget.ts new file mode 100644 index 0000000000..df34264fb5 --- /dev/null +++ b/cocos/renderer/ui/label-widget.ts @@ -0,0 +1,13 @@ +import { UI } from './ui'; +import { UIWidget, UIWidgetType } from './ui-widget'; + +export class LabelWidget extends UIWidget { + + constructor (ui: UI) { + super(ui, UIWidgetType.LABEL); + } + + public update () { + + } +} diff --git a/cocos/renderer/ui/ui-widget.ts b/cocos/renderer/ui/ui-widget.ts new file mode 100644 index 0000000000..8cd54ed5a8 --- /dev/null +++ b/cocos/renderer/ui/ui-widget.ts @@ -0,0 +1,25 @@ +import { UI } from './ui'; + +export enum UIWidgetType { + LABEL, + SPRITE, +} + +export abstract class UIWidget { + + protected _ui: UI; + protected _type: UIWidgetType; + protected _vertices: Float32Array | null = null; + protected _indices: Uint16Array | null = null; + + constructor (ui: UI, type: UIWidgetType) { + this._ui = ui; + this._type = type; + } + + public type (): UIWidgetType { + return this._type; + } + + public abstract update (); +} diff --git a/cocos/renderer/ui/ui.ts b/cocos/renderer/ui/ui.ts new file mode 100644 index 0000000000..00fd85d0ac --- /dev/null +++ b/cocos/renderer/ui/ui.ts @@ -0,0 +1,57 @@ +import { Root } from '../../core/root'; +import { RenderView } from '../../pipeline/render-view'; +import { RenderScene } from '../scene/render-scene'; +import { UIWidget } from './ui-widget'; + +export class UI { + + public get root (): Root { + return this._root; + } + + public get scene (): RenderScene { + return this._scene; + } + + private _root: Root; + private _scene: RenderScene; + private _widgets: UIWidget[] = []; + + constructor (root: Root) { + this._root = root; + this._scene = this._root.createScene({ + name: 'GUIScene', + }); + } + + public initialize (): boolean { + return true; + } + + public destroy () { + this.destroyWidgets(); + } + + public render (view: RenderView) { + + } + + public createWidget (clazz: new () => T): T { + const widget = new clazz(); + this._widgets.push(widget); + return widget; + } + + public destroyWidget (widget: UIWidget) { + for (let i = 0; i < this._widgets.length; ++i) { + if (this._widgets[i] === widget) { + this._widgets.splice(i); + return; + } + } + } + + public destroyWidgets () { + this._widgets = []; + } +}