mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
commit modified files
This commit is contained in:
+13
-3
@@ -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 <GFXWindow>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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -46,8 +46,8 @@ export class WebGLGFXBindingLayout extends GFXBindingLayout {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuBindingLayout(): WebGLGPUBindingLayout | null {
|
||||
return this._gpuBindingLayout;
|
||||
public get gpuBindingLayout(): WebGLGPUBindingLayout {
|
||||
return <WebGLGPUBindingLayout>this._gpuBindingLayout;
|
||||
}
|
||||
|
||||
private _gpuBindingLayout: WebGLGPUBindingLayout | null = null;
|
||||
|
||||
@@ -55,8 +55,8 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuBuffer(): WebGLGPUBuffer | null {
|
||||
return this._gpuBuffer;
|
||||
public get gpuBuffer(): WebGLGPUBuffer {
|
||||
return <WebGLGPUBuffer>this._gpuBuffer;
|
||||
}
|
||||
|
||||
private _gpuBuffer: WebGLGPUBuffer | null = null;
|
||||
|
||||
@@ -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<WebGLGPUUniformBlock>(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<WebGLGPUUniformSampler>(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<WebGLAttrib>(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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -47,8 +47,8 @@ export class WebGLGFXInputAssembler extends GFXInputAssembler {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuInputAssembler(): WebGLGPUInputAssembler | null {
|
||||
return this._gpuInputAssembler;
|
||||
public get gpuInputAssembler(): WebGLGPUInputAssembler {
|
||||
return <WebGLGPUInputAssembler>this._gpuInputAssembler;
|
||||
}
|
||||
|
||||
private _gpuInputAssembler: WebGLGPUInputAssembler | null = null;
|
||||
|
||||
@@ -27,8 +27,8 @@ export class WebGLGFXPipelineLayout extends GFXPipelineLayout {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuPipelineLayout(): WebGLGPUPipelineLayout | null {
|
||||
return this._gpuPipelineLayout;
|
||||
public get gpuPipelineLayout(): WebGLGPUPipelineLayout {
|
||||
return <WebGLGPUPipelineLayout>this._gpuPipelineLayout;
|
||||
}
|
||||
|
||||
private _gpuPipelineLayout: WebGLGPUPipelineLayout | null = null;
|
||||
|
||||
@@ -36,8 +36,8 @@ export class WebGLGFXPipelineState extends GFXPipelineState {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuPipelineState(): WebGLGPUPipelineState | null {
|
||||
return this._gpuPipelineState;
|
||||
public get gpuPipelineState(): WebGLGPUPipelineState {
|
||||
return <WebGLGPUPipelineState>this._gpuPipelineState;
|
||||
}
|
||||
|
||||
private _gpuPipelineState: WebGLGPUPipelineState | null = null;
|
||||
|
||||
@@ -81,8 +81,8 @@ export class WebGLGFXSampler extends GFXSampler {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuSampler() : WebGLGPUSampler | null {
|
||||
return this._gpuSampler;
|
||||
public get gpuSampler() : WebGLGPUSampler {
|
||||
return <WebGLGPUSampler>this._gpuSampler;
|
||||
}
|
||||
|
||||
private _gpuSampler : WebGLGPUSampler | null = null;
|
||||
|
||||
@@ -38,8 +38,8 @@ export class WebGLGFXShader extends GFXShader {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuShader(): WebGLGPUShader | null {
|
||||
return this._gpuShader;
|
||||
public get gpuShader(): WebGLGPUShader {
|
||||
return <WebGLGPUShader>this._gpuShader;
|
||||
}
|
||||
|
||||
private _gpuShader: WebGLGPUShader | null = null;
|
||||
|
||||
@@ -49,8 +49,8 @@ export class WebGLGFXTextureView extends GFXTextureView {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuTextureView(): WebGLGPUTextureView | null {
|
||||
return this._gpuTextureView;
|
||||
public get gpuTextureView(): WebGLGPUTextureView {
|
||||
return <WebGLGPUTextureView>this._gpuTextureView;
|
||||
}
|
||||
|
||||
private _gpuTextureView: WebGLGPUTextureView | null = null;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user