From 1dca42f7fb5c79c3533aece45b58493248e5b1d3 Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Thu, 10 Jan 2019 14:52:54 +0800 Subject: [PATCH] remove null return-value from GFXDevice.createXXX interfaces, add GFXStatus to GFXObject --- cocos/core/root.ts | 146 ++++++++++---------- cocos/gfx/binding-layout.ts | 5 +- cocos/gfx/buffer.ts | 5 +- cocos/gfx/command-allocator.ts | 4 +- cocos/gfx/command-buffer.ts | 5 +- cocos/gfx/define.ts | 43 ++++++ cocos/gfx/device.ts | 30 ++--- cocos/gfx/framebuffer.ts | 4 +- cocos/gfx/input-assembler.ts | 5 +- cocos/gfx/pipeline-layout.ts | 5 +- cocos/gfx/pipeline-state.ts | 5 +- cocos/gfx/queue.ts | 5 +- cocos/gfx/render-pass.ts | 5 +- cocos/gfx/sampler.ts | 5 +- cocos/gfx/shader.ts | 5 +- cocos/gfx/texture-view.ts | 5 +- cocos/gfx/texture.ts | 5 +- cocos/gfx/webgl/webgl-binding-layout.ts | 4 + cocos/gfx/webgl/webgl-buffer.ts | 4 +- cocos/gfx/webgl/webgl-command-allocator.ts | 4 +- cocos/gfx/webgl/webgl-command-buffer.ts | 4 +- cocos/gfx/webgl/webgl-device.ts | 150 +++++++-------------- cocos/gfx/webgl/webgl-framebuffer.ts | 3 + cocos/gfx/webgl/webgl-input-assembler.ts | 3 + cocos/gfx/webgl/webgl-pipeline-layout.ts | 3 + cocos/gfx/webgl/webgl-pipeline-state.ts | 3 + cocos/gfx/webgl/webgl-queue.ts | 4 +- cocos/gfx/webgl/webgl-render-pass.ts | 3 + cocos/gfx/webgl/webgl-sampler.ts | 3 + cocos/gfx/webgl/webgl-shader.ts | 3 + cocos/gfx/webgl/webgl-texture-view.ts | 3 + cocos/gfx/webgl/webgl-texture.ts | 5 +- cocos/gfx/webgl/webgl-window.ts | 5 +- cocos/gfx/window.ts | 17 +-- cocos/pipeline/forward/forward-flow.ts | 24 ++-- cocos/pipeline/forward/forward-pipeline.ts | 11 +- cocos/pipeline/forward/forward-stage.ts | 34 +++-- cocos/pipeline/forward/test-model-stage.ts | 3 +- cocos/pipeline/render-view.ts | 139 ++++++++++--------- cocos/renderer/scene/model.ts | 71 +++++----- cocos/renderer/scene/render-scene.ts | 149 ++++++++++---------- cocos/scene-graph/scene.js | 3 +- 42 files changed, 503 insertions(+), 439 deletions(-) diff --git a/cocos/core/root.ts b/cocos/core/root.ts index c42b2019da..4bf75dd063 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -1,24 +1,65 @@ -import { GFXWindow, IGFXWindowInfo } from "../gfx/window"; -import { GFXDevice } from "../gfx/device"; -import { RenderView, RenderViewInfo } from "../pipeline/render-view"; -import { RenderPipeline } from "../pipeline/render-pipeline"; -import { ForwardPipeline } from "../pipeline/forward/forward-pipeline"; -import { RenderScene, RenderSceneInfo } from "../renderer/scene/render-scene"; +import { GFXDevice } from '../gfx/device'; +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 { IRenderSceneInfo, RenderScene } from '../renderer/scene/render-scene'; -export interface RootInfo { -}; +export let _createSceneFun; +export let _createViewFun; -export interface SceneInfo { +export interface IRootInfo { +} + +export interface ISceneInfo { name: string; -}; +} export class Root { - constructor(device: GFXDevice) { - this._device = device; + public get device (): GFXDevice { + return this._device; } - public initialize(info: RootInfo): boolean { + public get mainWindow (): GFXWindow | null { + return this._mainWindow; + } + + public get pipeline (): RenderPipeline | null { + return this._pipeline; + } + + public get scenes (): RenderScene[] { + return this._scenes; + } + + public get views (): RenderView[] { + return this._views; + } + + public get frameTime (): number { + return this._frameTime; + } + + public _createSceneFun; + public _createViewFun; + + private _device: GFXDevice; + private _windows: GFXWindow[] = []; + private _mainWindow: GFXWindow | null = null; + private _pipeline: RenderPipeline | null = null; + private _scenes: RenderScene[] = []; + private _views: RenderView[] = []; + private _frameTime: number = 0; + + constructor (device: GFXDevice) { + this._device = device; + + RenderScene.registerCreateFunc(this); + RenderView.registerCreateFunc(this); + } + + public initialize (info: IRootInfo): boolean { if (!this._device.mainWindow) { return false; @@ -26,7 +67,7 @@ export class Root { this._mainWindow = this._device.mainWindow; - let pipeline = new ForwardPipeline(this); + const pipeline = new ForwardPipeline(this); if (!pipeline.initialize()) { return false; } @@ -36,7 +77,7 @@ export class Root { return true; } - public destroy() { + public destroy () { this.destroyViews(); this.destroyScenes(); @@ -46,23 +87,22 @@ export class Root { } } - public frameMove(deltaTime: number) { + public frameMove (deltaTime: number) { this._frameTime = deltaTime; - for (let i = 0; i < this._views.length; ++i) { - let view = this._views[i]; + for (const view of this._views) { if (view.isEnable() && view.isAttached) { - (this._pipeline).render(view); + ( this._pipeline as RenderPipeline).render(view); } } - (this._device).present(); + ( this._device as GFXDevice).present(); } - public createWindow(info: IGFXWindowInfo): GFXWindow | null { + public createWindow (info: IGFXWindowInfo): GFXWindow | null { if (this._device) { - let window = this._device.createWindow(info); + const window = this._device.createWindow(info); if (window) { this._windows.push(window); return window; @@ -72,7 +112,7 @@ export class Root { return null; } - public destroyWindow(window: GFXWindow) { + public destroyWindow (window: GFXWindow) { for (let i = 0; i < this._windows.length; ++i) { if (this._windows[i] === window) { window.destroy(); @@ -82,15 +122,15 @@ export class Root { } } - public destroyWindows() { - for (let i = 0; i < this._windows.length; ++i) { - this._windows[i].destroy(); + public destroyWindows () { + for (const window of this._windows) { + window.destroy(); } this._windows = []; } - public createScene(info: RenderSceneInfo): RenderScene | null { - let scene = new RenderScene(this); + public createScene (info: IRenderSceneInfo): RenderScene | null { + const scene = this._createSceneFun(this); if (scene.initialize(info)) { this._scenes.push(scene); return scene; @@ -99,7 +139,7 @@ export class Root { } } - public destroyScene(scene: RenderScene) { + public destroyScene (scene: RenderScene) { for (let i = 0; i < this._scenes.length; ++i) { if (this._scenes[i] === scene) { scene.destroy(); @@ -109,15 +149,15 @@ export class Root { } } - public destroyScenes() { - for (let i = 0; i < this._scenes.length; ++i) { - this._scenes[i].destroy(); + public destroyScenes () { + for (const scene of this._scenes) { + scene.destroy(); } this._scenes = []; } - public createView(info: RenderViewInfo): RenderView | null { - let view = new RenderView; + public createView (info: IRenderViewInfo): RenderView | null { + const view = this._createViewFun(this); if (view.initialize(info)) { this._views.push(view); this._views.sort((a: RenderView, b: RenderView) => { @@ -129,7 +169,7 @@ export class Root { } } - public destroyView(view: RenderView) { + public destroyView (view: RenderView) { for (let i = 0; i < this._views.length; ++i) { if (this._views[i] === view) { this._views.splice(i); @@ -138,42 +178,10 @@ export class Root { } } - public destroyViews() { + public destroyViews () { for (let i = 0; i < this._views.length; ++i) { this._views[i].destroy(); } this._views = []; } - - public get device(): GFXDevice { - return this._device; - } - - public get mainWindow(): GFXWindow | null { - return this._mainWindow; - } - - public get pipeline(): RenderPipeline | null { - return this._pipeline; - } - - public get scenes(): RenderScene[] { - return this._scenes; - } - - public get views(): RenderView[] { - return this._views; - } - - public get frameTime(): number { - return this._frameTime; - } - - private _device: GFXDevice; - private _windows: GFXWindow[] = []; - private _mainWindow: GFXWindow | null = null; - private _pipeline: RenderPipeline | null = null; - private _scenes: RenderScene[] = []; - private _views: RenderView[] = []; - private _frameTime: number = 0; -}; +} diff --git a/cocos/gfx/binding-layout.ts b/cocos/gfx/binding-layout.ts index cb591daa98..d922b4fe2a 100644 --- a/cocos/gfx/binding-layout.ts +++ b/cocos/gfx/binding-layout.ts @@ -1,5 +1,5 @@ import { GFXBuffer } from './buffer'; -import { GFXBindingType } from './define'; +import { GFXBindingType, GFXObject, GFXObjectType } from './define'; import { GFXDevice } from './device'; import { GFXSampler } from './sampler'; import { GFXTextureView } from './texture-view'; @@ -23,13 +23,14 @@ export class GFXBindingUnit { public sampler: GFXSampler | null = null; } -export abstract class GFXBindingLayout { +export abstract class GFXBindingLayout extends GFXObject { protected _device: GFXDevice; protected _bindingUnits: GFXBindingUnit[] = []; protected _isDirty = false; constructor (device: GFXDevice) { + super(GFXObjectType.BINDING_LAYOUT); this._device = device; } diff --git a/cocos/gfx/buffer.ts b/cocos/gfx/buffer.ts index 58a9cb0518..957b756227 100644 --- a/cocos/gfx/buffer.ts +++ b/cocos/gfx/buffer.ts @@ -1,4 +1,4 @@ -import { GFXBufferUsage, GFXBufferUsageBit, GFXMemoryUsage, GFXMemoryUsageBit } from './define'; +import { GFXBufferUsage, GFXBufferUsageBit, GFXMemoryUsage, GFXMemoryUsageBit, GFXObject, GFXObjectType } from './define'; import { GFXDevice } from './device'; export interface IGFXBufferInfo { @@ -8,7 +8,7 @@ export interface IGFXBufferInfo { stride?: number; } -export abstract class GFXBuffer { +export abstract class GFXBuffer extends GFXObject { public get usage (): GFXBufferUsage { return this._usage; @@ -39,6 +39,7 @@ export abstract class GFXBuffer { protected _bufferView: Uint8Array | null = null; constructor (device: GFXDevice) { + super(GFXObjectType.BUFFER); this._device = device; } diff --git a/cocos/gfx/command-allocator.ts b/cocos/gfx/command-allocator.ts index 2fd580eed8..56a96506d3 100644 --- a/cocos/gfx/command-allocator.ts +++ b/cocos/gfx/command-allocator.ts @@ -1,13 +1,15 @@ +import { GFXObject, GFXObjectType } from './define'; import { GFXDevice } from './device'; export interface IGFXCommandAllocatorInfo { } -export abstract class GFXCommandAllocator { +export abstract class GFXCommandAllocator extends GFXObject { protected _device: GFXDevice; constructor (device: GFXDevice) { + super(GFXObjectType.COMMAND_ALLOCATOR); this._device = device; } diff --git a/cocos/gfx/command-buffer.ts b/cocos/gfx/command-buffer.ts index 142474ccbe..7f7f25276f 100644 --- a/cocos/gfx/command-buffer.ts +++ b/cocos/gfx/command-buffer.ts @@ -1,7 +1,7 @@ import { GFXBindingLayout } from './binding-layout'; import { GFXBuffer } from './buffer'; import { GFXCommandAllocator } from './command-allocator'; -import { GFXBufferTextureCopy, GFXCommandBufferType, GFXTextureLayout, IGFXColor, IGFXRect } from './define'; +import { GFXBufferTextureCopy, GFXCommandBufferType, GFXObject, GFXObjectType, GFXTextureLayout, IGFXColor, IGFXRect } from './define'; import { GFXDevice } from './device'; import { GFXFramebuffer } from './framebuffer'; import { GFXInputAssembler } from './input-assembler'; @@ -13,7 +13,7 @@ export interface IGFXCommandBufferInfo { type: GFXCommandBufferType; } -export abstract class GFXCommandBuffer { +export abstract class GFXCommandBuffer extends GFXObject { public get type (): number { return this._type; @@ -24,6 +24,7 @@ export abstract class GFXCommandBuffer { protected _type: GFXCommandBufferType = GFXCommandBufferType.PRIMARY; constructor (device: GFXDevice) { + super(GFXObjectType.COMMAND_BUFFER); this._device = device; } diff --git a/cocos/gfx/define.ts b/cocos/gfx/define.ts index edb48d1f32..d1b0317d0e 100644 --- a/cocos/gfx/define.ts +++ b/cocos/gfx/define.ts @@ -22,6 +22,49 @@ export const GFX_MAX_VERTEX_ATTRIBUTES: number = 16; export const GFX_MAX_TEXTURE_UNITS: number = 16; export const GFX_MAX_ATTACHMENTS: number = 4; +export enum GFXObjectType { + UNKNOWN, + BUFFER, + TEXTURE, + TEXTURE_VIEW, + RENDER_PASS, + FRAMEBUFFER, + SAMPLER, + SHADER, + PIPELINE_LAYOUT, + PIPELINE_STATE, + BINDING_LAYOUT, + INPUT_ASSEMBLER, + COMMAND_ALLOCATOR, + COMMAND_BUFFER, + QUEUE, + WINDOW, +} + +export enum GFXStatus { + UNREADY, + FAILED, + SUCCESS, +} + +export class GFXObject { + + public get gfxType (): GFXObjectType { + return this._gfxType; + } + + public get status (): GFXStatus { + return this._status; + } + + protected _gfxType = GFXObjectType.UNKNOWN; + protected _status = GFXStatus.UNREADY; + + constructor (gfxType: GFXObjectType) { + this._gfxType = gfxType; + } +} + export enum GFXType { UNKNOWN, BOOL, diff --git a/cocos/gfx/device.ts b/cocos/gfx/device.ts index 8d118b7d59..5b5de3bb6c 100644 --- a/cocos/gfx/device.ts +++ b/cocos/gfx/device.ts @@ -122,21 +122,21 @@ export abstract class GFXDevice { public abstract initialize (info: IGFXDeviceInfo): boolean; public abstract destroy (): void; - public abstract createBuffer (info: IGFXBufferInfo): GFXBuffer | null; - public abstract createTexture (info: IGFXTextureInfo): GFXTexture | null; - public abstract createTextureView (info: IGFXTextureViewInfo): GFXTextureView | null; - public abstract createSampler (info: IGFXSamplerInfo): GFXSampler | null; - public abstract createBindingLayout (info: IGFXBindingLayoutInfo): GFXBindingLayout | null; - public abstract createShader (info: IGFXShaderInfo): GFXShader | null; - public abstract createInputAssembler (info: IGFXInputAssemblerInfo): GFXInputAssembler | null; - public abstract createRenderPass (info: IGFXRenderPassInfo): GFXRenderPass | null; - public abstract createFramebuffer (info: IGFXFramebufferInfo): GFXFramebuffer | null; - public abstract createPipelineLayout (info: IGFXPipelineLayoutInfo): GFXPipelineLayout | null; - public abstract createPipelineState (info: IGFXPipelineStateInfo): GFXPipelineState | null; - public abstract createCommandAllocator (info: IGFXCommandAllocatorInfo): GFXCommandAllocator | null; - public abstract createCommandBuffer (info: IGFXCommandBufferInfo): GFXCommandBuffer | null; - public abstract createQueue (info: IGFXQueueInfo): GFXQueue | null; - public abstract createWindow (info: IGFXWindowInfo): GFXWindow | null; + public abstract createBuffer (info: IGFXBufferInfo): GFXBuffer; + public abstract createTexture (info: IGFXTextureInfo): GFXTexture; + public abstract createTextureView (info: IGFXTextureViewInfo): GFXTextureView; + public abstract createSampler (info: IGFXSamplerInfo): GFXSampler; + public abstract createBindingLayout (info: IGFXBindingLayoutInfo): GFXBindingLayout; + public abstract createShader (info: IGFXShaderInfo): GFXShader; + public abstract createInputAssembler (info: IGFXInputAssemblerInfo): GFXInputAssembler; + public abstract createRenderPass (info: IGFXRenderPassInfo): GFXRenderPass; + public abstract createFramebuffer (info: IGFXFramebufferInfo): GFXFramebuffer; + public abstract createPipelineLayout (info: IGFXPipelineLayoutInfo): GFXPipelineLayout; + public abstract createPipelineState (info: IGFXPipelineStateInfo): GFXPipelineState; + public abstract createCommandAllocator (info: IGFXCommandAllocatorInfo): GFXCommandAllocator; + public abstract createCommandBuffer (info: IGFXCommandBufferInfo): GFXCommandBuffer; + public abstract createQueue (info: IGFXQueueInfo): GFXQueue; + public abstract createWindow (info: IGFXWindowInfo): GFXWindow; public abstract present (); public abstract copyBufferToTexture (buffer: ArrayBuffer, texture: GFXTexture, regions: GFXBufferTextureCopy[]); diff --git a/cocos/gfx/framebuffer.ts b/cocos/gfx/framebuffer.ts index e20a240b7a..f9a3729389 100644 --- a/cocos/gfx/framebuffer.ts +++ b/cocos/gfx/framebuffer.ts @@ -1,3 +1,4 @@ +import { GFXObject, GFXObjectType } from './define'; import { GFXDevice } from './device'; import { GFXRenderPass } from './render-pass'; import { GFXTextureView } from './texture-view'; @@ -9,7 +10,7 @@ export interface IGFXFramebufferInfo { isOffscreen?: boolean; } -export abstract class GFXFramebuffer { +export abstract class GFXFramebuffer extends GFXObject { public get renderPass (): GFXRenderPass | null { return this._renderPass; @@ -34,6 +35,7 @@ export abstract class GFXFramebuffer { protected _isOffscreen: boolean = true; constructor (device: GFXDevice) { + super(GFXObjectType.FRAMEBUFFER); this._device = device; } diff --git a/cocos/gfx/input-assembler.ts b/cocos/gfx/input-assembler.ts index b17caeb8c1..1baca3e5e0 100644 --- a/cocos/gfx/input-assembler.ts +++ b/cocos/gfx/input-assembler.ts @@ -1,5 +1,5 @@ import { GFXBuffer } from './buffer'; -import { GFXFormat } from './define'; +import { GFXFormat, GFXObject, GFXObjectType } from './define'; import { GFXDevice } from './device'; export interface IGFXInputAttribute { @@ -18,7 +18,7 @@ export interface IGFXInputAssemblerInfo { isIndirect?: boolean; } -export abstract class GFXInputAssembler { +export abstract class GFXInputAssembler extends GFXObject { public get vertexBuffers (): GFXBuffer[] { return this._vertexBuffers; @@ -102,6 +102,7 @@ export abstract class GFXInputAssembler { protected _isIndirect: boolean = false; constructor (device: GFXDevice) { + super(GFXObjectType.INPUT_ASSEMBLER); this._device = device; } diff --git a/cocos/gfx/pipeline-layout.ts b/cocos/gfx/pipeline-layout.ts index 7137bced05..b1a26fefc1 100644 --- a/cocos/gfx/pipeline-layout.ts +++ b/cocos/gfx/pipeline-layout.ts @@ -1,5 +1,5 @@ import { GFXBindingLayout } from './binding-layout'; -import { GFXShaderType } from './define'; +import { GFXObject, GFXObjectType, GFXShaderType } from './define'; import { GFXDevice } from './device'; export interface IGFXPushConstantRange { @@ -13,13 +13,14 @@ export interface IGFXPipelineLayoutInfo { layouts: GFXBindingLayout[]; } -export abstract class GFXPipelineLayout { +export abstract class GFXPipelineLayout extends GFXObject { protected _device: GFXDevice; protected _pushConstantsRanges: IGFXPushConstantRange[] = []; protected _layouts: GFXBindingLayout[] = []; constructor (device: GFXDevice) { + super(GFXObjectType.PIPELINE_LAYOUT); this._device = device; } diff --git a/cocos/gfx/pipeline-state.ts b/cocos/gfx/pipeline-state.ts index c2d22276ce..b854d4b7e7 100644 --- a/cocos/gfx/pipeline-state.ts +++ b/cocos/gfx/pipeline-state.ts @@ -1,4 +1,4 @@ -import { GFXBlendFactor, GFXBlendOp, GFXColorMask, GFXComparisonFunc, GFXCullMode, GFXPolygonMode, GFXPrimitiveMode, GFXShadeModel, GFXStencilOp } from './define'; +import { GFXBlendFactor, GFXBlendOp, GFXColorMask, GFXComparisonFunc, GFXCullMode, GFXObject, GFXObjectType, GFXPolygonMode, GFXPrimitiveMode, GFXShadeModel, GFXStencilOp } from './define'; import { GFXDevice } from './device'; import { IGFXInputAttribute } from './input-assembler'; import { GFXPipelineLayout } from './pipeline-layout'; @@ -119,7 +119,7 @@ export interface IGFXPipelineStateInfo { renderPass: GFXRenderPass; } -export abstract class GFXPipelineState { +export abstract class GFXPipelineState extends GFXObject { public get shader (): GFXShader { return this._shader as GFXShader; @@ -160,6 +160,7 @@ export abstract class GFXPipelineState { protected _renderPass: GFXRenderPass | null = null; constructor (device: GFXDevice) { + super(GFXObjectType.PIPELINE_STATE); this._device = device; } diff --git a/cocos/gfx/queue.ts b/cocos/gfx/queue.ts index 0c11f60b2a..a13c31a3cd 100644 --- a/cocos/gfx/queue.ts +++ b/cocos/gfx/queue.ts @@ -1,12 +1,12 @@ import { GFXCommandBuffer } from './command-buffer'; -import { GFXQueueType } from './define'; +import { GFXObject, GFXObjectType, GFXQueueType } from './define'; import { GFXDevice } from './device'; export interface IGFXQueueInfo { type: GFXQueueType; } -export abstract class GFXQueue { +export abstract class GFXQueue extends GFXObject { public get type (): number { return this._type; @@ -16,6 +16,7 @@ export abstract class GFXQueue { protected _type: GFXQueueType = GFXQueueType.GRAPHICS; constructor (device: GFXDevice) { + super(GFXObjectType.QUEUE); this._device = device; } diff --git a/cocos/gfx/render-pass.ts b/cocos/gfx/render-pass.ts index 23250bb97e..548dc7e567 100644 --- a/cocos/gfx/render-pass.ts +++ b/cocos/gfx/render-pass.ts @@ -1,4 +1,4 @@ -import { GFXFormat, GFXLoadOp, GFXPipelineBindPoint, GFXStoreOp, GFXTextureLayout } from './define'; +import { GFXFormat, GFXLoadOp, GFXObject, GFXObjectType, GFXPipelineBindPoint, GFXStoreOp, GFXTextureLayout } from './define'; import { GFXDevice } from './device'; export class GFXColorAttachment { @@ -36,13 +36,14 @@ export interface IGFXRenderPassInfo { // subPasses? : GFXSubPassInfo[]; } -export abstract class GFXRenderPass { +export abstract class GFXRenderPass extends GFXObject { protected _device: GFXDevice; protected _colorInfos: GFXColorAttachment[] = []; protected _depthStencilInfo: GFXDepthStencilAttachment | null = null; constructor (device: GFXDevice) { + super(GFXObjectType.RENDER_PASS); this._device = device; } diff --git a/cocos/gfx/sampler.ts b/cocos/gfx/sampler.ts index c1647abdf9..6d0afc5e89 100644 --- a/cocos/gfx/sampler.ts +++ b/cocos/gfx/sampler.ts @@ -1,4 +1,4 @@ -import { GFXAddress, GFXComparisonFunc, GFXFilter } from './define'; +import { GFXAddress, GFXComparisonFunc, GFXFilter, GFXObject, GFXObjectType } from './define'; import { GFXDevice } from './device'; export interface IGFXSamplerInfo { @@ -48,7 +48,7 @@ export class GFXSamplerState { } } -export abstract class GFXSampler { +export abstract class GFXSampler extends GFXObject { public get state (): GFXSamplerState { return this._state; @@ -58,6 +58,7 @@ export abstract class GFXSampler { protected _state: GFXSamplerState = new GFXSamplerState(); constructor (device: GFXDevice) { + super(GFXObjectType.SAMPLER); this._device = device; } diff --git a/cocos/gfx/shader.ts b/cocos/gfx/shader.ts index 02e21132a0..4059d228b6 100644 --- a/cocos/gfx/shader.ts +++ b/cocos/gfx/shader.ts @@ -1,4 +1,4 @@ -import { GFXShaderType, GFXType } from './define'; +import { GFXObject, GFXObjectType, GFXShaderType, GFXType } from './define'; import { GFXDevice } from './device'; export interface IGFXShaderMacro { @@ -41,7 +41,7 @@ export interface IGFXShaderInfo { samplers?: GFXUniformSampler[]; } -export abstract class GFXShader { +export abstract class GFXShader extends GFXObject { public get id (): number { return this._id; @@ -56,6 +56,7 @@ export abstract class GFXShader { protected _samplers: GFXUniformSampler[] = []; constructor (device: GFXDevice) { + super(GFXObjectType.SHADER); this._device = device; this._id = device.genShaderId(); } diff --git a/cocos/gfx/texture-view.ts b/cocos/gfx/texture-view.ts index f6e026d82c..6b19137200 100644 --- a/cocos/gfx/texture-view.ts +++ b/cocos/gfx/texture-view.ts @@ -1,4 +1,4 @@ -import { GFXFormat, GFXTextureViewType } from './define'; +import { GFXFormat, GFXObject, GFXObjectType, GFXTextureViewType } from './define'; import { GFXDevice } from './device'; import { GFXTexture } from './texture'; @@ -12,7 +12,7 @@ export interface IGFXTextureViewInfo { layerCount?: number; } -export abstract class GFXTextureView { +export abstract class GFXTextureView extends GFXObject { public get texture (): GFXTexture { return this._texture as GFXTexture; @@ -52,6 +52,7 @@ export abstract class GFXTextureView { protected _layerCount: number = 1; constructor (device: GFXDevice) { + super(GFXObjectType.TEXTURE_VIEW); this._device = device; } diff --git a/cocos/gfx/texture.ts b/cocos/gfx/texture.ts index c3969b65dc..31954487b7 100644 --- a/cocos/gfx/texture.ts +++ b/cocos/gfx/texture.ts @@ -1,4 +1,4 @@ -import { GFXFormat, GFXTextureFlagBit, GFXTextureFlags, GFXTextureType, GFXTextureUsage, GFXTextureUsageBit } from './define'; +import { GFXFormat, GFXObject, GFXObjectType, GFXTextureFlagBit, GFXTextureFlags, GFXTextureType, GFXTextureUsage, GFXTextureUsageBit } from './define'; import { GFXDevice } from './device'; export interface IGFXTextureInfo { @@ -13,7 +13,7 @@ export interface IGFXTextureInfo { flags?: GFXTextureFlags; } -export abstract class GFXTexture { +export abstract class GFXTexture extends GFXObject { public get type (): GFXTextureType { return this._type; @@ -73,6 +73,7 @@ export abstract class GFXTexture { protected _buffer: ArrayBuffer | null = null; constructor (device: GFXDevice) { + super(GFXObjectType.TEXTURE); this._device = device; } diff --git a/cocos/gfx/webgl/webgl-binding-layout.ts b/cocos/gfx/webgl/webgl-binding-layout.ts index 2a661ef7f4..259cd84db3 100644 --- a/cocos/gfx/webgl/webgl-binding-layout.ts +++ b/cocos/gfx/webgl/webgl-binding-layout.ts @@ -1,4 +1,5 @@ import { GFXBindingLayout, GFXBindingUnit, IGFXBindingLayoutInfo } from '../binding-layout'; +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { WebGLGFXDevice } from './webgl-device'; import { WebGLGPUBindingLayout } from './webgl-gpu-objects'; @@ -35,6 +36,7 @@ export class WebGLGFXBindingLayout extends GFXBindingLayout { } this._gpuBindingLayout = this.webGLDevice.emitCmdCreateGPUBindingLayout(info); + this._status = GFXStatus.SUCCESS; return true; } @@ -44,6 +46,8 @@ export class WebGLGFXBindingLayout extends GFXBindingLayout { this.webGLDevice.emitCmdDestroyGPUBindingLayout(this._gpuBindingLayout); this._gpuBindingLayout = null; } + + this._status = GFXStatus.UNREADY; } public update () { diff --git a/cocos/gfx/webgl/webgl-buffer.ts b/cocos/gfx/webgl/webgl-buffer.ts index 14d8d4c7bb..031c049fa7 100644 --- a/cocos/gfx/webgl/webgl-buffer.ts +++ b/cocos/gfx/webgl/webgl-buffer.ts @@ -1,5 +1,5 @@ import { GFXBuffer, IGFXBufferInfo } from '../buffer'; -import { GFXMemoryUsageBit } from '../define'; +import { GFXMemoryUsageBit, GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { WebGLGFXDevice } from './webgl-device'; import { WebGLGPUBuffer } from './webgl-gpu-objects'; @@ -38,6 +38,7 @@ export class WebGLGFXBuffer extends GFXBuffer { // this._isSimulate = (this._usage & GFXBufferUsageBit.TRANSFER_SRC) != GFXBufferUsageBit.NONE; this._gpuBuffer = this.webGLDevice.emitCmdCreateGPUBuffer(info, this._buffer); + this._status = GFXStatus.SUCCESS; return true; } @@ -50,6 +51,7 @@ export class WebGLGFXBuffer extends GFXBuffer { this._buffer = null; this._bufferView = null; + this._status = GFXStatus.UNREADY; } public update (buffer: ArrayBuffer, offset?: number) { diff --git a/cocos/gfx/webgl/webgl-command-allocator.ts b/cocos/gfx/webgl/webgl-command-allocator.ts index f5ea380c72..d103695b51 100644 --- a/cocos/gfx/webgl/webgl-command-allocator.ts +++ b/cocos/gfx/webgl/webgl-command-allocator.ts @@ -1,4 +1,5 @@ import { GFXCommandAllocator, IGFXCommandAllocatorInfo } from '../command-allocator'; +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { WebGLCmdBeginRenderPass, WebGLCmdBindBindingLayout, WebGLCmdBindInputAssembler, WebGLCmdBindPipelineState, WebGLCmdCopyBufferToTexture, WebGLCmdDraw, WebGLCmdUpdateBuffer } from './webgl-commands'; @@ -70,10 +71,11 @@ export class WebGLGFXCommandAllocator extends GFXCommandAllocator { public initialize (info: IGFXCommandAllocatorInfo): boolean { + this._status = GFXStatus.SUCCESS; return true; } public destroy () { - + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-command-buffer.ts b/cocos/gfx/webgl/webgl-command-buffer.ts index 8aa6a42445..7c3b2363b7 100644 --- a/cocos/gfx/webgl/webgl-command-buffer.ts +++ b/cocos/gfx/webgl/webgl-command-buffer.ts @@ -1,7 +1,7 @@ import { GFXBindingLayout } from '../binding-layout'; import { GFXBuffer } from '../buffer'; import { GFXCommandBuffer, IGFXCommandBufferInfo } from '../command-buffer'; -import { GFXBufferTextureCopy, GFXTextureLayout, IGFXColor, IGFXRect, IGFXViewport } from '../define'; +import { GFXBufferTextureCopy, GFXStatus, GFXTextureLayout, IGFXColor, IGFXRect } from '../define'; import { GFXDevice } from '../device'; import { GFXFramebuffer } from '../framebuffer'; import { GFXInputAssembler } from '../input-assembler'; @@ -33,6 +33,7 @@ export class WebGLGFXCommandBuffer extends GFXCommandBuffer { this._allocator = info.allocator; this._type = info.type; + this._status = GFXStatus.SUCCESS; return true; } @@ -41,6 +42,7 @@ export class WebGLGFXCommandBuffer extends GFXCommandBuffer { if (this._allocator) { this.cmdPackage.clearCmds( this._allocator as WebGLGFXCommandAllocator); } + this._status = GFXStatus.UNREADY; } public begin () { diff --git a/cocos/gfx/webgl/webgl-device.ts b/cocos/gfx/webgl/webgl-device.ts index c450614744..d636823ef8 100644 --- a/cocos/gfx/webgl/webgl-device.ts +++ b/cocos/gfx/webgl/webgl-device.ts @@ -354,154 +354,94 @@ export class WebGLGFXDevice extends GFXDevice { this._webGLRC = null; } - public createBuffer (info: IGFXBufferInfo): GFXBuffer | null { + public createBuffer (info: IGFXBufferInfo): GFXBuffer { const buffer = new WebGLGFXBuffer(this); - if (buffer.initialize(info)) { - return buffer; - } else { - buffer.destroy(); - return null; - } + buffer.initialize(info); + return buffer; } - public createTexture (info: IGFXTextureInfo): GFXTexture | null { + public createTexture (info: IGFXTextureInfo): GFXTexture { const texture = new WebGLGFXTexture(this); - if (texture.initialize(info)) { - return texture; - } else { - texture.destroy(); - return null; - } + texture.initialize(info); + return texture; } - public createTextureView (info: IGFXTextureViewInfo): GFXTextureView | null { + public createTextureView (info: IGFXTextureViewInfo): GFXTextureView { const texView = new WebGLGFXTextureView(this); - if (texView.initialize(info)) { - return texView; - } else { - texView.destroy(); - return null; - } + texView.initialize(info); + return texView; } - public createSampler (info: IGFXSamplerInfo): GFXSampler | null { + public createSampler (info: IGFXSamplerInfo): GFXSampler { const sampler = new WebGLGFXSampler(this); - if (sampler.initialize(info)) { - return sampler; - } else { - sampler.destroy(); - return null; - } + sampler.initialize(info); + return sampler; } - public createBindingLayout (info: IGFXBindingLayoutInfo): GFXBindingLayout | null { + public createBindingLayout (info: IGFXBindingLayoutInfo): GFXBindingLayout { const bindingLayout = new WebGLGFXBindingLayout(this); - if (bindingLayout.initialize(info)) { - return bindingLayout; - } else { - bindingLayout.destroy(); - return null; - } + bindingLayout.initialize(info); + return bindingLayout; } - public createShader (info: IGFXShaderInfo): GFXShader | null { + public createShader (info: IGFXShaderInfo): GFXShader { const shader = new WebGLGFXShader(this); - if (shader.initialize(info)) { - return shader; - } else { - shader.destroy(); - return null; - } + shader.initialize(info); + return shader; } - public createInputAssembler (info: IGFXInputAssemblerInfo): GFXInputAssembler | null { + public createInputAssembler (info: IGFXInputAssemblerInfo): GFXInputAssembler { const inputAssembler = new WebGLGFXInputAssembler(this); - if (inputAssembler.initialize(info)) { - return inputAssembler; - } else { - inputAssembler.destroy(); - return null; - } + inputAssembler.initialize(info); + return inputAssembler; } - public createRenderPass (info: IGFXRenderPassInfo): GFXRenderPass | null { + public createRenderPass (info: IGFXRenderPassInfo): GFXRenderPass { const renderPass = new WebGLGFXRenderPass(this); - if (renderPass.initialize(info)) { - return renderPass; - } else { - renderPass.destroy(); - return null; - } + renderPass.initialize(info); + return renderPass; } - public createFramebuffer (info: IGFXFramebufferInfo): GFXFramebuffer | null { + public createFramebuffer (info: IGFXFramebufferInfo): GFXFramebuffer { const framebuffer = new WebGLGFXFramebuffer(this); - if (framebuffer.initialize(info)) { - return framebuffer; - } else { - framebuffer.destroy(); - return null; - } + framebuffer.initialize(info); + return framebuffer; } - public createPipelineLayout (info: IGFXPipelineLayoutInfo): GFXPipelineLayout | null { + public createPipelineLayout (info: IGFXPipelineLayoutInfo): GFXPipelineLayout { const pipelineLayout = new WebGLGFXPipelineLayout(this); - if (pipelineLayout.initialize(info)) { - return pipelineLayout; - } else { - pipelineLayout.destroy(); - return null; - } + pipelineLayout.initialize(info); + return pipelineLayout; } - public createPipelineState (info: IGFXPipelineStateInfo): GFXPipelineState | null { + public createPipelineState (info: IGFXPipelineStateInfo): GFXPipelineState { const pipelineState = new WebGLGFXPipelineState(this); - if (pipelineState.initialize(info)) { - return pipelineState; - } else { - pipelineState.destroy(); - return null; - } + pipelineState.initialize(info); + return pipelineState; } - public createCommandAllocator (info: IGFXCommandAllocatorInfo): GFXCommandAllocator | null { + public createCommandAllocator (info: IGFXCommandAllocatorInfo): GFXCommandAllocator { const cmdAllocator = new WebGLGFXCommandAllocator(this); - if (cmdAllocator.initialize(info)) { - return cmdAllocator; - } else { - cmdAllocator.destroy(); - return null; - } + cmdAllocator.initialize(info); + return cmdAllocator; } - public createCommandBuffer (info: IGFXCommandBufferInfo): GFXCommandBuffer | null { + public createCommandBuffer (info: IGFXCommandBufferInfo): GFXCommandBuffer { const cmdBuff = new WebGLGFXCommandBuffer(this); - if (cmdBuff.initialize(info)) { - return cmdBuff; - } else { - cmdBuff.destroy(); - return null; - } + cmdBuff.initialize(info); + return cmdBuff; } - public createQueue (info: IGFXQueueInfo): GFXQueue | null { + public createQueue (info: IGFXQueueInfo): GFXQueue { const queue = new WebGLGFXQueue(this); - if (queue.initialize(info)) { - return queue; - } else { - queue.destroy(); - return null; - } + queue.initialize(info); + return queue; } - public createWindow (info: IGFXWindowInfo): GFXWindow | null { + public createWindow (info: IGFXWindowInfo): GFXWindow { const window = new WebGLGFXWindow(this); - if (window.initialize(info)) { - return window; - } else { - window.destroy(); - return null; - } + window.initialize(info); + return window; } public present () { diff --git a/cocos/gfx/webgl/webgl-framebuffer.ts b/cocos/gfx/webgl/webgl-framebuffer.ts index 67d6152b9d..de35f53804 100644 --- a/cocos/gfx/webgl/webgl-framebuffer.ts +++ b/cocos/gfx/webgl/webgl-framebuffer.ts @@ -1,3 +1,4 @@ +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXFramebuffer, IGFXFramebufferInfo } from '../framebuffer'; import { WebGLGFXDevice } from './webgl-device'; @@ -31,6 +32,7 @@ export class WebGLGFXFramebuffer extends GFXFramebuffer { this._isOffscreen = info.isOffscreen !== undefined ? info.isOffscreen : true; this._gpuFramebuffer = this.webGLDevice.emitCmdCreateGPUFramebuffer(info); + this._status = GFXStatus.SUCCESS; return true; } @@ -41,5 +43,6 @@ export class WebGLGFXFramebuffer extends GFXFramebuffer { this.webGLDevice.emitCmdDestroyGPUFramebuffer(this._gpuFramebuffer); this._gpuFramebuffer = null; } + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-input-assembler.ts b/cocos/gfx/webgl/webgl-input-assembler.ts index 8973d9d33c..6da551bc93 100644 --- a/cocos/gfx/webgl/webgl-input-assembler.ts +++ b/cocos/gfx/webgl/webgl-input-assembler.ts @@ -1,3 +1,4 @@ +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXInputAssembler, IGFXInputAssemblerInfo } from '../input-assembler'; import { WebGLGFXDevice } from './webgl-device'; @@ -42,6 +43,7 @@ export class WebGLGFXInputAssembler extends GFXInputAssembler { } this._gpuInputAssembler = this.webGLDevice.emitCmdCreateGPUInputAssembler(info); + this._status = GFXStatus.SUCCESS; return true; } @@ -51,5 +53,6 @@ export class WebGLGFXInputAssembler extends GFXInputAssembler { this.webGLDevice.emitCmdDestroyGPUInputAssembler(this._gpuInputAssembler); this._gpuInputAssembler = null; } + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-pipeline-layout.ts b/cocos/gfx/webgl/webgl-pipeline-layout.ts index c085052818..c4c73fe4d8 100644 --- a/cocos/gfx/webgl/webgl-pipeline-layout.ts +++ b/cocos/gfx/webgl/webgl-pipeline-layout.ts @@ -1,3 +1,4 @@ +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXPipelineLayout, IGFXPipelineLayoutInfo } from '../pipeline-layout'; import { WebGLGFXDevice } from './webgl-device'; @@ -26,10 +27,12 @@ export class WebGLGFXPipelineLayout extends GFXPipelineLayout { if (info.pushConstantsRanges !== undefined) { this._pushConstantsRanges = info.pushConstantsRanges; } + this._status = GFXStatus.SUCCESS; return true; } public destroy () { + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-pipeline-state.ts b/cocos/gfx/webgl/webgl-pipeline-state.ts index b9072080c5..d3c3b8afe7 100644 --- a/cocos/gfx/webgl/webgl-pipeline-state.ts +++ b/cocos/gfx/webgl/webgl-pipeline-state.ts @@ -1,3 +1,4 @@ +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXPipelineState, IGFXPipelineStateInfo } from '../pipeline-state'; import { WebGLGFXDevice } from './webgl-device'; @@ -31,6 +32,7 @@ export class WebGLGFXPipelineState extends GFXPipelineState { this._renderPass = info.renderPass; this._gpuPipelineState = this.webGLDevice.emitCmdCreateGPUPipelineState(info); + this._status = GFXStatus.SUCCESS; return true; } @@ -40,5 +42,6 @@ export class WebGLGFXPipelineState extends GFXPipelineState { this.webGLDevice.emitCmdDestroyGPUPipelineState(this._gpuPipelineState); this._gpuPipelineState = null; } + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-queue.ts b/cocos/gfx/webgl/webgl-queue.ts index f9d2463943..99254b0777 100644 --- a/cocos/gfx/webgl/webgl-queue.ts +++ b/cocos/gfx/webgl/webgl-queue.ts @@ -1,4 +1,5 @@ import { GFXCommandBuffer } from '../command-buffer'; +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXQueue, IGFXQueueInfo } from '../queue'; import { WebGLGFXCommandBuffer } from './webgl-command-buffer'; @@ -16,12 +17,13 @@ export class WebGLGFXQueue extends GFXQueue { public initialize (info: IGFXQueueInfo): boolean { this._type = info.type; + this._status = GFXStatus.SUCCESS; return true; } public destroy () { - + this._status = GFXStatus.UNREADY; } public submit (cmdBuffs: GFXCommandBuffer[], fence?) { diff --git a/cocos/gfx/webgl/webgl-render-pass.ts b/cocos/gfx/webgl/webgl-render-pass.ts index 4fd5224035..b22c87f1b2 100644 --- a/cocos/gfx/webgl/webgl-render-pass.ts +++ b/cocos/gfx/webgl/webgl-render-pass.ts @@ -1,3 +1,4 @@ +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXRenderPass, IGFXRenderPassInfo } from '../render-pass'; import { WebGLGFXDevice } from './webgl-device'; @@ -30,6 +31,7 @@ export class WebGLGFXRenderPass extends GFXRenderPass { } this._gpuRenderPass = this.webGLDevice.emitCmdCreateGPURenderPass(info); + this._status = GFXStatus.SUCCESS; return true; } @@ -40,5 +42,6 @@ export class WebGLGFXRenderPass extends GFXRenderPass { this.webGLDevice.emitCmdDestroyGPURenderPass(this._gpuRenderPass); this._gpuRenderPass = null; } + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-sampler.ts b/cocos/gfx/webgl/webgl-sampler.ts index 4f6d375535..1ff41e8869 100644 --- a/cocos/gfx/webgl/webgl-sampler.ts +++ b/cocos/gfx/webgl/webgl-sampler.ts @@ -1,3 +1,4 @@ +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXSampler, GFXSamplerState, IGFXSamplerInfo } from '../sampler'; import { WebGLGFXDevice } from './webgl-device'; @@ -76,6 +77,7 @@ export class WebGLGFXSampler extends GFXSampler { } this._gpuSampler = this.webGLDevice.emitCmdCreateGPUSampler(info); + this._status = GFXStatus.SUCCESS; return true; } @@ -85,5 +87,6 @@ export class WebGLGFXSampler extends GFXSampler { this.webGLDevice.emitCmdDestroyGPUSampler(this._gpuSampler); this._gpuSampler = null; } + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-shader.ts b/cocos/gfx/webgl/webgl-shader.ts index 3aefb658b7..bcdc1e015e 100644 --- a/cocos/gfx/webgl/webgl-shader.ts +++ b/cocos/gfx/webgl/webgl-shader.ts @@ -1,3 +1,4 @@ +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXShader, IGFXShaderInfo } from '../shader'; import { WebGLGFXDevice } from './webgl-device'; @@ -33,6 +34,7 @@ export class WebGLGFXShader extends GFXShader { } this._gpuShader = this.webGLDevice.emitCmdCreateGPUShader(info); + this._status = GFXStatus.SUCCESS; return true; } @@ -42,5 +44,6 @@ export class WebGLGFXShader extends GFXShader { this.webGLDevice.emitCmdDestroyGPUShader(this._gpuShader); this._gpuShader = null; } + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-texture-view.ts b/cocos/gfx/webgl/webgl-texture-view.ts index 64cc9d3214..632aa95b51 100644 --- a/cocos/gfx/webgl/webgl-texture-view.ts +++ b/cocos/gfx/webgl/webgl-texture-view.ts @@ -1,3 +1,4 @@ +import { GFXStatus } from '../define'; import { GFXDevice } from '../device'; import { GFXTextureView, IGFXTextureViewInfo } from '../texture-view'; import { WebGLGFXDevice } from './webgl-device'; @@ -43,6 +44,7 @@ export class WebGLGFXTextureView extends GFXTextureView { } this._gpuTextureView = this.webGLDevice.emitCmdCreateGPUTextureView(info); + this._status = GFXStatus.SUCCESS; return true; } @@ -53,5 +55,6 @@ export class WebGLGFXTextureView extends GFXTextureView { this._gpuTextureView = null; } this._texture = null; + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-texture.ts b/cocos/gfx/webgl/webgl-texture.ts index 61f056399b..2e7c33fa2a 100644 --- a/cocos/gfx/webgl/webgl-texture.ts +++ b/cocos/gfx/webgl/webgl-texture.ts @@ -1,4 +1,4 @@ -import { GFXFormatSurfaceSize, GFXTextureFlagBit } from '../define'; +import { GFXFormatSurfaceSize, GFXStatus, GFXTextureFlagBit } from '../define'; import { GFXDevice } from '../device'; import { GFXTexture, IGFXTextureInfo } from '../texture'; import { WebGLGFXDevice } from './webgl-device'; @@ -51,15 +51,16 @@ export class WebGLGFXTexture extends GFXTexture { } this._gpuTexture = this.webGLDevice.emitCmdCreateGPUTexture(info); + this._status = GFXStatus.SUCCESS; return true; } public destroy () { - if (this._gpuTexture) { this.webGLDevice.emitCmdDestroyGPUTexture(this._gpuTexture); this._gpuTexture = null; } + this._status = GFXStatus.UNREADY; } } diff --git a/cocos/gfx/webgl/webgl-window.ts b/cocos/gfx/webgl/webgl-window.ts index e88a379998..b4f39940b9 100644 --- a/cocos/gfx/webgl/webgl-window.ts +++ b/cocos/gfx/webgl/webgl-window.ts @@ -1,4 +1,4 @@ -import { GFXFormat, GFXLoadOp, GFXStoreOp, GFXTextureFlagBit, GFXTextureLayout, GFXTextureType, GFXTextureUsageBit, GFXTextureViewType } from '../define'; +import { GFXLoadOp, GFXStatus, GFXStoreOp, GFXTextureLayout } from '../define'; import { GFXDevice } from '../device'; import { GFXWindow, IGFXWindowInfo } from '../window'; import { WebGLGFXDevice } from './webgl-device'; @@ -131,6 +131,7 @@ export class WebGLGFXWindow extends GFXWindow { this.destroy(); return false; } + this._status = GFXStatus.SUCCESS; return true; } @@ -167,6 +168,8 @@ export class WebGLGFXWindow extends GFXWindow { this._renderPass.destroy(); this._renderPass = null; } + + this._status = GFXStatus.UNREADY; } public get webGLDevice (): WebGLGFXDevice { diff --git a/cocos/gfx/window.ts b/cocos/gfx/window.ts index b4d8b2ea60..8e58075adb 100644 --- a/cocos/gfx/window.ts +++ b/cocos/gfx/window.ts @@ -1,4 +1,4 @@ -import { GFXFormat } from './define'; +import { GFXFormat, GFXObject, GFXObjectType } from './define'; import { GFXDevice } from './device'; import { GFXFramebuffer } from './framebuffer'; import { GFXRenderPass } from './render-pass'; @@ -13,7 +13,7 @@ export interface IGFXWindowInfo { depthStencilFmt: GFXFormat; } -export abstract class GFXWindow { +export abstract class GFXWindow extends GFXObject { public get width (): number { return this._width; @@ -23,20 +23,20 @@ export abstract class GFXWindow { return this._height; } - public get colorFormat (): GFXFormat | null { + public get colorFormat (): GFXFormat { return this._colorFmt; } - public get detphStencilFormat (): GFXFormat | null { + public get detphStencilFormat (): GFXFormat { return this._depthStencilFmt; } - public get renderPass (): GFXRenderPass | null { - return this._renderPass; + public get renderPass (): GFXRenderPass { + return this._renderPass as GFXRenderPass; } - public get framebuffer (): GFXFramebuffer | null { - return this._framebuffer; + public get framebuffer (): GFXFramebuffer { + return this._framebuffer as GFXFramebuffer; } protected _device: GFXDevice; @@ -55,6 +55,7 @@ export abstract class GFXWindow { protected _framebuffer: GFXFramebuffer | null = null; constructor (device: GFXDevice) { + super(GFXObjectType.WINDOW); this._device = device; } diff --git a/cocos/pipeline/forward/forward-flow.ts b/cocos/pipeline/forward/forward-flow.ts index 55007b77f9..b4a29558dc 100644 --- a/cocos/pipeline/forward/forward-flow.ts +++ b/cocos/pipeline/forward/forward-flow.ts @@ -1,5 +1,6 @@ import { IRenderFlowInfo, RenderFlow } from '../render-flow'; import { RenderPipeline } from '../render-pipeline'; +import { ForwardStage } from './forward-stage'; // import { TestStage } from "./test-stage"; import { TestMaterialStage } from './test-material-stage'; import { TestModelStage } from './test-model-stage'; @@ -28,26 +29,27 @@ export class ForwardFlow extends RenderFlow { return false; } - /* * - this.createStage(ForwardStage, { - name: "ForwardStage", + /* + this.createStage(ForwardStage, { + name: 'ForwardStage', priority: ForwardStagePriority.FORWARD, framebuffer: mainWindow.framebuffer, }); - /* */ + */ this.createStage(TestModelStage, { name: 'TestModelStage', priority: ForwardStagePriority.FORWARD, framebuffer: mainWindow.framebuffer, }); - /* */ - // this.createStage(TestStage, { - // name: 'TestStage', - // priority: ForwardStagePriority.FORWARD, - // framebuffer: mainWindow.framebuffer, - // }); - /* */ + + /* + this.createStage(TestStage, { + name: 'TestStage', + priority: ForwardStagePriority.FORWARD, + framebuffer: mainWindow.framebuffer, + }); + */ return true; } diff --git a/cocos/pipeline/forward/forward-pipeline.ts b/cocos/pipeline/forward/forward-pipeline.ts index 3470871a70..02a90df558 100644 --- a/cocos/pipeline/forward/forward-pipeline.ts +++ b/cocos/pipeline/forward/forward-pipeline.ts @@ -1,9 +1,8 @@ -import { Root } from "../../core/root"; -import { GFXBufferUsageBit, GFXMemoryUsageBit } from "../../gfx/define"; -import { GFXRenderPass } from "../../gfx/render-pass"; -import { RenderPassStage, RenderPipeline, UBOGlobal } from "../render-pipeline"; -import { RenderQueue } from "../render-queue"; -import { ForwardFlow } from "./forward-flow"; +import { Root } from '../../core/root'; +import { GFXBufferUsageBit, GFXMemoryUsageBit } from '../../gfx/define'; +import { GFXRenderPass } from '../../gfx/render-pass'; +import { RenderPassStage, RenderPipeline, UBOGlobal } from '../render-pipeline'; +import { ForwardFlow } from './forward-flow'; export enum ForwardFlowPriority { FORWARD = 0, diff --git a/cocos/pipeline/forward/forward-stage.ts b/cocos/pipeline/forward/forward-stage.ts index e9cf5104d8..195e1bb045 100644 --- a/cocos/pipeline/forward/forward-stage.ts +++ b/cocos/pipeline/forward/forward-stage.ts @@ -1,18 +1,17 @@ -import { RenderStage, IRenderStageInfo } from "../render-stage"; -import { RenderFlow } from "../render-flow"; -import { GFXCommandBuffer } from "../../gfx/command-buffer"; -import { RenderView } from "../render-view"; -import { GFXFramebuffer } from "../../gfx/framebuffer"; -import { GFXCommandBufferType } from "../../gfx/define"; -import { GFXInputAssembler } from "../../gfx/input-assembler"; +import { GFXCommandBuffer } from '../../gfx/command-buffer'; +import { GFXCommandBufferType } from '../../gfx/define'; +import { GFXFramebuffer } from '../../gfx/framebuffer'; +import { RenderFlow } from '../render-flow'; +import { IRenderStageInfo, RenderStage } from '../render-stage'; +import { RenderView } from '../render-view'; export class ForwardStage extends RenderStage { - constructor(flow: RenderFlow) { + constructor (flow: RenderFlow) { super(flow); } - public initialize(info: IRenderStageInfo): boolean { + public initialize (info: IRenderStageInfo): boolean { if (info.name !== undefined) { this._name = info.name; @@ -29,7 +28,7 @@ export class ForwardStage extends RenderStage { return true; } - public destroy() { + public destroy () { if (this._cmdBuff) { this._cmdBuff.destroy(); @@ -37,25 +36,24 @@ export class ForwardStage extends RenderStage { } } - public render(view: RenderView) { + public render (view: RenderView) { - let cmdBuff = this._cmdBuff as GFXCommandBuffer; - let queue = this._pipeline.queue; + const cmdBuff = this._cmdBuff as GFXCommandBuffer; + const queue = this._pipeline.queue; this._renderArea.width = view.width; this._renderArea.height = view.height; cmdBuff.begin(); - cmdBuff.beginRenderPass(this._framebuffer, this._renderArea, this._clearColors, this._clearDepth, this._clearStencil); + cmdBuff.beginRenderPass( this._framebuffer as GFXFramebuffer, this._renderArea, this._clearColors, this._clearDepth, this._clearStencil); - for (let item of queue.opaques) { - item.model.commandBuffers + for (const item of queue.opaques) { + // item.model.commandBuffers; } - cmdBuff.endRenderPass(); cmdBuff.end(); this._device.queue.submit([cmdBuff]); } -}; +} diff --git a/cocos/pipeline/forward/test-model-stage.ts b/cocos/pipeline/forward/test-model-stage.ts index 22198e5b84..6060404f65 100644 --- a/cocos/pipeline/forward/test-model-stage.ts +++ b/cocos/pipeline/forward/test-model-stage.ts @@ -80,7 +80,7 @@ export class TestModelStage extends RenderStage { } } - public render(view: RenderView) { + public render (view: RenderView) { if (!this._init) { @@ -88,7 +88,6 @@ export class TestModelStage extends RenderStage { this._material.effectName = 'test'; // parsed-effect file is embedded in cocos/3d/builtin/effects.js this._material.setProperty('u_sampler', this._textureAsset); this._material.setProperty('u_color', cc.color('#ff0000')); - this._material.inited = true; this._scene = new Scene(); this._scene._scene = this._scene; diff --git a/cocos/pipeline/render-view.ts b/cocos/pipeline/render-view.ts index 88f0e30e04..daaf6db898 100644 --- a/cocos/pipeline/render-view.ts +++ b/cocos/pipeline/render-view.ts @@ -1,30 +1,86 @@ -import { Camera } from "../renderer/scene/camera"; -import { GFXWindow } from "../gfx/window"; -import { RenderScene } from "../renderer/scene/render-scene"; +import { Root } from '../core/root'; +import { GFXWindow } from '../gfx/window'; +import { Camera } from '../renderer/scene/camera'; +import { RenderScene } from '../renderer/scene/render-scene'; export enum RenderViewPriority { GENERAL = 100, -}; +} -export interface RenderViewInfo { +export interface IRenderViewInfo { name: string; window: GFXWindow; priority: number; width: number; height: number; -}; +} export class RenderView { - public initialize(info: RenderViewInfo): boolean { + public get name (): string { + return this._name; + } + + public get window (): GFXWindow | null { + return this._window; + } + + public get priority (): number { + return this._priority; + } + + public set visibility (vis: number) { + this._visiblity = vis; + } + public get visibility (): number { + return this._visiblity; + } + + public get width (): number { + return this._width; + } + + public get height (): number { + return this._height; + } + + public get camera (): Camera { + return this._camera as Camera; + } + + public get scene (): RenderScene { + return this._scene as RenderScene; + } + + public static registerCreateFunc (root: Root) { + root._createViewFun = (_root: Root): RenderView => new RenderView(_root); + } + + private _root: Root; + private _name: string = ''; + private _window: GFXWindow | null = null; + private _priority: number = 0; + private _visiblity: number = 0; + private _width: number = 0; + private _height: number = 0; + private _scene: RenderScene | null = null; + private _camera: Camera | null = null; + private _isAttached: boolean = false; + private _isEnable: boolean = true; + + private constructor (root: Root) { + this._root = root; + } + + public initialize (info: IRenderViewInfo): boolean { if (!info.window) { - console.error("RenderViewInfo.window is null."); + console.error('RenderViewInfo.window is null.'); return false; } if (info.width <= 0 || info.height <= 0) { - console.error("RenderView size is an error size."); + console.error('RenderView size is an error size.'); return false; } @@ -37,85 +93,38 @@ export class RenderView { return true; } - public destroy() { + public destroy () { this._window = null; this._priority = 0; this._width = 0; this._height = 0; } - public resize(width, height) { + public resize (width, height) { } - public attach(camera: Camera) { + public attach (camera: Camera) { this._scene = camera.scene; this._camera = camera; this._isAttached = true; } - public detach() { + public detach () { this._scene = null; this._camera = null; this._isAttached = false; } - public enable(isEnable: boolean) { + public enable (isEnable: boolean) { this._isEnable = isEnable; } - public isEnable() : boolean { + public isEnable (): boolean { return this._isEnable; } - - public isAttached() : boolean { + + public isAttached (): boolean { return this._isAttached; } - - public get name(): string { - return this._name; - } - - public get window(): GFXWindow | null { - return this._window; - } - - public get priority(): number { - return this._priority; - } - - public get visibility(): number { - return this._visiblity; - } - - public get width(): number { - return this._width; - } - - public get height(): number { - return this._height; - } - - public get camera(): Camera { - return this._camera as Camera; - } - - public get scene(): RenderScene { - return this._scene as RenderScene; - } - - public set visibility(vis: number) { - this._visiblity = vis; - } - - private _name: string = ""; - private _window: GFXWindow | null = null; - private _priority: number = 0; - private _visiblity: number = 0; - private _width: number = 0; - private _height: number = 0; - private _scene: RenderScene | null = null; - private _camera: Camera | null = null; - private _isAttached: boolean = false; - private _isEnable: boolean = true; -}; +} diff --git a/cocos/renderer/scene/model.ts b/cocos/renderer/scene/model.ts index 126f476570..387352929c 100644 --- a/cocos/renderer/scene/model.ts +++ b/cocos/renderer/scene/model.ts @@ -1,20 +1,20 @@ // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. import { Material } from '../../3d/assets/material'; import { aabb } from '../../3d/geom-utils'; -import { IGFXInputAttribute, GFXInputAssembler } from '../../gfx/input-assembler'; -import { GFXFormat, GFXBufferUsageBit, GFXMemoryUsageBit, GFXCommandBufferType } from '../../gfx/define'; -import { RenderScene } from './render-scene'; -import { vec3, mat4 } from '../../core/vmath'; import { Vec3 } from '../../core/value-types'; +import { mat4, vec3 } from '../../core/vmath'; +import { GFXBuffer } from '../../gfx/buffer'; import { GFXCommandBuffer } from '../../gfx/command-buffer'; +import { GFXBufferUsageBit, GFXCommandBufferType, GFXFormat, GFXMemoryUsageBit } from '../../gfx/define'; +import { GFXInputAssembler, IGFXInputAttribute } from '../../gfx/input-assembler'; +import { UBOLocal } from '../../pipeline/render-pipeline'; import { Node } from '../../scene-graph'; import { Effect } from '../core/effect'; import { Pass } from '../core/pass'; -import { UBOLocal } from '../../pipeline/render-pipeline'; -import { GFXBuffer } from '../../gfx/buffer'; +import { RenderScene } from './render-scene'; -let _temp_floatx16 = new Float32Array(16); -let _temp_mat4 = mat4.create(); +const _temp_floatx16 = new Float32Array(16); +const _temp_mat4 = mat4.create(); /** * A representation of a model @@ -45,7 +45,7 @@ export default class Model { /** * Setup a default empty model */ - constructor() { + constructor () { this._scene = null; this._id = 0; this._enable = false; @@ -69,7 +69,7 @@ export default class Model { this._localUBO = null; } - initialize() { + public initialize () { this._localUniforms = new UBOLocal(); this._localUBO = cc.director.root.device.createBuffer({ usage: GFXBufferUsageBit.UNIFORM | GFXBufferUsageBit.TRANSFER_DST, @@ -77,11 +77,12 @@ export default class Model { size: UBOLocal.SIZE, stride: UBOLocal.SIZE, }); - if (this._localUBO) + if (this._localUBO) { this._localUBO.update(this._localUniforms.view); + } } - set scene(scene: RenderScene | null) { + set scene (scene: RenderScene | null) { this._scene = scene; if (this._scene) { @@ -89,31 +90,34 @@ export default class Model { } } - get scene(): RenderScene | null { + get scene (): RenderScene | null { return this._scene; } - get id(): number { + get id (): number { return this._id; } - public _updateTransform() { + public _updateTransform () { if (!this._node._hasChanged || !this._boundingShape) { return; } this._node.updateWorldTransformFull(); this._bsModelSpace.transform(this._node._mat, this._node._pos, this._node._rot, this._node._scale, this._boundingShape); } - updateRenderData() { + public updateRenderData () { mat4.array(_temp_floatx16, this._node._mat); this._node._mat.invert(_temp_mat4); - if (this._localUniforms) + if (this._localUniforms) { this._localUniforms.view.set(_temp_floatx16, UBOLocal.MAT_WORLD_OFFSET); + } mat4.array(_temp_floatx16, _temp_mat4); - if (this._localUniforms) + if (this._localUniforms) { this._localUniforms.view.set(_temp_floatx16, UBOLocal.MAT_WORLD_IT_OFFSET); - if (this._localUBO) + } + if (this._localUBO) { this._localUBO.update(this._localUniforms.view); + } } /** @@ -121,17 +125,17 @@ export default class Model { * @param {vec3} minPos the min position of the model * @param {vec3} maxPos the max position of the model */ - public createBoundingShape(minPos: Vec3, maxPos: Vec3) { + public createBoundingShape (minPos: Vec3, maxPos: Vec3) { if (!minPos || !maxPos) { return; } this._bsModelSpace = aabb.fromPoints(aabb.create(), minPos, maxPos); this._boundingShape = aabb.clone(this._bsModelSpace); } - public enable(isEnable: boolean) { + public enable (isEnable: boolean) { this._isEnable = isEnable; } - public isEnable(): boolean { + public isEnable (): boolean { return this._isEnable; } @@ -139,7 +143,7 @@ export default class Model { * Get the hosting node of this camera * @returns {Node} the hosting node */ - get node(): Node { + get node (): Node { return this._node; } @@ -147,7 +151,7 @@ export default class Model { * Set the hosting node of this model * @param {Node} node the hosting node */ - set node(node: Node) { + set node (node: Node) { this._node = node; } @@ -155,7 +159,7 @@ export default class Model { * Set the input assembler * @param {InputAssembler} ia */ - set inputAssembler(ia: GFXInputAssembler) { + set inputAssembler (ia: GFXInputAssembler) { this._inputAssembler = ia; } @@ -171,7 +175,7 @@ export default class Model { * Set the model effect * @param {?Effect} effect the effect to use */ - public setEffect(effect: Effect) { + public setEffect (effect: Effect) { if (effect) { this._effect = effect; // this._defines = effect.extractDefines(Object.create(null)); @@ -183,7 +187,7 @@ export default class Model { } } - set material(material: Material) { + set material (material: Material) { this._material = material; for (let i = 0; i < this._material.passes.length; i++) { this.recordCommandBuffer(i); @@ -196,7 +200,7 @@ export default class Model { } } - public recordCommandBuffer(index: number) { + public recordCommandBuffer (index: number) { const pass = (this._material as Material).passes[index]; const cmdBufferInfo = { allocator: cc.director.root.device.commandAllocator, @@ -205,8 +209,9 @@ export default class Model { if (this._cmdBuffers[index] == null) { this._cmdBuffers[index] = cc.director.root.device.createCommandBuffer(cmdBufferInfo); } - if (this._localUBO) + if (this._localUBO) { pass.bindingLayout.bindBuffer(UBOLocal.BLOCK.binding, this._localUBO); + } pass.bindingLayout.update(); this._cmdBuffers[index].begin(); this._cmdBuffers[index].bindPipelineState(pass.pipelineState); @@ -220,15 +225,15 @@ export default class Model { * Set the user key * @param {number} key */ - set userKey(key: number) { + set userKey (key: number) { this._userKey = key; } - get passes(): Pass[] { + get passes (): Pass[] { return (this._material as Material).passes; } - get commandBuffers(): GFXCommandBuffer[] { + get commandBuffers (): GFXCommandBuffer[] { return this._cmdBuffers; } @@ -236,7 +241,7 @@ export default class Model { * Extract a drawing item * @param {Object} out the receiving item */ - public extractDrawItem(out) { + public extractDrawItem (out) { out.model = this; out.node = this._node; out.ia = this._inputAssembler; diff --git a/cocos/renderer/scene/render-scene.ts b/cocos/renderer/scene/render-scene.ts index 52a0135342..2968a6ce14 100644 --- a/cocos/renderer/scene/render-scene.ts +++ b/cocos/renderer/scene/render-scene.ts @@ -1,55 +1,92 @@ -import Node from "../../scene-graph/node"; -import Light from "./light"; -import Model from "./model"; -import { Camera } from "./camera"; -import { Root } from "../../core/root"; +import { Root, _createSceneFun } from '../../core/root'; +import Node from '../../scene-graph/node'; +import { Camera } from './camera'; +import Light from './light'; +import Model from './model'; -export interface RenderSceneInfo { +export interface IRenderSceneInfo { name: string; -}; +} -export interface SceneNodeInfo { +export interface ISceneNodeInfo { name: string; isStatic?: boolean; - //parent: Node; + // parent: Node; } export class RenderScene { - constructor(root: Root) { + public get root (): Root { + return this._root; + } + + public get name (): string { + return this._name; + } + + public get cameras (): Camera[] { + return this._cameras; + } + + public get mainCamera (): Camera | null { + return this._mainCamera; + } + + public get lights (): Light[] { + return this._lights; + } + + public get models (): Model[] { + return this._models; + } + + public static registerCreateFunc (root: Root) { + root._createSceneFun = (_root: Root): RenderScene => new RenderScene(_root); + } + + private _root: Root; + private _name: string = ''; + private _nodes: Map = new Map(); + private _cameras: Camera[] = []; + private _mainCamera: Camera | null = null; + private _lights: Light[] = []; + private _models: Model[] = []; + private _modelId: number = 0; + + private constructor (root: Root) { this._root = root; } - public initialize(info: RenderSceneInfo): boolean { + public initialize (info: IRenderSceneInfo): boolean { this._name = info.name; - this._mainCamera = this.createCamera("mainCamera"); + this._mainCamera = this.createCamera('mainCamera'); return true; } - public destroy() { + public destroy () { this.destroyCameras(); this.destroyLights(); this.destroyNodes(); this.destroyModels(); } - public createNode(info: SceneNodeInfo): Node { - let node = new Node(info.name); + public createNode (info: ISceneNodeInfo): Node { + const node = new Node(info.name); this._nodes.set(node.uuid, node); return node; } - public destroyNode(node: Node) { + public destroyNode (node: Node) { this._nodes.delete(node.uuid); } - public destroyNodes() { + public destroyNodes () { this._nodes.clear(); } - public getNode(id: number): Node | null { - let node = this._nodes.get(id); + public getNode (id: number): Node | null { + const node = this._nodes.get(id); if (node) { return node; } else { @@ -57,13 +94,13 @@ export class RenderScene { } } - public createCamera(name: string): Camera { - let camera = new Camera(this, name); + public createCamera (name: string): Camera { + const camera = new Camera(this, name); this._cameras.push(camera); return camera; } - public destroyCamera(camera: Camera) { + public destroyCamera (camera: Camera) { for (let i = 0; i < this._cameras.length; ++i) { if (this._cameras[i] === camera) { this._cameras.slice(i); @@ -72,28 +109,28 @@ export class RenderScene { } } - public destroyCameras() { + public destroyCameras () { this._cameras = []; this._mainCamera = null; } - public getCamera(name: string): Camera | null { - for (let i = 0; i < this._cameras.length; ++i) { - if (this._cameras[i].name === name) { - return this._cameras[i]; + public getCamera (name: string): Camera | null { + for (const camera of this._cameras) { + if (camera.name === name) { + return camera; } } return null; } - public createLight(name: string): Light { - let light = new Light(this, name); + public createLight (name: string): Light { + const light = new Light(this, name); this._lights.push(light); return light; } - public destroyLight(light: Light) { + public destroyLight (light: Light) { for (let i = 0; i < this._lights.length; ++i) { if (this._lights[i] === light) { this._lights.slice(i); @@ -102,13 +139,12 @@ export class RenderScene { } } - public destroyLights() { + public destroyLights () { this._lights = []; } - public getLight(name: string): Light | null { - for (let i = 0; i < this._lights.length; ++i) { - let light = this._lights[i]; + public getLight (name: string): Light | null { + for (const light of this._lights) { if (light.getName() === name) { return light; } @@ -117,15 +153,15 @@ export class RenderScene { return null; } - public createModel(clazz: new () => T): Model { - let model = new clazz; + public createModel (clazz: new () => T): Model { + const model = new clazz(); model.initialize(); model.scene = this; this._models.push(model); return model; } - public destroyModel(model: Model) { + public destroyModel (model: Model) { for (let i = 0; i < this._models.length; ++i) { if (this._models[i] === model) { this._models.slice(i); @@ -134,44 +170,11 @@ export class RenderScene { } } - public destroyModels() { + public destroyModels () { this._models = []; } - public generateModelId(): number { + public generateModelId (): number { return this._modelId++; } - - public get root(): Root { - return this._root; - } - - public get name(): string { - return this._name; - } - - public get cameras(): Camera[] { - return this._cameras; - } - - public get mainCamera(): Camera | null { - return this._mainCamera; - } - - public get lights(): Light[] { - return this._lights; - } - - public get models(): Model[] { - return this._models; - } - - private _root: Root; - private _name: string = ""; - private _nodes: Map = new Map; - private _cameras: Camera[] = []; - private _mainCamera: Camera | null = null; - private _lights: Light[] = []; - private _models: Model[] = []; - private _modelId: number = 0; -}; +} diff --git a/cocos/scene-graph/scene.js b/cocos/scene-graph/scene.js index 75838edfc7..b3788a9aac 100644 --- a/cocos/scene-graph/scene.js +++ b/cocos/scene-graph/scene.js @@ -56,7 +56,8 @@ export default class Scene extends Node { // cache all depend assets for auto release this.dependAssets = null; - this._renderScenes.push(new RenderScene()); + let scene = cc.director.root.createScene({ name: 'mainScene' }); + this._renderScenes.push(scene); } /**