remove null return-value from GFXDevice.createXXX interfaces, add GFXStatus to GFXObject

This commit is contained in:
jerrywwl
2019-01-10 14:52:54 +08:00
parent 1a1f89b3f7
commit 1dca42f7fb
42 changed files with 503 additions and 439 deletions
+77 -69
View File
@@ -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) {
(<RenderPipeline>this._pipeline).render(view);
( this._pipeline as RenderPipeline).render(view);
}
}
(<GFXDevice>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;
};
}
+3 -2
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+3 -1
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+43
View File
@@ -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,
+15 -15
View File
@@ -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[]);
+3 -1
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+3 -2
View File
@@ -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();
}
+3 -2
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+4
View File
@@ -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 () {
+3 -1
View File
@@ -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) {
+3 -1
View File
@@ -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;
}
}
+3 -1
View File
@@ -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 () {
+45 -105
View File
@@ -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 () {
+3
View File
@@ -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;
}
}
+3
View File
@@ -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;
}
}
+3
View File
@@ -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;
}
}
+3
View File
@@ -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;
}
}
+3 -1
View File
@@ -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?) {
+3
View File
@@ -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;
}
}
+3
View File
@@ -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;
}
}
+3
View File
@@ -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;
}
}
+3
View File
@@ -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;
}
}
+3 -2
View File
@@ -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;
}
}
+4 -1
View File
@@ -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 {
+9 -8
View File
@@ -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;
}
+13 -11
View File
@@ -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>(ForwardStage, {
name: "ForwardStage",
/*
this.createStage(ForwardStage, {
name: 'ForwardStage',
priority: ForwardStagePriority.FORWARD,
framebuffer: mainWindow.framebuffer,
});
/* */
*/
this.createStage<TestModelStage>(TestModelStage, {
name: 'TestModelStage',
priority: ForwardStagePriority.FORWARD,
framebuffer: mainWindow.framebuffer,
});
/* */
// this.createStage<TestStage>(TestStage, {
// name: 'TestStage',
// priority: ForwardStagePriority.FORWARD,
// framebuffer: mainWindow.framebuffer,
// });
/* */
/*
this.createStage<TestStage>(TestStage, {
name: 'TestStage',
priority: ForwardStagePriority.FORWARD,
framebuffer: mainWindow.framebuffer,
});
*/
return true;
}
+5 -6
View File
@@ -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,
+16 -18
View File
@@ -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(<GFXFramebuffer>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]);
}
};
}
+1 -2
View File
@@ -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;
+74 -65
View File
@@ -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;
};
}
+38 -33
View File
@@ -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;
+76 -73
View File
@@ -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<number, Node> = 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<T extends Model>(clazz: new () => T): Model {
let model = new clazz;
public createModel<T extends Model> (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<number, Node> = new Map;
private _cameras: Camera[] = [];
private _mainCamera: Camera | null = null;
private _lights: Light[] = [];
private _models: Model[] = [];
private _modelId: number = 0;
};
}
+2 -1
View File
@@ -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);
}
/**