diff --git a/cocos/gfx/device.ts b/cocos/gfx/device.ts index 1c97dc83bf..e37c42ef07 100644 --- a/cocos/gfx/device.ts +++ b/cocos/gfx/device.ts @@ -13,7 +13,7 @@ import { GFXCommandBufferInfo, GFXCommandBuffer } from './command-buffer'; import { GFXCommandAllocatorInfo, GFXCommandAllocator } from './command-allocator'; import { GFXWindowInfo, GFXWindow } from './window'; import { GFXBindingLayoutInfo, GFXBindingLayout } from './binding-layout'; -import { GFXRect, GFXBufferTextureCopy } from './define'; +import { GFXRect, GFXBufferTextureCopy, GFXFormat } from './define'; export enum GFXFeature { }; @@ -69,8 +69,8 @@ export abstract class GFXDevice { return this._height; } - public get mainWindow(): GFXWindow | null { - return this._mainWindow; + public get mainWindow(): GFXWindow { + return this._mainWindow; } public get commandAllocator(): GFXCommandAllocator { @@ -113,6 +113,14 @@ export abstract class GFXDevice { return this._stencilBits; } + public get colorFormat(): GFXFormat { + return this._colorFmt; + } + + public get depthStencilFormat(): GFXFormat { + return this._depthStencilFmt; + } + public genShaderId(): number { return this._shaderIdGen++; } @@ -135,5 +143,7 @@ export abstract class GFXDevice { protected _maxVertexTextureUnits: number = 0; protected _depthBits: number = 0; protected _stencilBits: number = 0; + protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN; + protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN; protected _shaderIdGen: number = 0; }; diff --git a/cocos/gfx/framebuffer.ts b/cocos/gfx/framebuffer.ts index adb1751031..c5a6f3d7ef 100644 --- a/cocos/gfx/framebuffer.ts +++ b/cocos/gfx/framebuffer.ts @@ -1,6 +1,7 @@ import { GFXDevice } from './device'; import { GFXTextureView } from './texture-view'; import { GFXRenderPass } from './render-pass'; +import { GFXFormat } from './define'; export interface GFXFramebufferInfo { renderPass: GFXRenderPass; diff --git a/cocos/gfx/webgl/webgl-binding-layout.ts b/cocos/gfx/webgl/webgl-binding-layout.ts index 76343d2154..9cabcec35f 100644 --- a/cocos/gfx/webgl/webgl-binding-layout.ts +++ b/cocos/gfx/webgl/webgl-binding-layout.ts @@ -46,8 +46,8 @@ export class WebGLGFXBindingLayout extends GFXBindingLayout { return this._device; } - public get gpuBindingLayout(): WebGLGPUBindingLayout | null { - return this._gpuBindingLayout; + public get gpuBindingLayout(): WebGLGPUBindingLayout { + return this._gpuBindingLayout; } private _gpuBindingLayout: WebGLGPUBindingLayout | null = null; diff --git a/cocos/gfx/webgl/webgl-buffer.ts b/cocos/gfx/webgl/webgl-buffer.ts index f9e5cf21a8..078ed87aed 100644 --- a/cocos/gfx/webgl/webgl-buffer.ts +++ b/cocos/gfx/webgl/webgl-buffer.ts @@ -55,8 +55,8 @@ export class WebGLGFXBuffer extends GFXBuffer { return this._device; } - public get gpuBuffer(): WebGLGPUBuffer | null { - return this._gpuBuffer; + public get gpuBuffer(): WebGLGPUBuffer { + return this._gpuBuffer; } private _gpuBuffer: WebGLGPUBuffer | null = null; diff --git a/cocos/gfx/webgl/webgl-commands.ts b/cocos/gfx/webgl/webgl-commands.ts index 0d5c4acec3..a1221a7f4e 100644 --- a/cocos/gfx/webgl/webgl-commands.ts +++ b/cocos/gfx/webgl/webgl-commands.ts @@ -893,7 +893,7 @@ export function WebGLCmdFuncCreateShader(device: WebGLGFXDevice, gpuShader: WebG } // create uniform blocks - if (gpuShader.blocks && gpuShader.blocks.length > 0) { + if (gpuShader.blocks.length > 0) { gpuShader.glBlocks = new Array(gpuShader.blocks.length); for (let i = 0; i < gpuShader.blocks.length; ++i) { let block = gpuShader.blocks[i]; @@ -937,7 +937,7 @@ export function WebGLCmdFuncCreateShader(device: WebGLGFXDevice, gpuShader: WebG } // create uniform samplers - if (gpuShader.samplers && gpuShader.samplers.length > 0) { + if (gpuShader.samplers.length > 0) { gpuShader.glSamplers = new Array(gpuShader.samplers.length); for (let i = 0; i < gpuShader.samplers.length; ++i) { @@ -1087,46 +1087,6 @@ export function WebGLCmdFuncCreateInputAssember(device: WebGLGFXDevice, gpuInput offsets[stream] += size; } - - /* - if (gpuInputAssembler.gpuShader) { - let attribCount = gpuInputAssembler.gpuShader.glInputs.length; - gpuInputAssembler.glAttribs = new Array(attribCount); - - let offsets = [0, 0, 0, 0, 0, 0, 0, 0]; - - for (let i = 0; i < attribCount; ++i) { - let glInput = gpuInputAssembler.gpuShader.glInputs[i]; - let glAttrib = gpuInputAssembler.glAttribs[i]; - glAttrib.glLoc = glInput.glLoc; - glAttrib.glType = glInput.glType; - glAttrib.size = glInput.size; - glAttrib.componentCount = WebGLGetComponentCount(glAttrib.glType); - - for (let j = 0; j < gpuInputAssembler.attributes.length; ++j) { - let attrib = gpuInputAssembler.attributes[j]; - - let stream = attrib.stream !== undefined ? attrib.stream : 0; - - if (glInput.name === attrib.name && stream < gpuInputAssembler.gpuVertexBuffers.length) { - - let gpuBuffer = gpuInputAssembler.gpuVertexBuffers[stream]; - glAttrib.count = GFXFormatInfos[attrib.format].count; - glAttrib.stride = gpuBuffer.stride; - glAttrib.glBuffer = gpuBuffer.glBuffer; - - if (attrib.isInstanced) { - glAttrib.isInstanced = attrib.isInstanced; - } - - glAttrib.offset = offsets[stream]; - offsets[stream] += glInput.size; - break; - } - } - } - } - */ } export function WebGLCmdFuncDestroyInputAssembler(device: WebGLGFXDevice, gpuInputAssembler: WebGLGPUInputAssembler) { diff --git a/cocos/gfx/webgl/webgl-device.ts b/cocos/gfx/webgl/webgl-device.ts index 306b1f346e..ae57c065b4 100644 --- a/cocos/gfx/webgl/webgl-device.ts +++ b/cocos/gfx/webgl/webgl-device.ts @@ -130,11 +130,28 @@ export class WebGLGFXDevice extends GFXDevice { this._width = this._canvas.width; this._height = this._canvas.height; + this._colorFmt = GFXFormat.RGBA8; + + if (this._depthBits === 24) { + if (this._stencilBits === 8) { + this._depthStencilFmt = GFXFormat.D24S8; + } else { + this._depthStencilFmt = GFXFormat.D24; + } + } else { + if (this._stencilBits === 8) { + this._depthStencilFmt = GFXFormat.D16S8; + } else { + this._depthStencilFmt = GFXFormat.D16; + } + } console.info("RENDERER: " + this._renderer); console.info("VENDOR: " + this._vendor); console.info("VERSION: " + this._version); - console.info("SCREEN_SIZE: " + this._width + "x" + this._height); + console.info("SCREEN_SIZE: " + this._width + " x " + this._height); + console.info("COLOR_FORMAT: " + GFXFormatInfos[this._colorFmt].name); + console.info("DEPTH_STENCIL_FORMAT: " + GFXFormatInfos[this._depthStencilFmt].name); console.info("MAX_VERTEX_ATTRIBS: " + this._maxVertexAttributes); console.info("MAX_VERTEX_UNIFORM_VECTORS: " + this._maxVertexUniformVectors); @@ -176,21 +193,7 @@ export class WebGLGFXDevice extends GFXDevice { // init states this.initStates(gl); - let depthStencilFmt; - if (this._depthBits === 24) { - if (this._stencilBits === 8) { - depthStencilFmt = GFXFormat.D24S8; - } else { - depthStencilFmt = GFXFormat.D24; - } - } else { - if (this._stencilBits === 8) { - depthStencilFmt = GFXFormat.D16S8; - } else { - depthStencilFmt = GFXFormat.D16; - } - } // create queue this._queue = this.createQueue({ type: GFXQueueType.GRAPHICS }); @@ -202,8 +205,8 @@ export class WebGLGFXDevice extends GFXDevice { top: this._webGLRC.canvas.offsetTop, width: this._webGLRC.drawingBufferWidth, height: this._webGLRC.drawingBufferHeight, - colorFmt: GFXFormat.RGBA8, - depthStencilFmt: depthStencilFmt, + colorFmt: this._colorFmt, + depthStencilFmt: this._depthStencilFmt, }); this._cmdAllocator = this.createCommandAllocator({}); @@ -430,7 +433,7 @@ export class WebGLGFXDevice extends GFXDevice { let memSize = GFXFormatSize(GFXFormat.RGBA8, w, h, 1); let data = view.subarray(buffOffset, buffOffset + memSize); - + gl.readPixels(region.texOffset.x, region.texOffset.y, w, h, WebGLRenderingContext.RGBA, WebGLRenderingContext.UNSIGNED_BYTE, data); } @@ -732,8 +735,8 @@ export class WebGLGFXDevice extends GFXDevice { let gpuShader: WebGLGPUShader = { objType: WebGLGPUObjectType.SHADER, name: info.name ? info.name : "", - blocks: info.blocks, - samplers: info.samplers, + blocks: (info.blocks !== undefined ? info.blocks : []), + samplers: (info.samplers !== undefined ? info.samplers : []), gpuStages: gpuStages, glProgram: 0, diff --git a/cocos/gfx/webgl/webgl-gpu-objects.ts b/cocos/gfx/webgl/webgl-gpu-objects.ts index 9bfd803b83..1f2ddcf769 100644 --- a/cocos/gfx/webgl/webgl-gpu-objects.ts +++ b/cocos/gfx/webgl/webgl-gpu-objects.ts @@ -175,8 +175,8 @@ export class WebGLGPUShaderStage { export class WebGLGPUShader extends WebGLGPUObject { name: string = ""; - blocks?: GFXUniformBlock[]; - samplers?: GFXUniformSampler[]; + blocks: GFXUniformBlock[] = []; + samplers: GFXUniformSampler[] = []; gpuStages: WebGLGPUShaderStage[] = []; glProgram: WebGLProgram = 0; diff --git a/cocos/gfx/webgl/webgl-input-assembler.ts b/cocos/gfx/webgl/webgl-input-assembler.ts index e74a2d8b99..b6d47c1fa1 100644 --- a/cocos/gfx/webgl/webgl-input-assembler.ts +++ b/cocos/gfx/webgl/webgl-input-assembler.ts @@ -47,8 +47,8 @@ export class WebGLGFXInputAssembler extends GFXInputAssembler { return this._device; } - public get gpuInputAssembler(): WebGLGPUInputAssembler | null { - return this._gpuInputAssembler; + public get gpuInputAssembler(): WebGLGPUInputAssembler { + return this._gpuInputAssembler; } private _gpuInputAssembler: WebGLGPUInputAssembler | null = null; diff --git a/cocos/gfx/webgl/webgl-pipeline-layout.ts b/cocos/gfx/webgl/webgl-pipeline-layout.ts index e42563dc34..75aeb0f5de 100644 --- a/cocos/gfx/webgl/webgl-pipeline-layout.ts +++ b/cocos/gfx/webgl/webgl-pipeline-layout.ts @@ -27,8 +27,8 @@ export class WebGLGFXPipelineLayout extends GFXPipelineLayout { return this._device; } - public get gpuPipelineLayout(): WebGLGPUPipelineLayout | null { - return this._gpuPipelineLayout; + public get gpuPipelineLayout(): WebGLGPUPipelineLayout { + return this._gpuPipelineLayout; } private _gpuPipelineLayout: WebGLGPUPipelineLayout | null = null; diff --git a/cocos/gfx/webgl/webgl-pipeline-state.ts b/cocos/gfx/webgl/webgl-pipeline-state.ts index 79d379121e..f53d765f20 100644 --- a/cocos/gfx/webgl/webgl-pipeline-state.ts +++ b/cocos/gfx/webgl/webgl-pipeline-state.ts @@ -36,8 +36,8 @@ export class WebGLGFXPipelineState extends GFXPipelineState { return this._device; } - public get gpuPipelineState(): WebGLGPUPipelineState | null { - return this._gpuPipelineState; + public get gpuPipelineState(): WebGLGPUPipelineState { + return this._gpuPipelineState; } private _gpuPipelineState: WebGLGPUPipelineState | null = null; diff --git a/cocos/gfx/webgl/webgl-sampler.ts b/cocos/gfx/webgl/webgl-sampler.ts index b4f57c19c7..372dd84c42 100644 --- a/cocos/gfx/webgl/webgl-sampler.ts +++ b/cocos/gfx/webgl/webgl-sampler.ts @@ -81,8 +81,8 @@ export class WebGLGFXSampler extends GFXSampler { return this._device; } - public get gpuSampler() : WebGLGPUSampler | null { - return this._gpuSampler; + public get gpuSampler() : WebGLGPUSampler { + return this._gpuSampler; } private _gpuSampler : WebGLGPUSampler | null = null; diff --git a/cocos/gfx/webgl/webgl-shader.ts b/cocos/gfx/webgl/webgl-shader.ts index a0fe6ad917..2f5119686a 100644 --- a/cocos/gfx/webgl/webgl-shader.ts +++ b/cocos/gfx/webgl/webgl-shader.ts @@ -38,8 +38,8 @@ export class WebGLGFXShader extends GFXShader { return this._device; } - public get gpuShader(): WebGLGPUShader | null { - return this._gpuShader; + public get gpuShader(): WebGLGPUShader { + return this._gpuShader; } private _gpuShader: WebGLGPUShader | null = null; diff --git a/cocos/gfx/webgl/webgl-texture-view.ts b/cocos/gfx/webgl/webgl-texture-view.ts index aa9e0a289a..920169270a 100644 --- a/cocos/gfx/webgl/webgl-texture-view.ts +++ b/cocos/gfx/webgl/webgl-texture-view.ts @@ -49,8 +49,8 @@ export class WebGLGFXTextureView extends GFXTextureView { return this._device; } - public get gpuTextureView(): WebGLGPUTextureView | null { - return this._gpuTextureView; + public get gpuTextureView(): WebGLGPUTextureView { + return this._gpuTextureView; } private _gpuTextureView: WebGLGPUTextureView | null = null; diff --git a/cocos/gfx/webgl/webgl-window.ts b/cocos/gfx/webgl/webgl-window.ts index 742c43264a..15fec7b617 100644 --- a/cocos/gfx/webgl/webgl-window.ts +++ b/cocos/gfx/webgl/webgl-window.ts @@ -11,15 +11,15 @@ export class WebGLGFXWindow extends GFXWindow { public initialize(info: GFXWindowInfo): boolean { - if(info.title) { + if(info.title !== undefined) { this._title = info.title; } - if(info.left) { + if(info.left !== undefined) { this._left = info.left; } - if(info.top) { + if(info.top !== undefined) { this._top = info.top; } diff --git a/cocos/renderer/scene/camera.ts b/cocos/renderer/scene/camera.ts index 635d01b374..f8aa88ff6c 100644 --- a/cocos/renderer/scene/camera.ts +++ b/cocos/renderer/scene/camera.ts @@ -2,6 +2,13 @@ import { RenderScene } from "./render-scene"; import Node from "../../scene-graph/node"; import { mat4, vec3, quat } from '../../core/vmath'; +export enum NodeSpace +{ + LOCAL, + PARENT, + WORLD, +}; + export enum CameraProjection { PERSPECTIVE, ORTHO, @@ -119,6 +126,49 @@ export class Camera { return this._position; } + public rotate(axis: vec3, rad: number, ns?: NodeSpace) { + quat.fromAxisAngle(this._rotation, axis, rad); + let space = (ns !== undefined? ns : NodeSpace.LOCAL); + if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) { + this._node.setRotation(this._rotation); + } else if (space === NodeSpace.WORLD) { + this._node.setWorldRotation(this._rotation); + } + } + + public pitch(rad: number, ns?: NodeSpace) { + let space = (ns !== undefined? ns : NodeSpace.LOCAL); + if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) { + this._node.getRotation(this._rotation); + this.rotate(this._rotation, rad, ns); + } else if (space === NodeSpace.WORLD) { + this._node.getWorldRotation(this._rotation); + this.rotate(this._rotation, rad, ns); + } + } + + public yaw(rad: number, ns?: NodeSpace) { + let space = (ns !== undefined? ns : NodeSpace.LOCAL); + if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) { + this._node.getRotation(this._rotation); + this.rotate(this._rotation, rad, ns); + } else if (space === NodeSpace.WORLD) { + this._node.getWorldRotation(this._rotation); + this.rotate(this._rotation, rad, ns); + } + } + + public roll(rad: number, ns?: NodeSpace) { + let space = (ns !== undefined? ns : NodeSpace.LOCAL); + if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) { + this._node.getRotation(this._rotation); + this.rotate(this._rotation, rad, ns); + } else if (space === NodeSpace.WORLD) { + this._node.getWorldRotation(this._rotation); + this.rotate(this._rotation, rad, ns); + } + } + public set target(target: vec3) { this._node.lookAt(target); }