mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
mod gfx
This commit is contained in:
@@ -7,7 +7,6 @@ export const enum GFXBindingType {
|
||||
UNKNOWN,
|
||||
UNIFORM_BUFFER,
|
||||
SAMPLER,
|
||||
TEXTURE_VIEW,
|
||||
STORAGE_BUFFER,
|
||||
};
|
||||
|
||||
@@ -39,6 +38,42 @@ export abstract class GFXBindingSetLayout {
|
||||
public abstract initialize(info : GFXBindingSetLayoutInfo) : boolean;
|
||||
public abstract destroy() : void;
|
||||
|
||||
public bindBuffer(binding: number, buffer: GFXBuffer) {
|
||||
for (let i = 0; i < this._bindingUnits.length; ++i) {
|
||||
let bindingUnit = this._bindingUnits[i];
|
||||
if (bindingUnit.type === GFXBindingType.UNIFORM_BUFFER) {
|
||||
bindingUnit.buffer = buffer;
|
||||
return;
|
||||
} else {
|
||||
console.error("Setting binding is not GFXBindingType.UNIFORM_BUFFER.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bindSampler(binding: number, sampler: GFXSampler) {
|
||||
for (let i = 0; i < this._bindingUnits.length; ++i) {
|
||||
let bindingUnit = this._bindingUnits[i];
|
||||
if (bindingUnit.type === GFXBindingType.SAMPLER) {
|
||||
bindingUnit.sampler = sampler;
|
||||
return;
|
||||
} else {
|
||||
console.error("Setting binding is not GFXBindingType.SAMPLER.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bindTextureView(binding: number, texView: GFXTextureView) {
|
||||
for (let i = 0; i < this._bindingUnits.length; ++i) {
|
||||
let bindingUnit = this._bindingUnits[i];
|
||||
if (bindingUnit.type === GFXBindingType.SAMPLER) {
|
||||
bindingUnit.texView = texView;
|
||||
return;
|
||||
} else {
|
||||
console.error("Setting binding is not GFXBindingType.SAMPLER.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected _device : GFXDevice;
|
||||
protected _bindingUnits : GFXBindingUnit[] = [];
|
||||
};
|
||||
|
||||
@@ -2,14 +2,12 @@ import { GFXDevice } from './gfx-device';
|
||||
|
||||
export const enum GFXBufferUsageBit {
|
||||
NONE = 0,
|
||||
MAP_READ = 0x1,
|
||||
MAP_WRITE = 0x2,
|
||||
TRANSFER_SRC = 0x4,
|
||||
TRANSFER_DST = 0x8,
|
||||
INDEX = 0x10,
|
||||
VERTEX = 0x20,
|
||||
UNIFORM = 0x40,
|
||||
STORAGE = 0x80,
|
||||
TRANSFER_SRC = 0x1,
|
||||
TRANSFER_DST = 0x2,
|
||||
INDEX = 0x4,
|
||||
VERTEX = 0x8,
|
||||
UNIFORM = 0x10,
|
||||
STORAGE = 0x20,
|
||||
};
|
||||
|
||||
export type GFXBufferUsage = GFXBufferUsageBit;
|
||||
@@ -45,7 +43,7 @@ export abstract class GFXBuffer {
|
||||
|
||||
public abstract initialize(info : GFXBufferInfo) : boolean;
|
||||
public abstract destroy() : void;
|
||||
public abstract update(buffer : ArrayBuffer, offset : number);
|
||||
public abstract update(buffer : Buffer, offset : number);
|
||||
|
||||
public get usage(): GFXBufferUsage {
|
||||
return this._usage;
|
||||
@@ -63,7 +61,7 @@ export abstract class GFXBuffer {
|
||||
return this._stride;
|
||||
}
|
||||
|
||||
public get buffer(): ArrayBuffer | null {
|
||||
public get buffer(): Buffer | null {
|
||||
return this._buffer;
|
||||
}
|
||||
|
||||
@@ -72,5 +70,6 @@ export abstract class GFXBuffer {
|
||||
protected _memUsage : GFXMemoryUsage = GFXMemoryUsageBit.NONE;
|
||||
protected _size : number = 0;
|
||||
protected _stride : number = 1;
|
||||
protected _buffer : ArrayBuffer | null = null;
|
||||
protected _arrayBuffer : ArrayBuffer | null = null;
|
||||
protected _buffer: Buffer | null = null;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ export abstract class GFXCommandAllocator {
|
||||
}
|
||||
|
||||
public abstract initialize() : boolean;
|
||||
public abstract destroy() : void;
|
||||
public abstract destroy();
|
||||
|
||||
protected _device : GFXDevice;
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
import { GFXDevice } from './gfx-device';
|
||||
import { GFXCommandAllocator } from './gfx-command-allocator';
|
||||
import { GFXBuffer } from './gfx-buffer';
|
||||
import { GFXInputAssembler } from './gfx-input-assembler';
|
||||
import { GFXPipelineState } from './gfx-pipeline-state';
|
||||
import { GFXBindingSetLayout } from './gfx-binding-set-layout';
|
||||
|
||||
export const enum GFXCommandBufferType {
|
||||
PRIMARY,
|
||||
@@ -18,12 +22,21 @@ export abstract class GFXCommandBuffer {
|
||||
}
|
||||
|
||||
public abstract initialize(info : GFXCommandBufferInfo) : boolean;
|
||||
public abstract destroy() : void;
|
||||
public abstract destroy();
|
||||
|
||||
public abstract begin();
|
||||
public abstract end();
|
||||
public abstract bindPipelineState(pipelineState : GFXPipelineState);
|
||||
public abstract bindBindingSetLayout(bindingSetLayout : GFXBindingSetLayout);
|
||||
public abstract bindInputAssembler(inputAssembler : GFXInputAssembler);
|
||||
public abstract draw(inputAssembler : GFXInputAssembler);
|
||||
public abstract updateBuffer(buffer : GFXBuffer, data : ArrayBuffer, offset : number);
|
||||
|
||||
public get type(): number {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
protected _device : GFXDevice;
|
||||
protected _allocator : GFXCommandAllocator | null = null;
|
||||
protected _type : GFXCommandBufferType = GFXCommandBufferType.PRIMARY;
|
||||
};
|
||||
|
||||
@@ -182,6 +182,7 @@ export const enum GFXFormat {
|
||||
export class GFXFormatInfo {
|
||||
readonly name : string = "UNKNOWN";
|
||||
readonly size : number = 0;
|
||||
readonly count : number = 0;
|
||||
readonly isFloating : boolean = false;
|
||||
readonly hasAlpha : boolean = false;
|
||||
readonly hasDepth : boolean = false;
|
||||
@@ -191,107 +192,107 @@ export class GFXFormatInfo {
|
||||
|
||||
export const GFXFormatInfos : GFXFormatInfo[] = [
|
||||
|
||||
{ name : "UNKNOWN", size : 0, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "UNKNOWN", size : 0, count : 0, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
|
||||
{ name : "A8", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "L8", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "LA8", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "A8", size : 1, count : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "L8", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "LA8", size : 1, count : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
|
||||
{ name : "R8", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R8SN", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R8UI", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R8I", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R16F", size : 2, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R16UI", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R16I", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R32F", size : 4, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R32UI", size : 4, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R32I", size : 4, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R8", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R8SN", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R8UI", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R8I", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R16F", size : 2, count : 1, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R16UI", size : 2, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R16I", size : 2, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R32F", size : 4, count : 1, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R32UI", size : 4, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R32I", size : 4, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
|
||||
{ name : "RG8", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG8SN", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG8UI", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG8I", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG16F", size : 4, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG16UI", size : 4, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG16I", size : 4, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG32F", size : 8, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG32UI", size : 8, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG32I", size : 8, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG8", size : 2, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG8SN", size : 2, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG8UI", size : 2, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG8I", size : 2, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG16F", size : 4, count : 2, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG16UI", size : 4, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG16I", size : 4, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG32F", size : 8, count : 2, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG32UI", size : 8, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RG32I", size : 8, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
|
||||
{ name : "RGB8", size : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "SRGB8", size : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB8SN", size : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB8UI", size : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB8I", size : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB16F", size : 6, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB16UI", size : 6, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB16I", size : 6, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB32F", size : 12, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB32UI", size : 12, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB32I", size : 12, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB8", size : 3, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "SRGB8", size : 3, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB8SN", size : 3, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB8UI", size : 3, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB8I", size : 3, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB16F", size : 6, count : 3, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB16UI", size : 6, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB16I", size : 6, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB32F", size : 12, count : 3, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB32UI", size : 12, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB32I", size : 12, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
|
||||
{ name : "RGBA8", size : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "SRGB8_A8", size : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA8SN", size : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA8UI", size : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA8I", size : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA16F", size : 8, isFloating : true, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA16UI", size : 8, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA16I", size : 8, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA32F", size : 16, isFloating : true, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA32UI", size : 16, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA32I", size : 16, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA8", size : 4, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "SRGB8_A8", size : 4, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA8SN", size : 4, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA8UI", size : 4, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA8I", size : 4, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA16F", size : 8, count : 4, isFloating : true, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA16UI", size : 8, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA16I", size : 8, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA32F", size : 16, count : 4, isFloating : true, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA32UI", size : 16, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA32I", size : 16, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
|
||||
{ name : "R5G6B5", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R11G11B10F", size : 4, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB5A1", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA4", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB10A2", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB10A2UI", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB9E5", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R5G6B5", size : 2, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "R11G11B10F", size : 4, count : 3, isFloating : true, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB5A1", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGBA4", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB10A2", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB10A2UI", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
{ name : "RGB9E5", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : false },
|
||||
|
||||
{ name : "D16", size : 2, isFloating : false, hasAlpha : false, hasDepth : true, hasStencil : false, isCompressed : false },
|
||||
{ name : "D24", size : 3, isFloating : false, hasAlpha : false, hasDepth : true, hasStencil : false, isCompressed : false },
|
||||
{ name : "D24S8", size : 4, isFloating : false, hasAlpha : false, hasDepth : true, hasStencil : true, isCompressed : false },
|
||||
{ name : "D32F", size : 4, isFloating : true, hasAlpha : false, hasDepth : true, hasStencil : false, isCompressed : false },
|
||||
{ name : "D32FS8", size : 5, isFloating : true, hasAlpha : false, hasDepth : true, hasStencil : true, isCompressed : false },
|
||||
{ name : "D16", size : 2, count : 1, isFloating : false, hasAlpha : false, hasDepth : true, hasStencil : false, isCompressed : false },
|
||||
{ name : "D24", size : 3, count : 1, isFloating : false, hasAlpha : false, hasDepth : true, hasStencil : false, isCompressed : false },
|
||||
{ name : "D24S8", size : 4, count : 2, isFloating : false, hasAlpha : false, hasDepth : true, hasStencil : true, isCompressed : false },
|
||||
{ name : "D32F", size : 4, count : 1, isFloating : true, hasAlpha : false, hasDepth : true, hasStencil : false, isCompressed : false },
|
||||
{ name : "D32FS8", size : 5, count : 2, isFloating : true, hasAlpha : false, hasDepth : true, hasStencil : true, isCompressed : false },
|
||||
|
||||
{ name : "BC1", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC1_ALPHA", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC1_SRGB", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC1_SRGB_ALPHA", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC2", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC2_SRGB", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC3", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC3_SRGB", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC4", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC4_SNORM", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC5", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC5_SNORM", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC6H_UF16", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC6H_SF16", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC7", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC7_SRGB", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC1", size : 1, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC1_ALPHA", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC1_SRGB", size : 1, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC1_SRGB_ALPHA", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC2", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC2_SRGB", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC3", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC3_SRGB", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC4", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC4_SNORM", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC5", size : 1, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC5_SNORM", size : 1, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC6H_UF16", size : 1, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC6H_SF16", size : 1, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC7", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "BC7_SRGB", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
|
||||
{ name : "ETC_RGB8", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_RGB8", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_SRGB8", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_RGB8_A1", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_SRGB8_A1", size : 1, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_RGBA8", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_SRGB8_A8", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "EAC_R11", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "EAC_R11SN", size : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "EAC_RG11", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "EAC_RG11SN", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC_RGB8", size : 1, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_RGB8", size : 1, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_SRGB8", size : 1, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_RGB8_A1", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_SRGB8_A1", size : 1, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_RGBA8", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "ETC2_SRGB8_A8", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "EAC_R11", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "EAC_R11SN", size : 1, count : 1, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "EAC_RG11", size : 2, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "EAC_RG11SN", size : 2, count : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
|
||||
{ name : "PVRTC_RGB2", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC_RGBA2", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC_RGB4", size : 2, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC_RGBA4", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC2_2BPP", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC2_4BPP", size : 2, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC_RGB2", size : 2, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC_RGBA2", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC_RGB4", size : 2, count : 3, isFloating : false, hasAlpha : false, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC_RGBA4", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC2_2BPP", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
{ name : "PVRTC2_4BPP", size : 2, count : 4, isFloating : false, hasAlpha : true, hasDepth : false, hasStencil : false, isCompressed : true },
|
||||
];
|
||||
|
||||
export function GFXFormatSize(format : GFXFormat, width : number, height : number, depth : number) : number {
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import { GFXDevice } from './gfx-device';
|
||||
import { GFXFormat } from './gfx-define';
|
||||
import { GFXBuffer } from './gfx-buffer';
|
||||
import { GFXShader } from './gfx-shader';
|
||||
|
||||
export class GFXInputAttribute {
|
||||
name: string = "";
|
||||
format: GFXFormat = GFXFormat.UNKNOWN;
|
||||
stream: number = 0;
|
||||
isInstanced: boolean = false;
|
||||
};
|
||||
|
||||
export class GFXInputAssemblerInfo {
|
||||
attributes: GFXInputAttribute[] = [];
|
||||
shader: GFXShader | null = null;
|
||||
vertexBuffers: GFXBuffer[] = [];
|
||||
indexBuffer: GFXBuffer | null = null;
|
||||
isIndirect: boolean = false;
|
||||
};
|
||||
|
||||
export abstract class GFXInputAssembler {
|
||||
|
||||
constructor(device: GFXDevice) {
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize(info: GFXInputAssemblerInfo): boolean;
|
||||
public abstract destroy(): void;
|
||||
|
||||
public get vertexBuffers(): GFXBuffer[] {
|
||||
return this._vertexBuffers;
|
||||
}
|
||||
|
||||
public get indexBuffer(): GFXBuffer | null {
|
||||
return this._indexBuffer;
|
||||
}
|
||||
|
||||
public getVertexBuffer(stream: number): GFXBuffer | null {
|
||||
if (stream < this._vertexBuffers.length) {
|
||||
return this._vertexBuffers[stream];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public get vertexCount(): number {
|
||||
return this._vertexCount;
|
||||
}
|
||||
|
||||
public set vertexCount(count : number) {
|
||||
this._vertexCount = count;
|
||||
}
|
||||
|
||||
public get firstVertex(): number {
|
||||
return this._firstVertex;
|
||||
}
|
||||
|
||||
public set firstVertex(first : number) {
|
||||
this._firstVertex = first;
|
||||
}
|
||||
|
||||
public get indexCount(): number {
|
||||
return this._indexCount;
|
||||
}
|
||||
|
||||
public set indexCount(count : number) {
|
||||
this._indexCount = count;
|
||||
}
|
||||
|
||||
public get firstIndex(): number {
|
||||
return this._firstIndex;
|
||||
}
|
||||
|
||||
public set firstIndex(first : number) {
|
||||
this._firstIndex = first;
|
||||
}
|
||||
|
||||
public get vertexOffset(): number {
|
||||
return this._vertexOffset;
|
||||
}
|
||||
|
||||
public set vertexOffset(offset : number) {
|
||||
this._vertexOffset = offset;
|
||||
}
|
||||
|
||||
public get instanceCount(): number {
|
||||
return this._instanceCount;
|
||||
}
|
||||
|
||||
public set instanceCount(count : number) {
|
||||
this._instanceCount = count;
|
||||
}
|
||||
|
||||
public get firstInstance(): number {
|
||||
return this._firstInstance;
|
||||
}
|
||||
|
||||
public set firstInstance(first : number) {
|
||||
this._firstInstance = first;
|
||||
}
|
||||
|
||||
protected _device: GFXDevice;
|
||||
protected _attributes: GFXInputAttribute[] = [];
|
||||
protected _vertexBuffers: GFXBuffer[] = [];
|
||||
protected _indexBuffer: GFXBuffer | null = null;
|
||||
protected _vertexCount: number = 0;
|
||||
protected _firstVertex: number = 0;
|
||||
protected _indexCount: number = 0;
|
||||
protected _firstIndex: number = 0;
|
||||
protected _vertexOffset: number = 0;
|
||||
protected _instanceCount: number = 0;
|
||||
protected _firstInstance: number = 0;
|
||||
|
||||
protected _isIndirect: boolean = false;
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
import { GFXDevice } from './gfx-device';
|
||||
import { GFX_MAX_VERTEX_ATTRIBUTES, GFXFormat } from './gfx-define';
|
||||
|
||||
export class GFXInputAttribute {
|
||||
name : string = "";
|
||||
format : GFXFormat = GFXFormat.UNKNOWN;
|
||||
//offset : number = 0;
|
||||
isInstanced : boolean = false;
|
||||
};
|
||||
|
||||
export class GFXInputStateInfo {
|
||||
attributes: GFXInputAttribute[] = [];
|
||||
};
|
||||
|
||||
export abstract class GFXInputState {
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public abstract initialize(info : GFXInputStateInfo) : boolean;
|
||||
public abstract destroy() : void;
|
||||
|
||||
protected _device : GFXDevice;
|
||||
protected _attributes: GFXInputAttribute[] = [];
|
||||
};
|
||||
@@ -1,5 +1,4 @@
|
||||
import { GFXDevice } from './gfx-device';
|
||||
import { GFXRenderPass } from './gfx-render-pass';
|
||||
import { GFXBindingSetLayout } from './gfx-binding-set-layout';
|
||||
import { GFXShaderType } from './gfx-shader';
|
||||
|
||||
@@ -24,5 +23,6 @@ export abstract class GFXPipelineLayout {
|
||||
public abstract destroy() : void;
|
||||
|
||||
protected _device : GFXDevice;
|
||||
protected _renderPass: GFXRenderPass | null = null;
|
||||
protected _pushConstantsRanges : GFXPushConstantRange[] = [];
|
||||
protected _layouts: GFXBindingSetLayout[] = [];
|
||||
};
|
||||
|
||||
@@ -2,6 +2,8 @@ import { GFXDevice } from './gfx-device';
|
||||
import { GFX_MAX_VERTEX_ATTRIBUTES, GFXFormat } from './gfx-define';
|
||||
import { GFXShader } from './gfx-shader';
|
||||
import { GFXRenderPass } from './gfx-render-pass';
|
||||
import { GFXPipelineLayout } from './gfx-pipeline-layout';
|
||||
import { GFXInputAttribute } from './gfx-input-assembler';
|
||||
|
||||
export const enum GFXPrimitiveMode {
|
||||
POINT_LIST,
|
||||
@@ -132,7 +134,7 @@ export class GFXDepthStencilState {
|
||||
frontStencilWriteMask : number = 0xffffffff;
|
||||
frontStencilFailOp : GFXStencilOp = GFXStencilOp.KEEP;
|
||||
frontStencilDepthFailOp : GFXStencilOp = GFXStencilOp.KEEP;
|
||||
frontStencilPassFailOp : GFXStencilOp = GFXStencilOp.KEEP;
|
||||
frontStencilPassOp : GFXStencilOp = GFXStencilOp.KEEP;
|
||||
frontStencilRef : number = 1;
|
||||
isBackStencilTest : boolean = false;
|
||||
backStencilFunc : GFXComparisonFunc = GFXComparisonFunc.ALWAYS;
|
||||
@@ -140,7 +142,7 @@ export class GFXDepthStencilState {
|
||||
backStencilWriteMask : number = 0xffffffff;
|
||||
backStencilFailOp : GFXStencilOp = GFXStencilOp.KEEP;
|
||||
backStencilDepthFailOp : GFXStencilOp = GFXStencilOp.KEEP;
|
||||
backStencilPassFailOp : GFXStencilOp = GFXStencilOp.KEEP;
|
||||
backStencilPassOp : GFXStencilOp = GFXStencilOp.KEEP;
|
||||
backStencilRef : number = 1;
|
||||
|
||||
public compare(state : GFXDepthStencilState) : boolean {
|
||||
@@ -153,7 +155,7 @@ export class GFXDepthStencilState {
|
||||
(this.frontStencilWriteMask === state.frontStencilWriteMask) &&
|
||||
(this.frontStencilFailOp === state.frontStencilFailOp) &&
|
||||
(this.frontStencilDepthFailOp === state.frontStencilDepthFailOp) &&
|
||||
(this.frontStencilPassFailOp === state.frontStencilPassFailOp) &&
|
||||
(this.frontStencilPassOp === state.frontStencilPassOp) &&
|
||||
(this.frontStencilRef === state.frontStencilRef) &&
|
||||
(this.isBackStencilTest === state.isBackStencilTest) &&
|
||||
(this.backStencilFunc === state.backStencilFunc) &&
|
||||
@@ -161,7 +163,7 @@ export class GFXDepthStencilState {
|
||||
(this.backStencilWriteMask === state.backStencilWriteMask) &&
|
||||
(this.backStencilFailOp === state.backStencilFailOp) &&
|
||||
(this.backStencilDepthFailOp === state.backStencilDepthFailOp) &&
|
||||
(this.backStencilPassFailOp === state.backStencilPassFailOp) &&
|
||||
(this.backStencilPassOp === state.backStencilPassOp) &&
|
||||
(this.backStencilRef === state.backStencilRef);
|
||||
}
|
||||
};
|
||||
@@ -196,12 +198,18 @@ export class GFXBlendState {
|
||||
targets : GFXBlendTarget[] = [new GFXBlendTarget];
|
||||
}
|
||||
|
||||
export class GFXInputState {
|
||||
attributes: GFXInputAttribute[] = [];
|
||||
};
|
||||
|
||||
export class GFXPipelineStateInfo {
|
||||
primitiveMode : GFXPrimitiveMode = GFXPrimitiveMode.TRIANGLE_LIST;
|
||||
primitive : GFXPrimitiveMode = GFXPrimitiveMode.TRIANGLE_LIST;
|
||||
shader : GFXShader | null = null;
|
||||
is : GFXInputState | null = null;
|
||||
rs : GFXRasterizerState | null = null;
|
||||
dss : GFXDepthStencilState | null = null;
|
||||
bs : GFXBlendState = new GFXBlendState;
|
||||
bs : GFXBlendState | null = null;
|
||||
layout : GFXPipelineLayout | null = null;
|
||||
renderPass : GFXRenderPass | null = null;
|
||||
};
|
||||
|
||||
@@ -216,8 +224,11 @@ export abstract class GFXPipelineState {
|
||||
|
||||
protected _device : GFXDevice;
|
||||
protected _shader : GFXShader | null = null;
|
||||
protected _primitive : GFXPrimitiveMode = GFXPrimitiveMode.TRIANGLE_LIST;
|
||||
protected _is : GFXInputState | null = null;
|
||||
protected _rs : GFXRasterizerState | null = null;
|
||||
protected _dss : GFXDepthStencilState | null = null;
|
||||
protected _bs : GFXBlendState | null = null;
|
||||
protected _layout: GFXPipelineLayout | null = null;
|
||||
protected _renderPass: GFXRenderPass | null = null;
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@ export const enum GFXTextureLayout
|
||||
PRESENT_SRC,
|
||||
};
|
||||
|
||||
export class ColorAttachmentInfo
|
||||
export class GFXColorAttachment
|
||||
{
|
||||
format : GFXFormat = GFXFormat.UNKNOWN;
|
||||
loadOp : GFXLoadOp = GFXLoadOp.CLEAR;
|
||||
@@ -40,11 +40,11 @@ export class ColorAttachmentInfo
|
||||
endLayout : GFXTextureLayout = GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL;
|
||||
};
|
||||
|
||||
export class DepthStencilAttachmentInfo
|
||||
export class GFXDepthStencilAttachment
|
||||
{
|
||||
format : GFXFormat = GFXFormat.UNKNOWN;
|
||||
loadOp : GFXLoadOp = GFXLoadOp.CLEAR;
|
||||
storeOp : GFXStoreOp = GFXStoreOp.STORE;
|
||||
depthLoadOp : GFXLoadOp = GFXLoadOp.CLEAR;
|
||||
depthStoreOp : GFXStoreOp = GFXStoreOp.STORE;
|
||||
stencilLoadOp : GFXLoadOp = GFXLoadOp.CLEAR;
|
||||
stencilStoreOp : GFXStoreOp = GFXStoreOp.STORE;
|
||||
sampleCount : number = 1;
|
||||
@@ -71,8 +71,8 @@ export class GFXSubPassInfo
|
||||
|
||||
export class GFXRenderPassInfo
|
||||
{
|
||||
colorInfos : ColorAttachmentInfo[] = [];
|
||||
depthStencilInfo : DepthStencilAttachmentInfo | null = null;
|
||||
colorInfos : GFXColorAttachment[] = [];
|
||||
depthStencilInfo : GFXDepthStencilAttachment | null = null;
|
||||
subPasses : GFXSubPassInfo[] = [];
|
||||
};
|
||||
|
||||
@@ -86,7 +86,7 @@ export abstract class GFXRenderPass {
|
||||
public abstract destroy() : void;
|
||||
|
||||
protected _device : GFXDevice;
|
||||
protected _colorInfos : ColorAttachmentInfo[] = [];
|
||||
protected _depthStencilInfo : DepthStencilAttachmentInfo | null = null;
|
||||
protected _colorInfos : GFXColorAttachment[] = [];
|
||||
protected _depthStencilInfo : GFXDepthStencilAttachment | null = null;
|
||||
protected _subPasses : GFXSubPassInfo[] = [];
|
||||
};
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { GFXDevice } from './gfx-device';
|
||||
import { GFXComparisonFunc } from './gfx-pipeline-state';
|
||||
|
||||
export const enum GFXFilterOp {
|
||||
export const enum GFXFilter {
|
||||
NONE,
|
||||
POINT,
|
||||
LINEAR,
|
||||
ANISOTROPIC,
|
||||
};
|
||||
|
||||
export const enum GFXAddressMode {
|
||||
export const enum GFXAddress {
|
||||
WRAP,
|
||||
MIRROR,
|
||||
CLAMP,
|
||||
@@ -17,12 +17,12 @@ export const enum GFXAddressMode {
|
||||
|
||||
export class GFXSamplerInfo {
|
||||
name : string = "";
|
||||
minFilter : GFXFilterOp = GFXFilterOp.LINEAR;
|
||||
magFilter : GFXFilterOp = GFXFilterOp.LINEAR;
|
||||
mipFilter : GFXFilterOp = GFXFilterOp.LINEAR;
|
||||
addressU : GFXAddressMode = GFXAddressMode.WRAP;
|
||||
addressV : GFXAddressMode = GFXAddressMode.WRAP;
|
||||
addressW : GFXAddressMode = GFXAddressMode.WRAP;
|
||||
minFilter : GFXFilter = GFXFilter.LINEAR;
|
||||
magFilter : GFXFilter = GFXFilter.LINEAR;
|
||||
mipFilter : GFXFilter = GFXFilter.LINEAR;
|
||||
addressU : GFXAddress = GFXAddress.WRAP;
|
||||
addressV : GFXAddress = GFXAddress.WRAP;
|
||||
addressW : GFXAddress = GFXAddress.WRAP;
|
||||
maxAnisotropy : number = 16;
|
||||
cmpFunc : GFXComparisonFunc = GFXComparisonFunc.NEVER;
|
||||
borderColor : number[] = [0.0, 0.0, 0.0, 0.0];
|
||||
@@ -57,12 +57,12 @@ export abstract class GFXSampler {
|
||||
|
||||
protected _device : GFXDevice;
|
||||
protected _name : string = "";
|
||||
protected _minFilter : GFXFilterOp = GFXFilterOp.LINEAR;
|
||||
protected _magFilter : GFXFilterOp = GFXFilterOp.LINEAR;
|
||||
protected _mipFilter : GFXFilterOp = GFXFilterOp.LINEAR;
|
||||
protected _addressU : GFXAddressMode = GFXAddressMode.WRAP;
|
||||
protected _addressV : GFXAddressMode = GFXAddressMode.WRAP;
|
||||
protected _addressW : GFXAddressMode = GFXAddressMode.WRAP;
|
||||
protected _minFilter : GFXFilter = GFXFilter.LINEAR;
|
||||
protected _magFilter : GFXFilter = GFXFilter.LINEAR;
|
||||
protected _mipFilter : GFXFilter = GFXFilter.LINEAR;
|
||||
protected _addressU : GFXAddress = GFXAddress.WRAP;
|
||||
protected _addressV : GFXAddress = GFXAddress.WRAP;
|
||||
protected _addressW : GFXAddress = GFXAddress.WRAP;
|
||||
protected _maxAnisotropy : number = 16;
|
||||
protected _cmpFunc : GFXComparisonFunc = GFXComparisonFunc.NEVER;
|
||||
protected _borderColor : number[] = [0.0, 0.0, 0.0, 0.0];
|
||||
|
||||
@@ -22,28 +22,17 @@ export class GFXShaderMacro {
|
||||
}
|
||||
};
|
||||
|
||||
export class GFXShaderVar {
|
||||
binding : number = -1;
|
||||
export class GFXUniform {
|
||||
name : string = "";
|
||||
type : GFXType = GFXType.UNKNOWN;
|
||||
stride : number = 0;
|
||||
count : number = 0;
|
||||
size : number = 0;
|
||||
offset : number = 0;
|
||||
count : number = 1;
|
||||
};
|
||||
|
||||
export class GFXShaderBlock {
|
||||
export class GFXUniformBlock {
|
||||
binding : number = -1;
|
||||
name : string = "";
|
||||
size : number = 0;
|
||||
uniforms : GFXShaderVar[] = [];
|
||||
};
|
||||
|
||||
export class GFXShaderSampler {
|
||||
binding : number = -1;
|
||||
name : string = "";
|
||||
type : GFXType = GFXType.UNKNOWN;
|
||||
units : number[] = [];
|
||||
//instance : string = "";
|
||||
uniforms : GFXUniform[] = [];
|
||||
};
|
||||
|
||||
export class GFXShaderStage {
|
||||
@@ -60,6 +49,9 @@ export class GFXShaderInfo {
|
||||
name : string = "";
|
||||
stages : GFXShaderStage[] = [];
|
||||
bindings : GFXBinding[] = [];
|
||||
|
||||
// blocks are used for being compatible with single uniforms
|
||||
blocks : GFXUniformBlock[] = [];
|
||||
};
|
||||
|
||||
export abstract class GFXShader {
|
||||
@@ -75,9 +67,5 @@ export abstract class GFXShader {
|
||||
protected _name : string = "";
|
||||
protected _stages : GFXShaderStage[] = [];
|
||||
protected _bindings : GFXBinding[] = [];
|
||||
|
||||
protected _inputs : GFXShaderVar[] = [];
|
||||
protected _uniforms : GFXShaderVar[] = [];
|
||||
protected _blocks : GFXShaderBlock[] = [];
|
||||
protected _samplers : GFXShaderSampler[] = [];
|
||||
protected _blocks : GFXUniformBlock[] = [];
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
import { WebGLGPUBindingSetLayout } from './webgl-gpu-objects';
|
||||
import { GFXBindingSetLayout, GFXBindingSetLayoutInfo, GFXBindingType } from '../gfx-binding-set-layout';
|
||||
import { GFXBuffer } from '../gfx-buffer';
|
||||
import { GFXSampler } from '../gfx-sampler';
|
||||
import { GFXTextureView } from '../gfx-texture-view';
|
||||
|
||||
export class WebGLGFXBindingSetLayout extends GFXBindingSetLayout {
|
||||
|
||||
constructor(device: GFXDevice) {
|
||||
super(device);
|
||||
}
|
||||
|
||||
public initialize(info: GFXBindingSetLayoutInfo): boolean {
|
||||
|
||||
for (let i = 0; i < info.bindings.length; ++i) {
|
||||
let binding = info.bindings[i];
|
||||
|
||||
this._bindingUnits.push({
|
||||
binding: binding.binding,
|
||||
type: binding.type,
|
||||
name: binding.name,
|
||||
buffer: null,
|
||||
texView: null,
|
||||
sampler: null,
|
||||
});
|
||||
}
|
||||
|
||||
this._gpuBindingSetLayout = this.webGLDevice.emitCmdCreateGPUBindingSetLayout(info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
if (this._gpuBindingSetLayout) {
|
||||
this.webGLDevice.emitCmdDestroyGPUBindingSetLayout(this._gpuBindingSetLayout);
|
||||
this._gpuBindingSetLayout = null;
|
||||
}
|
||||
}
|
||||
|
||||
public update() {
|
||||
|
||||
}
|
||||
|
||||
public get webGLDevice(): WebGLGFXDevice {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuBindingSetLayout(): WebGLGPUBindingSetLayout | null {
|
||||
return this._gpuBindingSetLayout;
|
||||
}
|
||||
|
||||
private _gpuBindingSetLayout: WebGLGPUBindingSetLayout | null = null;
|
||||
};
|
||||
@@ -5,11 +5,11 @@ import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
|
||||
export class WebGLGFXBuffer extends GFXBuffer {
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
constructor(device: GFXDevice) {
|
||||
super(device);
|
||||
}
|
||||
|
||||
public initialize(info : GFXBufferInfo) : boolean {
|
||||
public initialize(info: GFXBufferInfo): boolean {
|
||||
|
||||
this._usage = info.usage;
|
||||
this._memUsage = info.memUsage;
|
||||
@@ -17,46 +17,48 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
this._stride = info.stride;
|
||||
|
||||
if (this._memUsage & GFXMemoryUsageBit.HOST) {
|
||||
this._buffer = new ArrayBuffer(this._size);
|
||||
this._arrayBuffer = new ArrayBuffer(this._size);
|
||||
this._buffer = new Buffer(this._arrayBuffer);
|
||||
}
|
||||
|
||||
this._isSimulate = (this._usage & GFXBufferUsageBit.TRANSFER_SRC) != GFXBufferUsageBit.NONE;
|
||||
|
||||
if (!this._isSimulate) {
|
||||
this._gpuBuffer = this.webGLDevice.emitCmdCreateGPUBuffer(info);
|
||||
if (!this._isSimulate || this._usage & GFXBufferUsageBit.UNIFORM) {
|
||||
this._gpuBuffer = this.webGLDevice.emitCmdCreateGPUBuffer(info, this._buffer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
if(this._gpuBuffer) {
|
||||
if (this._gpuBuffer) {
|
||||
this.webGLDevice.emitCmdDestroyGPUBuffer(this._gpuBuffer);
|
||||
this._buffer = null;
|
||||
this._gpuBuffer = null;
|
||||
}
|
||||
|
||||
this._arrayBuffer = null;
|
||||
this._buffer = null;
|
||||
}
|
||||
|
||||
public update(buffer: Buffer, offset: number) {
|
||||
|
||||
if (this._buffer) {
|
||||
this._buffer.set(buffer, offset);
|
||||
}
|
||||
|
||||
if (!this._isSimulate && this._buffer) {
|
||||
this.webGLDevice.emitCmdUpdateGPUBuffer(<WebGLGPUBuffer>this._gpuBuffer, offset, this._buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public update(buffer : ArrayBuffer, offset : number) {
|
||||
|
||||
if(this._buffer) {
|
||||
let srcView : Uint8Array = new Uint8Array(buffer);
|
||||
let dstView : Uint8Array = new Uint8Array(this._buffer, offset);
|
||||
dstView.set(srcView);
|
||||
}
|
||||
|
||||
if(!this._isSimulate) {
|
||||
this.webGLDevice.emitCmdUpdateGPUBuffer(<WebGLGPUBuffer>this._gpuBuffer, offset, <ArrayBuffer>this._buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public get webGLDevice() : WebGLGFXDevice {
|
||||
public get webGLDevice(): WebGLGFXDevice {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuBuffer() : WebGLGPUBuffer | null {
|
||||
public get gpuBuffer(): WebGLGPUBuffer | null {
|
||||
return this._gpuBuffer;
|
||||
}
|
||||
|
||||
private _gpuBuffer : WebGLGPUBuffer | null = null;
|
||||
private _isSimulate : boolean = false;
|
||||
private _gpuBuffer: WebGLGPUBuffer | null = null;
|
||||
private _isSimulate: boolean = false;
|
||||
};
|
||||
|
||||
@@ -1,19 +1,65 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { GFXCommandAllocator } from '../gfx-command-allocator';
|
||||
import { WebGLCmdUpdateBuffer, WebGLCmdBeginRenderPass, WebGLCmdBindInputAssembler, WebGLCmdDraw, WebGLCmdBindPipelineState, WebGLCmdBindBindingSetLayout } from './webgl-commands';
|
||||
|
||||
export class WebGLGFXCommandPool<T> {
|
||||
|
||||
constructor(size: number) {
|
||||
this._commands = new Array(size);
|
||||
constructor(count: number, increase : number) {
|
||||
this._frees = new Array(count);
|
||||
this._freeIdx = count - 1;
|
||||
this._increase = increase;
|
||||
}
|
||||
|
||||
private _commands : T[];
|
||||
alloc(clazz: new() => T) : T | null {
|
||||
|
||||
if (this._freeIdx <= 0) {
|
||||
let size = this._frees.length + this._increase;
|
||||
let temp = this._frees;
|
||||
this._frees = new Array<T>(size);
|
||||
|
||||
for(let i = 0; i < temp.length; ++i) {
|
||||
this._frees[i] = temp[i];
|
||||
}
|
||||
|
||||
for(let i = temp.length + 1; i < size; ++i) {
|
||||
this._frees[i] = new clazz();
|
||||
}
|
||||
|
||||
this._freeIdx += (size - temp.length);
|
||||
}
|
||||
|
||||
let item = this._frees[this._freeIdx];
|
||||
this._frees[this._freeIdx--] = null;
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
free(cmd : T) {
|
||||
this._frees[++this._freeIdx] = cmd;
|
||||
}
|
||||
|
||||
private _frees : (T|null)[];
|
||||
private _freeIdx : number = 0;
|
||||
private _increase : number = 0;
|
||||
};
|
||||
|
||||
export class GFXWebGLCommandAllocator extends GFXCommandAllocator {
|
||||
export class WebGLGFXCommandAllocator extends GFXCommandAllocator {
|
||||
|
||||
beginRenderPassCmdPool : WebGLGFXCommandPool<WebGLCmdBeginRenderPass>;
|
||||
bindPipelineStateCmdPool : WebGLGFXCommandPool<WebGLCmdBindPipelineState>;
|
||||
bindBindingSetLayoutCmdPool : WebGLGFXCommandPool<WebGLCmdBindBindingSetLayout>;
|
||||
bindInputAssemblerCmdPool : WebGLGFXCommandPool<WebGLCmdBindInputAssembler>;
|
||||
drawCmdPool : WebGLGFXCommandPool<WebGLCmdDraw>;
|
||||
updateBufferCmdPool : WebGLGFXCommandPool<WebGLCmdUpdateBuffer>;
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
super(device);
|
||||
this.beginRenderPassCmdPool = new WebGLGFXCommandPool<WebGLCmdBeginRenderPass>(64, 32);
|
||||
this.bindPipelineStateCmdPool = new WebGLGFXCommandPool<WebGLCmdBindPipelineState>(64, 32);
|
||||
this.bindBindingSetLayoutCmdPool = new WebGLGFXCommandPool<WebGLCmdBindBindingSetLayout>(64, 32);
|
||||
this.bindInputAssemblerCmdPool = new WebGLGFXCommandPool<WebGLCmdBindInputAssembler>(64, 32);
|
||||
this.drawCmdPool = new WebGLGFXCommandPool<WebGLCmdDraw>(64, 32);
|
||||
this.updateBufferCmdPool = new WebGLGFXCommandPool<WebGLCmdUpdateBuffer>(64, 32);
|
||||
}
|
||||
|
||||
public initialize() : boolean {
|
||||
@@ -21,7 +67,7 @@ export class GFXWebGLCommandAllocator extends GFXCommandAllocator {
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() : void {
|
||||
public destroy() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { GFXCommandBuffer, GFXCommandBufferInfo } from '../gfx-command-buffer';
|
||||
import { GFXBuffer } from '../gfx-buffer';
|
||||
import { WebGLCmdUpdateBuffer, WebGLCmd, WebGLCmdBeginRenderPass, WebGLCmdPackage, WebGLCmdBindInputAssembler, WebGLCmdBindPipelineState, WebGLCmdDraw } from './webgl-commands';
|
||||
import { WebGLGFXCommandAllocator } from './webgl-gfx-command-allocator';
|
||||
import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
import { WebGLGFXBuffer } from './webgl-gfx-buffer';
|
||||
import { GFXFramebuffer } from '../gfx-framebuffer';
|
||||
import { WebGLGFXFramebuffer } from './webgl-gfx-framebuffer';
|
||||
import { GFXInputAssembler } from '../gfx-input-assembler';
|
||||
import { WebGLGFXInputAssembler } from './webgl-gfx-input-assembler';
|
||||
import { GFXPipelineState } from '../gfx-pipeline-state';
|
||||
import { WebGLGFXPipelineLayout } from './webgl-gfx-pipeline-layout';
|
||||
import { WebGLGFXPipelineState } from './webgl-gfx-pipeline-state';
|
||||
import { GFXBindingSetLayout } from '../gfx-binding-set-layout';
|
||||
|
||||
export class WebGLGFXCommandBuffer extends GFXCommandBuffer {
|
||||
|
||||
cmdPackage : WebGLCmdPackage = new WebGLCmdPackage;
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
super(device);
|
||||
}
|
||||
|
||||
public initialize(info : GFXCommandBufferInfo) : boolean {
|
||||
|
||||
if(!info.allocator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._allocator = info.allocator;
|
||||
this._type = info.type;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
if(this._allocator) {
|
||||
this.cmdPackage.clearCmds(<WebGLGFXCommandAllocator>this._allocator);
|
||||
}
|
||||
}
|
||||
|
||||
public begin() {
|
||||
if(this._allocator) {
|
||||
this.cmdPackage.clearCmds(<WebGLGFXCommandAllocator>this._allocator);
|
||||
}
|
||||
}
|
||||
|
||||
public end() {
|
||||
|
||||
}
|
||||
|
||||
public beginRenderPass(framebuffer : GFXFramebuffer, viewport : number[], numClearColors : number, clearColors : number[], clearStencil : number) {
|
||||
|
||||
let cmd = (<WebGLGFXCommandAllocator>this._allocator).beginRenderPassCmdPool.alloc(WebGLCmdBeginRenderPass);
|
||||
if (cmd) {
|
||||
cmd.gpuFramebuffer = (<WebGLGFXFramebuffer>framebuffer).gpuFramebuffer;
|
||||
cmd.viewport = viewport.slice();
|
||||
cmd.numClearColors = numClearColors;
|
||||
cmd.clearColors = clearColors.slice();
|
||||
cmd.clearStencil = clearStencil;
|
||||
this.cmdPackage.beginRenderPassCmds.push(cmd);
|
||||
|
||||
this.cmdPackage.cmds.push(WebGLCmd.BEGIN_RENDER_PASS);
|
||||
}
|
||||
}
|
||||
|
||||
public endRenderPass() {
|
||||
|
||||
}
|
||||
|
||||
public bindPipelineState(pipelineState : GFXPipelineState) {
|
||||
|
||||
let cmd = (<WebGLGFXCommandAllocator>this._allocator).bindPipelineStateCmdPool.alloc(WebGLCmdBindPipelineState);
|
||||
if (cmd) {
|
||||
cmd.gpuPipelineState = (<WebGLGFXPipelineState>pipelineState).gpuPipelineState;
|
||||
this.cmdPackage.bindPipelineStateCmds.push(cmd);
|
||||
|
||||
this.cmdPackage.cmds.push(WebGLCmd.BIND_PIPELINE_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
public bindBindingSetLayout(bindingSetLayout : GFXBindingSetLayout) {
|
||||
|
||||
// TODO
|
||||
|
||||
}
|
||||
|
||||
public bindInputAssembler(inputAssembler : GFXInputAssembler) {
|
||||
|
||||
let cmd = (<WebGLGFXCommandAllocator>this._allocator).bindInputAssemblerCmdPool.alloc(WebGLCmdBindInputAssembler);
|
||||
if (cmd) {
|
||||
cmd.gpuInputAssembler = (<WebGLGFXInputAssembler>inputAssembler).gpuInputAssembler;
|
||||
this.cmdPackage.bindInputAssemblerCmds.push(cmd);
|
||||
|
||||
this.cmdPackage.cmds.push(WebGLCmd.BIND_INPUT_ASSEMBLER);
|
||||
}
|
||||
}
|
||||
|
||||
public draw(inputAssembler : GFXInputAssembler) {
|
||||
let cmd = (<WebGLGFXCommandAllocator>this._allocator).drawCmdPool.alloc(WebGLCmdDraw);
|
||||
if (cmd) {
|
||||
cmd.vertexCount = inputAssembler.vertexCount;
|
||||
cmd.firstVertex = inputAssembler.firstVertex;
|
||||
cmd.indexCount = inputAssembler.indexCount;
|
||||
cmd.firstIndex = inputAssembler.firstIndex;
|
||||
cmd.vertexOffset = inputAssembler.vertexOffset;
|
||||
cmd.instanceCount = inputAssembler.instanceCount;
|
||||
cmd.firstInstance = inputAssembler.firstInstance;
|
||||
|
||||
this.cmdPackage.drawCmds.push(cmd);
|
||||
|
||||
this.cmdPackage.cmds.push(WebGLCmd.DRAW);
|
||||
}
|
||||
}
|
||||
|
||||
public updateBuffer(buffer : GFXBuffer, data : ArrayBuffer, offset : number) {
|
||||
|
||||
let gpuBuffer = (<WebGLGFXBuffer>buffer).gpuBuffer;
|
||||
if(gpuBuffer) {
|
||||
let cmd = (<WebGLGFXCommandAllocator>this._allocator).updateBufferCmdPool.alloc(WebGLCmdUpdateBuffer);
|
||||
if (cmd) {
|
||||
cmd.gpuBuffer = gpuBuffer;
|
||||
cmd.data = data.slice(0);
|
||||
cmd.offset = offset;
|
||||
this.cmdPackage.updateBufferCmds.push(cmd);
|
||||
|
||||
this.cmdPackage.cmds.push(WebGLCmd.UPDATE_BUFFER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public get webGLDevice() : WebGLGFXDevice {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
};
|
||||
@@ -3,8 +3,8 @@ import { GFXBuffer, GFXBufferInfo } from '../gfx-buffer';
|
||||
import { WebGLGFXBuffer } from './webgl-gfx-buffer';
|
||||
import { WebGLGFXQueue } from './webgl-gfx-queue';
|
||||
import { WebGLStateCache } from './webgl-state-cache';
|
||||
import { WebGLGPUBuffer, WebGLGPUObjectType, WebGLGPUTexture, WebGLGPURenderPass, WebGLGPUFramebuffer, WebGLGPUTextureView, WebGLGPUShader, WebGLGPUShaderStage } from './webgl-gpu-objects';
|
||||
import { WebGLCmdFuncUpdateBuffer, WebGLCmdFuncDestroyBuffer, WebGLCmdFuncCreateBuffer, WebGLCmdFuncDestroyTexture, WebGLCmdFuncCreateTexture, WebGLCmdFuncCreateFramebuffer, WebGLCmdFuncDestroyFramebuffer, WebGLCmdFuncCreateShader, WebGLCmdFuncDestroyShader } from './webgl-commands';
|
||||
import { WebGLGPUBuffer, WebGLGPUObjectType, WebGLGPUTexture, WebGLGPURenderPass, WebGLGPUFramebuffer, WebGLGPUTextureView, WebGLGPUShader, WebGLGPUShaderStage, WebGLGPUSampler, WebGLGPUInputAssembler, WebGLGPUPipelineState, WebGLGPUPipelineLayout, WebGLGPUBindingSetLayout, WebGLGPUBinding } from './webgl-gpu-objects';
|
||||
import { WebGLCmdFuncUpdateBuffer, WebGLCmdFuncDestroyBuffer, WebGLCmdFuncCreateBuffer, WebGLCmdFuncDestroyTexture, WebGLCmdFuncCreateTexture, WebGLCmdFuncCreateFramebuffer, WebGLCmdFuncDestroyFramebuffer, WebGLCmdFuncCreateShader, WebGLCmdFuncDestroyShader, WebGLCmdFuncCreateInputAssember, WebGLCmdFuncDestroyInputAssembler } from './webgl-commands';
|
||||
import { GFXTextureInfo, GFXTextureType, GFXTextureFlagBit } from '../gfx-texture';
|
||||
import { GFXTextureViewType, GFXTextureViewInfo } from '../gfx-texture-view';
|
||||
import { GFXRenderPassInfo } from '../gfx-render-pass';
|
||||
@@ -13,22 +13,50 @@ import { WebGLGFXRenderPass } from './webgl-gfx-render-pass';
|
||||
import { WebGLGFXTextureView } from './webgl-gfx-texture-view';
|
||||
import { WebGLGFXTexture } from './webgl-gfx-texture';
|
||||
import { GFXShaderInfo } from '../gfx-shader';
|
||||
import { GFXSamplerInfo } from '../gfx-sampler';
|
||||
import { WebGLGFXCommandAllocator } from './webgl-gfx-command-allocator';
|
||||
import { GFXInputAssemblerInfo } from '../gfx-input-assembler';
|
||||
import { WebGLGFXShader } from './webgl-gfx-shader';
|
||||
import { GFXCommandAllocator } from '../gfx-command-allocator';
|
||||
import { GFXPipelineStateInfo } from '../gfx-pipeline-state';
|
||||
import { WebGLGFXPipelineLayout } from './webgl-gfx-pipeline-layout';
|
||||
import { GFXBindingSetLayoutInfo } from '../gfx-binding-set-layout';
|
||||
|
||||
const WebGLPrimitives: GLenum[] = [
|
||||
WebGLRenderingContext.POINTS,
|
||||
WebGLRenderingContext.LINES,
|
||||
WebGLRenderingContext.LINE_STRIP,
|
||||
WebGLRenderingContext.LINE_LOOP,
|
||||
WebGLRenderingContext.TRIANGLES,
|
||||
WebGLRenderingContext.TRIANGLE_STRIP,
|
||||
WebGLRenderingContext.TRIANGLE_FAN,
|
||||
WebGLRenderingContext.NONE,
|
||||
WebGLRenderingContext.NONE,
|
||||
WebGLRenderingContext.NONE,
|
||||
WebGLRenderingContext.NONE,
|
||||
WebGLRenderingContext.NONE,
|
||||
WebGLRenderingContext.NONE,
|
||||
WebGLRenderingContext.NONE,
|
||||
];
|
||||
|
||||
export class WebGLGFXDevice extends GFXDevice {
|
||||
|
||||
stateCache : WebGLStateCache = new WebGLStateCache;
|
||||
|
||||
constructor(canvasEL : HTMLElement) {
|
||||
|
||||
stateCache: WebGLStateCache = new WebGLStateCache;
|
||||
webGLCmdAllocator: WebGLGFXCommandAllocator;
|
||||
|
||||
constructor(canvasEL: HTMLElement) {
|
||||
|
||||
super();
|
||||
|
||||
this.webGLCmdAllocator = new WebGLGFXCommandAllocator(this);
|
||||
|
||||
try {
|
||||
this._webGLRC = (<HTMLCanvasElement>canvasEL).getContext('webgl');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// No errors are thrown using try catch
|
||||
// Tested through ios baidu browser 4.14.1
|
||||
if (!this._webGLRC) {
|
||||
@@ -36,24 +64,28 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
}
|
||||
}
|
||||
|
||||
public initialize(info : GFXDeviceInfo) : boolean {
|
||||
public initialize(info: GFXDeviceInfo): boolean {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() : void {
|
||||
public destroy(): void {
|
||||
|
||||
}
|
||||
|
||||
public createBuffer() : GFXBuffer {
|
||||
public createBuffer(): GFXBuffer {
|
||||
return new WebGLGFXBuffer(this);
|
||||
}
|
||||
|
||||
public getDeviceName() : string {
|
||||
public createCommandAllocator(): GFXCommandAllocator {
|
||||
return new WebGLGFXCommandAllocator(this);
|
||||
}
|
||||
|
||||
public getDeviceName(): string {
|
||||
return "WebGLDevice";
|
||||
}
|
||||
|
||||
public get gl() : WebGLRenderingContext {
|
||||
public get gl(): WebGLRenderingContext {
|
||||
return <WebGLRenderingContext>this._webGLRC;
|
||||
}
|
||||
|
||||
@@ -61,18 +93,25 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
return <WebGLGFXQueue>this._queue;
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUBuffer(info : GFXBufferInfo) : WebGLGPUBuffer {
|
||||
public emitCmdCreateGPUBuffer(info: GFXBufferInfo, buffer : Buffer | null): WebGLGPUBuffer | null {
|
||||
|
||||
let gpuBuffer : WebGLGPUBuffer = {
|
||||
objType : WebGLGPUObjectType.BUFFER,
|
||||
usage : info.usage,
|
||||
memUsage : info.memUsage,
|
||||
size : info.size,
|
||||
stride : info.stride,
|
||||
glTarget : 0,
|
||||
glBuffer : 0,
|
||||
let gpuBuffer: WebGLGPUBuffer = {
|
||||
objType: WebGLGPUObjectType.BUFFER,
|
||||
usage: info.usage,
|
||||
memUsage: info.memUsage,
|
||||
size: info.size,
|
||||
stride: info.stride,
|
||||
arrayBuffer: null,
|
||||
buffer: null,
|
||||
glTarget: 0,
|
||||
glBuffer: 0,
|
||||
};
|
||||
|
||||
if(buffer) {
|
||||
gpuBuffer.arrayBuffer = buffer.buffer;
|
||||
gpuBuffer.buffer = buffer;
|
||||
}
|
||||
|
||||
// TODO: Async
|
||||
// let cmd : WebGLCmd = { type : WebGLCmdType.CREATE_BUFFER, gpuObj : gpuBuffer, isFree : false };
|
||||
|
||||
@@ -81,7 +120,7 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
return gpuBuffer;
|
||||
}
|
||||
|
||||
public emitCmdDestroyGPUBuffer(gpuBuffer : WebGLGPUBuffer) {
|
||||
public emitCmdDestroyGPUBuffer(gpuBuffer: WebGLGPUBuffer) {
|
||||
|
||||
// TODO: Async
|
||||
// let cmd : WebGLCmd = { type : WebGLCmdType.DESTROY_BUFFER, gpuObj : gpuBuffer, isFree : false };
|
||||
@@ -89,25 +128,25 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
WebGLCmdFuncDestroyBuffer(<WebGLGFXDevice>this, gpuBuffer);
|
||||
}
|
||||
|
||||
public emitCmdUpdateGPUBuffer(gpuBuffer : WebGLGPUBuffer, offset : number, data : ArrayBuffer) {
|
||||
public emitCmdUpdateGPUBuffer(gpuBuffer: WebGLGPUBuffer, offset: number, buffer: Buffer) {
|
||||
// TODO: Async
|
||||
WebGLCmdFuncUpdateBuffer(<WebGLGFXDevice>this, gpuBuffer, offset, data);
|
||||
WebGLCmdFuncUpdateBuffer(<WebGLGFXDevice>this, gpuBuffer, offset, buffer);
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUTexture(info : GFXTextureInfo) : WebGLGPUTexture {
|
||||
public emitCmdCreateGPUTexture(info: GFXTextureInfo): WebGLGPUTexture {
|
||||
|
||||
let viewType: GFXTextureViewType;
|
||||
|
||||
let viewType : GFXTextureViewType;
|
||||
|
||||
switch (info.type) {
|
||||
case GFXTextureType.TEX1D : {
|
||||
viewType = info.arrayLayer <= 1? GFXTextureViewType.TV1D : GFXTextureViewType.TV1D_ARRAY;
|
||||
case GFXTextureType.TEX1D: {
|
||||
viewType = info.arrayLayer <= 1 ? GFXTextureViewType.TV1D : GFXTextureViewType.TV1D_ARRAY;
|
||||
break;
|
||||
}
|
||||
case GFXTextureType.TEX2D : {
|
||||
|
||||
if(info.arrayLayer <= 1) {
|
||||
case GFXTextureType.TEX2D: {
|
||||
|
||||
if (info.arrayLayer <= 1) {
|
||||
viewType = GFXTextureViewType.TV2D;
|
||||
} else if(info.arrayLayer === 6 && (info.flags & GFXTextureFlagBit.CUBEMAP)) {
|
||||
} else if (info.arrayLayer === 6 && (info.flags & GFXTextureFlagBit.CUBEMAP)) {
|
||||
viewType = GFXTextureViewType.CUBE;
|
||||
} else {
|
||||
viewType = GFXTextureViewType.TV2D_ARRAY;
|
||||
@@ -115,7 +154,7 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
|
||||
break;
|
||||
}
|
||||
case GFXTextureType.TEX3D : {
|
||||
case GFXTextureType.TEX3D: {
|
||||
viewType = GFXTextureViewType.TV3D;
|
||||
break;
|
||||
}
|
||||
@@ -124,25 +163,25 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
}
|
||||
}
|
||||
|
||||
let gpuTexture : WebGLGPUTexture = {
|
||||
objType : WebGLGPUObjectType.TEXTURE,
|
||||
type : info.type,
|
||||
viewType : viewType,
|
||||
format : info.format,
|
||||
usage : info.usage,
|
||||
width : info.width,
|
||||
height : info.height,
|
||||
depth : info.depth,
|
||||
arrayLayer : info.arrayLayer,
|
||||
mipLevel : info.mipLevel,
|
||||
flags : info.flags,
|
||||
let gpuTexture: WebGLGPUTexture = {
|
||||
objType: WebGLGPUObjectType.TEXTURE,
|
||||
type: info.type,
|
||||
viewType: viewType,
|
||||
format: info.format,
|
||||
usage: info.usage,
|
||||
width: info.width,
|
||||
height: info.height,
|
||||
depth: info.depth,
|
||||
arrayLayer: info.arrayLayer,
|
||||
mipLevel: info.mipLevel,
|
||||
flags: info.flags,
|
||||
|
||||
glTarget : 0,
|
||||
glInternelFmt : 0,
|
||||
glFormat : 0,
|
||||
glType : 0,
|
||||
glUsage : 0,
|
||||
glTexture : 0,
|
||||
glTarget: 0,
|
||||
glInternelFmt: 0,
|
||||
glFormat: 0,
|
||||
glType: 0,
|
||||
glUsage: 0,
|
||||
glTexture: 0,
|
||||
};
|
||||
|
||||
// TODO: Async
|
||||
@@ -152,43 +191,46 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
return gpuTexture;
|
||||
}
|
||||
|
||||
public emitCmdDestroyGPUTexture(gpuTexture : WebGLGPUTexture) {
|
||||
public emitCmdDestroyGPUTexture(gpuTexture: WebGLGPUTexture) {
|
||||
|
||||
// TODO: Async
|
||||
// let cmd : WebGLCmd = { type : WebGLCmdType.DESTROY_BUFFER, gpuObj : gpuBuffer, isFree : false };
|
||||
WebGLCmdFuncDestroyTexture(<WebGLGFXDevice>this, gpuTexture);
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUTextureView(info : GFXTextureViewInfo) : WebGLGPUTextureView {
|
||||
public emitCmdCreateGPUTextureView(info: GFXTextureViewInfo): WebGLGPUTextureView {
|
||||
let webGLTexture = <WebGLGFXTexture>info.texture;
|
||||
|
||||
let gpuTextureView : WebGLGPUTextureView = {
|
||||
objType : WebGLGPUObjectType.TEXTURE_VIEW,
|
||||
gpuTexture : webGLTexture.gpuTexture,
|
||||
type : info.type,
|
||||
format : info.format,
|
||||
baseLevel : info.baseLevel,
|
||||
levelCount : info.levelCount,
|
||||
let gpuTextureView: WebGLGPUTextureView = {
|
||||
objType: WebGLGPUObjectType.TEXTURE_VIEW,
|
||||
gpuTexture: webGLTexture.gpuTexture,
|
||||
type: info.type,
|
||||
format: info.format,
|
||||
baseLevel: info.baseLevel,
|
||||
levelCount: info.levelCount,
|
||||
};
|
||||
|
||||
return gpuTextureView;
|
||||
}
|
||||
|
||||
public emitCmdCreateGPURenderPass(info : GFXRenderPassInfo) : WebGLGPURenderPass {
|
||||
let gpuRenderPass : WebGLGPURenderPass = {
|
||||
objType : WebGLGPUObjectType.RENDER_PASS,
|
||||
colorInfos : info.colorInfos,
|
||||
depthStencilInfo : info.depthStencilInfo,
|
||||
public emitCmdCreateGPURenderPass(info: GFXRenderPassInfo): WebGLGPURenderPass {
|
||||
let gpuRenderPass: WebGLGPURenderPass = {
|
||||
objType: WebGLGPUObjectType.RENDER_PASS,
|
||||
colorAttachments: info.colorInfos,
|
||||
depthStencilAttachment: info.depthStencilInfo,
|
||||
}
|
||||
|
||||
return gpuRenderPass;
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUFramebuffer(info : GFXFramebufferInfo) : WebGLGPUFramebuffer {
|
||||
|
||||
public emitCmdDestroyGPURenderPass(renderPass: WebGLGPURenderPass) {
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUFramebuffer(info: GFXFramebufferInfo): WebGLGPUFramebuffer {
|
||||
|
||||
let renderPass = <WebGLGFXRenderPass>info.renderPass;
|
||||
|
||||
let gpuColorViews : (WebGLGPUTextureView | null)[] = new Array<WebGLGPUTextureView | null>();
|
||||
|
||||
let gpuColorViews: (WebGLGPUTextureView | null)[] = new Array<WebGLGPUTextureView | null>();
|
||||
|
||||
for (let i = 0; i < info.colorViews.length; ++i) {
|
||||
let webGLColorView = <WebGLGFXTextureView>info.colorViews[i];
|
||||
@@ -197,13 +239,13 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
|
||||
let webGLDSView = <WebGLGFXTextureView>info.depthStencilView;
|
||||
|
||||
let gpuFramebuffer : WebGLGPUFramebuffer = {
|
||||
objType : WebGLGPUObjectType.FRAMEBUFFER,
|
||||
gpuRenderPass : renderPass.gpuRenderPass,
|
||||
gpuColorViews : gpuColorViews,
|
||||
gpuDepthStencilView : webGLDSView.gpuTextureView,
|
||||
isOffscreen : info.isOffscreen,
|
||||
glFramebuffer : 0,
|
||||
let gpuFramebuffer: WebGLGPUFramebuffer = {
|
||||
objType: WebGLGPUObjectType.FRAMEBUFFER,
|
||||
gpuRenderPass: renderPass.gpuRenderPass,
|
||||
gpuColorViews: gpuColorViews,
|
||||
gpuDepthStencilView: webGLDSView.gpuTextureView,
|
||||
isOffscreen: info.isOffscreen,
|
||||
glFramebuffer: 0,
|
||||
};
|
||||
|
||||
// TODO: Async
|
||||
@@ -212,37 +254,62 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
return gpuFramebuffer;
|
||||
}
|
||||
|
||||
public emitCmdDestroyGPUFramebuffer(gpuFramebuffer : WebGLGPUFramebuffer) {
|
||||
public emitCmdDestroyGPUFramebuffer(gpuFramebuffer: WebGLGPUFramebuffer) {
|
||||
|
||||
// TODO: Async
|
||||
WebGLCmdFuncDestroyFramebuffer(<WebGLGFXDevice>this, gpuFramebuffer);
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUShader(info : GFXShaderInfo) : WebGLGPUShader {
|
||||
public emitCmdCreateGPUSampler(info: GFXSamplerInfo): WebGLGPUSampler {
|
||||
let gpuSampler: WebGLGPUSampler = {
|
||||
objType: WebGLGPUObjectType.FRAMEBUFFER,
|
||||
minFilter: info.minFilter,
|
||||
magFilter: info.magFilter,
|
||||
mipFilter: info.minFilter,
|
||||
addressU: info.addressU,
|
||||
addressV: info.addressV,
|
||||
addressW: info.addressW,
|
||||
maxAnisotropy: info.maxAnisotropy,
|
||||
cmpFunc: info.cmpFunc,
|
||||
borderColor: info.borderColor,
|
||||
minLOD: info.minLOD,
|
||||
maxLOD: info.maxLOD,
|
||||
mipLODBias: info.mipLODBias,
|
||||
};
|
||||
|
||||
return gpuSampler;
|
||||
}
|
||||
|
||||
public emitCmdDestroyGPUSampler(gpuSampler: WebGLGPUSampler) {
|
||||
// TODO: Async
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUShader(info: GFXShaderInfo): WebGLGPUShader {
|
||||
|
||||
let gpuStages: WebGLGPUShaderStage[] = [];
|
||||
for(let i = 0; i < info.stages.length; ++i) {
|
||||
for (let i = 0; i < info.stages.length; ++i) {
|
||||
let stage = info.stages[i];
|
||||
|
||||
gpuStages.push({
|
||||
type : stage.type,
|
||||
source : stage.source,
|
||||
macros : stage.macros,
|
||||
glShader : 0,
|
||||
type: stage.type,
|
||||
source: stage.source,
|
||||
macros: stage.macros,
|
||||
glShader: 0,
|
||||
});
|
||||
}
|
||||
|
||||
let gpuShader : WebGLGPUShader = {
|
||||
objType : WebGLGPUObjectType.SHADER,
|
||||
name : info.name,
|
||||
bindings : info.bindings,
|
||||
let gpuShader: WebGLGPUShader = {
|
||||
objType: WebGLGPUObjectType.SHADER,
|
||||
name: info.name,
|
||||
bindings: info.bindings,
|
||||
blocks: info.blocks,
|
||||
|
||||
gpuStages : gpuStages,
|
||||
glProgram : 0,
|
||||
glInputs : [],
|
||||
glUniforms : [],
|
||||
glBlocks : [],
|
||||
glSamplers : [],
|
||||
gpuStages: gpuStages,
|
||||
glProgram: 0,
|
||||
glInputs: [],
|
||||
glUniforms: [],
|
||||
glBlocks: [],
|
||||
glSamplers: [],
|
||||
};
|
||||
|
||||
// TODO: Async
|
||||
@@ -251,11 +318,131 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
return gpuShader;
|
||||
}
|
||||
|
||||
public emitCmdDestroyGPUShader(gpuShader : WebGLGPUShader) {
|
||||
|
||||
public emitCmdDestroyGPUShader(gpuShader: WebGLGPUShader) {
|
||||
// TODO: Async
|
||||
WebGLCmdFuncDestroyShader(<WebGLGFXDevice>this, gpuShader);
|
||||
}
|
||||
|
||||
private _webGLRC : WebGLRenderingContext | null = null;
|
||||
public emitCmdCreateGPUPipelineState(info: GFXPipelineStateInfo): WebGLGPUPipelineState {
|
||||
|
||||
let gpuShader: WebGLGPUShader | null = null;
|
||||
if (info.shader) {
|
||||
gpuShader = (<WebGLGFXShader>info.shader).gpuShader;
|
||||
}
|
||||
|
||||
let gpuLayout: WebGLGPUPipelineLayout | null = null;
|
||||
if (info.layout) {
|
||||
gpuLayout = (<WebGLGFXPipelineLayout>info.layout).gpuPipelineLayout;
|
||||
}
|
||||
|
||||
let gpuRenderPass: WebGLGPURenderPass | null = null;
|
||||
if (info.renderPass) {
|
||||
gpuRenderPass = (<WebGLGFXRenderPass>info.renderPass).gpuRenderPass;
|
||||
}
|
||||
|
||||
let gpuPipelineState: WebGLGPUPipelineState = {
|
||||
objType: WebGLGPUObjectType.PIPELINE_STATE,
|
||||
glPrimitive: WebGLPrimitives[info.primitive],
|
||||
gpuShader: gpuShader,
|
||||
rs: info.rs,
|
||||
dss: info.dss,
|
||||
bs: info.bs,
|
||||
gpuLayout: gpuLayout,
|
||||
gpuRenderPass: gpuRenderPass,
|
||||
};
|
||||
|
||||
return gpuPipelineState;
|
||||
}
|
||||
|
||||
public emitCmdDestroyGPUPipelineState(gpuPipelineState: WebGLGPUPipelineState) {
|
||||
// TODO: Async
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUBindingSetLayout(info: GFXBindingSetLayoutInfo): WebGLGPUBindingSetLayout {
|
||||
|
||||
let gpuBindings: WebGLGPUBinding[] = new Array<WebGLGPUBinding>(info.bindings.length);
|
||||
for (let i = 0; i < info.bindings.length; ++i) {
|
||||
let binding = info.bindings[i];
|
||||
let gpuBinding = gpuBindings[i];
|
||||
gpuBinding.binding = binding.binding;
|
||||
gpuBinding.type = binding.type;
|
||||
gpuBinding.name = binding.name;
|
||||
}
|
||||
|
||||
let gpuBindingSetLayout: WebGLGPUBindingSetLayout = {
|
||||
objType: WebGLGPUObjectType.BINDING_SET_LAYOUT,
|
||||
gpuBinding: gpuBindings,
|
||||
};
|
||||
|
||||
return gpuBindingSetLayout;
|
||||
}
|
||||
|
||||
public emitCmdDestroyGPUBindingSetLayout(gpuBindingSetLayout: WebGLGPUBindingSetLayout) {
|
||||
// TODO: Async
|
||||
}
|
||||
|
||||
public emitCmdUpdateGPUBindingSetLayout(gpuBindingSetLayout: WebGLGPUBindingSetLayout) {
|
||||
// TODO: Async
|
||||
|
||||
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUInputAssembler(info: GFXInputAssemblerInfo): WebGLGPUInputAssembler {
|
||||
|
||||
let gpuShader: WebGLGPUShader | null = null;
|
||||
|
||||
if (info.shader) {
|
||||
gpuShader = (<WebGLGFXShader>info.shader).gpuShader;
|
||||
}
|
||||
|
||||
let gpuVertexBuffers: WebGLGPUBuffer[] = new Array<WebGLGPUBuffer>(info.vertexBuffers.length);
|
||||
|
||||
for (let i = 0; i < info.vertexBuffers.length; ++i) {
|
||||
let vb = <WebGLGFXBuffer>info.vertexBuffers[i];
|
||||
if (vb.gpuBuffer) {
|
||||
gpuVertexBuffers[i] = vb.gpuBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
let gpuIndexBuffer: WebGLGPUBuffer | null = null;
|
||||
|
||||
let glIndexType = 0;
|
||||
if (info.indexBuffer) {
|
||||
gpuIndexBuffer = (<WebGLGFXBuffer>info.indexBuffer).gpuBuffer;
|
||||
if (gpuIndexBuffer) {
|
||||
switch (gpuIndexBuffer.stride) {
|
||||
case 1: glIndexType = WebGLRenderingContext.UNSIGNED_BYTE; break;
|
||||
case 2: glIndexType = WebGLRenderingContext.UNSIGNED_SHORT; break;
|
||||
case 4: glIndexType = WebGLRenderingContext.UNSIGNED_INT; break;
|
||||
default: {
|
||||
console.error("Error index buffer stride.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let gpuInputAssembler: WebGLGPUInputAssembler = {
|
||||
objType: WebGLGPUObjectType.INPUT_ASSEMBLER,
|
||||
attributes: info.attributes,
|
||||
gpuShader: gpuShader,
|
||||
gpuVertexBuffers: gpuVertexBuffers,
|
||||
gpuIndexBuffer: gpuIndexBuffer,
|
||||
|
||||
glAttribs: [],
|
||||
glIndexType: glIndexType,
|
||||
glVAO: 0,
|
||||
};
|
||||
|
||||
WebGLCmdFuncCreateInputAssember(<WebGLGFXDevice>this, gpuInputAssembler);
|
||||
|
||||
// TODO: Async
|
||||
return gpuInputAssembler;
|
||||
}
|
||||
|
||||
public emitCmdDestroyGPUInputAssembler(gpuInputAssembler: WebGLGPUInputAssembler) {
|
||||
// TODO: Async
|
||||
// WebGLCmdFuncDestroyInputAssembler(<WebGLGFXDevice>this, gpuInputAssembler);
|
||||
}
|
||||
|
||||
private _webGLRC: WebGLRenderingContext | null = null;
|
||||
};
|
||||
|
||||
@@ -33,5 +33,9 @@ export class WebGLGFXFramebuffer extends GFXFramebuffer {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuFramebuffer() : WebGLGPUFramebuffer | null {
|
||||
return this._gpuFramebuffer;
|
||||
}
|
||||
|
||||
private _gpuFramebuffer : WebGLGPUFramebuffer | null = null;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { GFXInputAssembler, GFXInputAssemblerInfo } from '../gfx-input-assembler';
|
||||
import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
import { WebGLGPUInputAssembler } from './webgl-gpu-objects';
|
||||
|
||||
export class WebGLGFXInputAssembler extends GFXInputAssembler {
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
super(device);
|
||||
}
|
||||
|
||||
public initialize(info : GFXInputAssemblerInfo) : boolean {
|
||||
|
||||
this._attributes = info.attributes;
|
||||
this._vertexBuffers = info.vertexBuffers;
|
||||
this._indexBuffer = info.indexBuffer;
|
||||
this._isIndirect = info.isIndirect;
|
||||
|
||||
this._gpuInputAssembler = this.webGLDevice.emitCmdCreateGPUInputAssembler(info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
if(this._gpuInputAssembler) {
|
||||
this.webGLDevice.emitCmdDestroyGPUInputAssembler(this._gpuInputAssembler);
|
||||
this._gpuInputAssembler = null;
|
||||
}
|
||||
}
|
||||
|
||||
public get webGLDevice() : WebGLGFXDevice {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuInputAssembler() : WebGLGPUInputAssembler | null {
|
||||
return this._gpuInputAssembler;
|
||||
}
|
||||
|
||||
private _gpuInputAssembler : WebGLGPUInputAssembler | null = null;
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { WebGLGPUTexture } from './webgl-gpu-objects';
|
||||
import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
import { GFXFormatSurfaceSize } from '../gfx-define';
|
||||
import { GFXInputState, GFXInputStateInfo } from '../gfx-input-state';
|
||||
|
||||
export class WebGLGFXInputState extends GFXInputState {
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
super(device);
|
||||
}
|
||||
|
||||
public initialize(info : GFXInputStateInfo) : boolean {
|
||||
|
||||
this._attributes = info.attributes;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { GFXPipelineLayout, GFXPipelineLayoutInfo } from '../gfx-pipeline-layout';
|
||||
import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
import { WebGLGPUPipelineLayout } from './webgl-gpu-objects';
|
||||
|
||||
export class WebGLGFXPipelineLayout extends GFXPipelineLayout {
|
||||
|
||||
constructor(device: GFXDevice) {
|
||||
super(device);
|
||||
}
|
||||
|
||||
public initialize(info: GFXPipelineLayoutInfo): boolean {
|
||||
|
||||
this._pushConstantsRanges = info.pushConstantsRanges;
|
||||
this._layouts = info.layouts;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
}
|
||||
|
||||
public get webGLDevice(): WebGLGFXDevice {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuPipelineLayout(): WebGLGPUPipelineLayout | null {
|
||||
return this._gpuPipelineLayout;
|
||||
}
|
||||
|
||||
private _gpuPipelineLayout: WebGLGPUPipelineLayout | null = null;
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { GFXPipelineState, GFXPipelineStateInfo } from '../gfx-pipeline-state';
|
||||
import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
import { WebGLGPUPipelineState } from './webgl-gpu-objects';
|
||||
|
||||
export class WebGLGFXPipelineState extends GFXPipelineState {
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
super(device);
|
||||
}
|
||||
|
||||
public initialize(info : GFXPipelineStateInfo) : boolean {
|
||||
|
||||
this._primitive = info.primitive;
|
||||
this._shader = info.shader;
|
||||
this._is = info.is;
|
||||
this._rs = info.rs;
|
||||
this._dss = info.dss;
|
||||
this._bs = info.bs;
|
||||
this._layout = info.layout;
|
||||
this._renderPass = info.renderPass;
|
||||
|
||||
this._gpuPipelineState = this.webGLDevice.emitCmdCreateGPUPipelineState(info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
if(this._gpuPipelineState)
|
||||
{
|
||||
this.webGLDevice.emitCmdDestroyGPUPipelineState(this._gpuPipelineState);
|
||||
this._gpuPipelineState = null;
|
||||
}
|
||||
}
|
||||
|
||||
public get webGLDevice() : WebGLGFXDevice {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuPipelineState() : WebGLGPUPipelineState | null {
|
||||
return this._gpuPipelineState;
|
||||
}
|
||||
|
||||
private _gpuPipelineState : WebGLGPUPipelineState | null = null;
|
||||
};
|
||||
@@ -1,6 +1,9 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { GFXQueueInfo, GFXQueue } from '../gfx-queue';
|
||||
import { GFXCommandBuffer } from '../gfx-command-buffer';
|
||||
import { WebGLGFXCommandBuffer } from './webgl-gfx-command-buffer';
|
||||
import { WebGLCmdFuncExecuteCmds } from './webgl-commands';
|
||||
import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
|
||||
export class WebGLGFXQueue extends GFXQueue {
|
||||
|
||||
@@ -19,10 +22,14 @@ export class WebGLGFXQueue extends GFXQueue {
|
||||
|
||||
}
|
||||
|
||||
public submit(cmdBuffs: GFXCommandBuffer[], fence) {
|
||||
public submit(cmdBuffs: GFXCommandBuffer[], fence : null = null) {
|
||||
|
||||
for(let cb in cmdBuffs) {
|
||||
|
||||
// TODO: Async
|
||||
if(!this._isAsync) {
|
||||
for(let i = 0; i < cmdBuffs.length; ++i) {
|
||||
let cmdBuff = <WebGLGFXCommandBuffer>cmdBuffs[i];
|
||||
WebGLCmdFuncExecuteCmds(<WebGLGFXDevice>this._device, cmdBuff.cmdPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,28 +7,36 @@ import { GFXRenderPass, GFXRenderPassInfo } from '../gfx-render-pass';
|
||||
|
||||
export class WebGLGFXRenderPass extends GFXRenderPass {
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
constructor(device: GFXDevice) {
|
||||
super(device);
|
||||
}
|
||||
|
||||
public initialize(info : GFXRenderPassInfo) : boolean {
|
||||
public initialize(info: GFXRenderPassInfo): boolean {
|
||||
|
||||
this._colorInfos = info.colorInfos;
|
||||
this._depthStencilInfo = info.depthStencilInfo;
|
||||
this._subPasses = info.subPasses;
|
||||
|
||||
this._gpuRenderPass = (<WebGLGFXDevice>this._device).emitCmdCreateGPURenderPass(info);
|
||||
this._gpuRenderPass = this.webGLDevice.emitCmdCreateGPURenderPass(info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
this._gpuRenderPass = null;
|
||||
|
||||
if (this._gpuRenderPass) {
|
||||
this.webGLDevice.emitCmdDestroyGPURenderPass(this._gpuRenderPass);
|
||||
this._gpuRenderPass = null;
|
||||
}
|
||||
}
|
||||
|
||||
public get webGLDevice(): WebGLGFXDevice {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
public get gpuRenderPass(): WebGLGPURenderPass {
|
||||
return <WebGLGPURenderPass>this._gpuRenderPass;
|
||||
}
|
||||
|
||||
private _gpuRenderPass : WebGLGPURenderPass | null = null;
|
||||
private _gpuRenderPass: WebGLGPURenderPass | null = null;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { GFXDevice } from '../gfx-device';
|
||||
import { GFXSampler, GFXSamplerInfo } from '../gfx-sampler';
|
||||
import { WebGLGFXDevice } from './webgl-gfx-device';
|
||||
import { WebGLGPUSampler } from './webgl-gpu-objects';
|
||||
|
||||
export class WebGLGFXSampler extends GFXSampler {
|
||||
|
||||
@@ -22,9 +24,21 @@ export class WebGLGFXSampler extends GFXSampler {
|
||||
this._maxLOD = info.maxLOD;
|
||||
this._mipLODBias = info.mipLODBias;
|
||||
|
||||
this._gpuSampler = this.webGLDevice.emitCmdCreateGPUSampler(info);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
if(this._gpuSampler) {
|
||||
this.webGLDevice.emitCmdDestroyGPUSampler(this._gpuSampler);
|
||||
this._gpuSampler = null;
|
||||
}
|
||||
}
|
||||
|
||||
public get webGLDevice() : WebGLGFXDevice {
|
||||
return <WebGLGFXDevice>this._device;
|
||||
}
|
||||
|
||||
private _gpuSampler : WebGLGPUSampler | null = null;
|
||||
};
|
||||
|
||||
@@ -14,6 +14,7 @@ export class WebGLGFXShader extends GFXShader {
|
||||
this._name = info.name;
|
||||
this._stages = info.stages;
|
||||
this._bindings = info.bindings;
|
||||
this._blocks = info.blocks;
|
||||
|
||||
this._gpuShader = this.webGLDevice.emitCmdCreateGPUShader(info);
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { GFXBufferUsage, GFXBufferUsageBit, GFXMemoryUsage, GFXMemoryUsageBit } from "../gfx-buffer";
|
||||
import { GFXTextureType, GFXTextureUsage, GFXTextureUsageBit, GFXTextureFlags, GFXTextureFlagBit } from "../gfx-texture";
|
||||
import { GFXTextureViewType } from "../gfx-texture-view";
|
||||
import { GFXFormat, GFX_MAX_VERTEX_ATTRIBUTES, GFXType } from "../gfx-define";
|
||||
import { GFXInputAttribute } from "../gfx-input-state";
|
||||
import { ColorAttachmentInfo, DepthStencilAttachmentInfo } from "../gfx-render-pass";
|
||||
import { GFXShaderType, GFXShaderMacro } from "../gfx-shader";
|
||||
import { GFXBinding } from "../gfx-binding-set-layout";
|
||||
import { GFXFormat, GFXType } from "../gfx-define";
|
||||
import { GFXColorAttachment, GFXDepthStencilAttachment } from "../gfx-render-pass";
|
||||
import { GFXShaderType, GFXShaderMacro, GFXUniformBlock } from "../gfx-shader";
|
||||
import { GFXBinding, GFXBindingType } from "../gfx-binding-set-layout";
|
||||
import { GFXFilter, GFXAddress } from "../gfx-sampler";
|
||||
import { GFXComparisonFunc, GFXRasterizerState, GFXDepthStencilState, GFXBlendState } from "../gfx-pipeline-state";
|
||||
import { GFXInputAttribute } from "../gfx-input-assembler";
|
||||
|
||||
export const enum WebGLGPUObjectType {
|
||||
UNKNOWN,
|
||||
@@ -14,57 +16,56 @@ export const enum WebGLGPUObjectType {
|
||||
TEXTURE_VIEW,
|
||||
RENDER_PASS,
|
||||
FRAMEBUFFER,
|
||||
SAMPLER,
|
||||
SHADER,
|
||||
INPUT_STATE,
|
||||
PIPELINE_STATE,
|
||||
BINDING_SET_LAYOUT,
|
||||
INPUT_ASSEMBLER,
|
||||
COMMAND_BUFFER,
|
||||
};
|
||||
|
||||
export class WebGLGPUObject {
|
||||
objType : WebGLGPUObjectType;
|
||||
objType: WebGLGPUObjectType;
|
||||
|
||||
constructor(type : WebGLGPUObjectType) {
|
||||
constructor(type: WebGLGPUObjectType) {
|
||||
this.objType = type;
|
||||
}
|
||||
};
|
||||
|
||||
export class WebGLGPUBuffer extends WebGLGPUObject {
|
||||
usage : GFXBufferUsage = GFXBufferUsageBit.NONE;
|
||||
memUsage : GFXMemoryUsage = GFXMemoryUsageBit.NONE;
|
||||
size : number = 0;
|
||||
stride : number = 0;
|
||||
|
||||
glTarget : GLenum = 0;
|
||||
glBuffer : WebGLBuffer = 0;
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.BUFFER);
|
||||
}
|
||||
};
|
||||
|
||||
export class WebGLGPUInputState extends WebGLGPUObject {
|
||||
attributes : GFXInputAttribute[] = [];
|
||||
vertexBuffers : (WebGLGPUBuffer | null)[] = Array<WebGLGPUBuffer | null>(GFX_MAX_VERTEX_ATTRIBUTES);
|
||||
indexBuffer : WebGLGPUBuffer | null = null;
|
||||
glVAO : WebGLVertexArrayObjectOES = 0;
|
||||
export class WebGLGPUBuffer extends WebGLGPUObject {
|
||||
usage: GFXBufferUsage = GFXBufferUsageBit.NONE;
|
||||
memUsage: GFXMemoryUsage = GFXMemoryUsageBit.NONE;
|
||||
size: number = 0;
|
||||
stride: number = 0;
|
||||
|
||||
glTarget: GLenum = 0;
|
||||
glBuffer: WebGLBuffer = 0;
|
||||
arrayBuffer: ArrayBuffer | null = null;
|
||||
buffer: Buffer | null = null;
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.BUFFER);
|
||||
}
|
||||
};
|
||||
|
||||
export class WebGLGPUTexture extends WebGLGPUObject {
|
||||
type : GFXTextureType = GFXTextureType.TEX2D;
|
||||
viewType : GFXTextureViewType = GFXTextureViewType.TV2D;
|
||||
format : GFXFormat = GFXFormat.UNKNOWN;
|
||||
usage : GFXTextureUsage = GFXTextureUsageBit.NONE;
|
||||
width : number = 0;
|
||||
height : number = 0;
|
||||
depth : number = 0;
|
||||
arrayLayer : number = 0;
|
||||
mipLevel : number = 0;
|
||||
flags : GFXTextureFlags = GFXTextureFlagBit.NONE;
|
||||
type: GFXTextureType = GFXTextureType.TEX2D;
|
||||
viewType: GFXTextureViewType = GFXTextureViewType.TV2D;
|
||||
format: GFXFormat = GFXFormat.UNKNOWN;
|
||||
usage: GFXTextureUsage = GFXTextureUsageBit.NONE;
|
||||
width: number = 0;
|
||||
height: number = 0;
|
||||
depth: number = 0;
|
||||
arrayLayer: number = 0;
|
||||
mipLevel: number = 0;
|
||||
flags: GFXTextureFlags = GFXTextureFlagBit.NONE;
|
||||
|
||||
glTarget : GLenum = 0;
|
||||
glInternelFmt : GLenum = 0;
|
||||
glFormat : GLenum = 0;
|
||||
glType : GLenum = 0;
|
||||
glUsage : GLenum = 0;
|
||||
glTexture : WebGLTexture = 0;
|
||||
glTarget: GLenum = 0;
|
||||
glInternelFmt: GLenum = 0;
|
||||
glFormat: GLenum = 0;
|
||||
glType: GLenum = 0;
|
||||
glUsage: GLenum = 0;
|
||||
glTexture: WebGLTexture = 0;
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.TEXTURE);
|
||||
@@ -73,22 +74,22 @@ export class WebGLGPUTexture extends WebGLGPUObject {
|
||||
|
||||
export class WebGLGPUTextureView extends WebGLGPUObject {
|
||||
|
||||
gpuTexture : WebGLGPUTexture;
|
||||
type : GFXTextureViewType = GFXTextureViewType.TV2D;
|
||||
format : GFXFormat = GFXFormat.UNKNOWN;
|
||||
baseLevel : number = 0;
|
||||
levelCount : number = 1;
|
||||
gpuTexture: WebGLGPUTexture;
|
||||
type: GFXTextureViewType = GFXTextureViewType.TV2D;
|
||||
format: GFXFormat = GFXFormat.UNKNOWN;
|
||||
baseLevel: number = 0;
|
||||
levelCount: number = 1;
|
||||
|
||||
constructor(texture : WebGLGPUTexture) {
|
||||
constructor(texture: WebGLGPUTexture) {
|
||||
super(WebGLGPUObjectType.TEXTURE_VIEW);
|
||||
this.gpuTexture = texture;
|
||||
}
|
||||
}
|
||||
|
||||
export class WebGLGPURenderPass extends WebGLGPUObject {
|
||||
|
||||
colorInfos : ColorAttachmentInfo[] = [];
|
||||
depthStencilInfo : DepthStencilAttachmentInfo | null = null;
|
||||
|
||||
colorAttachments: GFXColorAttachment[] = [];
|
||||
depthStencilAttachment: GFXDepthStencilAttachment | null = null;
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.RENDER_PASS);
|
||||
@@ -96,15 +97,15 @@ export class WebGLGPURenderPass extends WebGLGPUObject {
|
||||
};
|
||||
|
||||
export class WebGLGPUFramebuffer extends WebGLGPUObject {
|
||||
|
||||
gpuRenderPass : WebGLGPURenderPass;
|
||||
gpuColorViews : (WebGLGPUTextureView | null)[] = [];
|
||||
gpuDepthStencilView : WebGLGPUTextureView | null = null;
|
||||
isOffscreen : boolean = false;
|
||||
|
||||
glFramebuffer : WebGLFramebuffer = 0;
|
||||
gpuRenderPass: WebGLGPURenderPass;
|
||||
gpuColorViews: (WebGLGPUTextureView | null)[] = [];
|
||||
gpuDepthStencilView: WebGLGPUTextureView | null = null;
|
||||
isOffscreen: boolean = false;
|
||||
|
||||
constructor(gpuRenderPass : WebGLGPURenderPass) {
|
||||
glFramebuffer: WebGLFramebuffer = 0;
|
||||
|
||||
constructor(gpuRenderPass: WebGLGPURenderPass) {
|
||||
super(WebGLGPUObjectType.FRAMEBUFFER);
|
||||
|
||||
this.gpuRenderPass = gpuRenderPass;
|
||||
@@ -112,70 +113,155 @@ export class WebGLGPUFramebuffer extends WebGLGPUObject {
|
||||
};
|
||||
|
||||
export class WebGLGPUSampler extends WebGLGPUObject {
|
||||
|
||||
minFilter: GFXFilter = GFXFilter.LINEAR;
|
||||
magFilter: GFXFilter = GFXFilter.LINEAR;
|
||||
mipFilter: GFXFilter = GFXFilter.LINEAR;
|
||||
addressU: GFXAddress = GFXAddress.WRAP;
|
||||
addressV: GFXAddress = GFXAddress.WRAP;
|
||||
addressW: GFXAddress = GFXAddress.WRAP;
|
||||
maxAnisotropy: number = 16;
|
||||
cmpFunc: GFXComparisonFunc = GFXComparisonFunc.NEVER;
|
||||
borderColor: number[] = [0.0, 0.0, 0.0, 0.0];
|
||||
minLOD: number = 0;
|
||||
maxLOD: number = 1000;
|
||||
mipLODBias: number = 0.0;
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.SAMPLER);
|
||||
}
|
||||
};
|
||||
|
||||
export class WebGLGPUInput {
|
||||
binding : number = -1;
|
||||
name : string = "";
|
||||
type : GFXType = GFXType.UNKNOWN;
|
||||
stride : number = 0;
|
||||
count : number = 0;
|
||||
size : number = 0;
|
||||
|
||||
glType : GLenum = 0;
|
||||
glLoc : GLint = 0;
|
||||
binding: number = -1;
|
||||
name: string = "";
|
||||
type: GFXType = GFXType.UNKNOWN;
|
||||
stride: number = 0;
|
||||
count: number = 0;
|
||||
size: number = 0;
|
||||
|
||||
glType: GLenum = 0;
|
||||
glLoc: GLint = 0;
|
||||
};
|
||||
|
||||
export class WebGLGPUUniform {
|
||||
binding : number = -1;
|
||||
name : string = "";
|
||||
type : GFXType = GFXType.UNKNOWN;
|
||||
stride : number = 0;
|
||||
count : number = 0;
|
||||
size : number = 0;
|
||||
offset : number = 0;
|
||||
|
||||
glType : GLenum = 0;
|
||||
glLoc : WebGLUniformLocation = -1;
|
||||
binding: number = -1;
|
||||
name: string = "";
|
||||
type: GFXType = GFXType.UNKNOWN;
|
||||
stride: number = 0;
|
||||
count: number = 0;
|
||||
size: number = 0;
|
||||
offset: number = 0;
|
||||
|
||||
glType: GLenum = 0;
|
||||
glLoc: WebGLUniformLocation = -1;
|
||||
bufferView: Int32Array | Float32Array | null = null;
|
||||
};
|
||||
|
||||
export class WebGLGPUUniformBlock {
|
||||
binding : number = -1;
|
||||
name : string = "";
|
||||
size : number = 0;
|
||||
glUniforms : WebGLGPUUniform[] = [];
|
||||
binding: number = -1;
|
||||
name: string = "";
|
||||
size: number = 0;
|
||||
glUniforms: WebGLGPUUniform[] = [];
|
||||
|
||||
isUniformPackage: boolean = false; // Is a single uniform package?
|
||||
buffer: ArrayBuffer | null = null; // for cache
|
||||
bufferView: Buffer | null = null;
|
||||
}
|
||||
|
||||
export class WebGLGPUUniformSampler {
|
||||
binding : number = -1;
|
||||
name : string = "";
|
||||
type : GFXType = GFXType.UNKNOWN;
|
||||
units : number[] = [];
|
||||
binding: number = -1;
|
||||
name: string = "";
|
||||
type: GFXType = GFXType.UNKNOWN;
|
||||
units: number[] = [];
|
||||
|
||||
glType : GLenum = 0;
|
||||
glLoc : WebGLUniformLocation = -1;
|
||||
glType: GLenum = 0;
|
||||
glLoc: WebGLUniformLocation = -1;
|
||||
}
|
||||
|
||||
export class WebGLGPUShaderStage {
|
||||
type : GFXShaderType = GFXShaderType.VERTEX;
|
||||
source : string = "";
|
||||
macros : GFXShaderMacro[] = [];
|
||||
glShader : WebGLShader = 0;
|
||||
type: GFXShaderType = GFXShaderType.VERTEX;
|
||||
source: string = "";
|
||||
macros: GFXShaderMacro[] = [];
|
||||
glShader: WebGLShader = 0;
|
||||
};
|
||||
|
||||
export class WebGLGPUShader extends WebGLGPUObject {
|
||||
name : string = "";
|
||||
bindings : GFXBinding[] = [];
|
||||
name: string = "";
|
||||
bindings: GFXBinding[] = [];
|
||||
blocks: GFXUniformBlock[] = [];
|
||||
|
||||
gpuStages : WebGLGPUShaderStage[] = [];
|
||||
glProgram : WebGLProgram = 0;
|
||||
glInputs : WebGLGPUInput[] = [];
|
||||
glUniforms : WebGLGPUUniform[] = [];
|
||||
glBlocks : WebGLGPUUniformBlock[] = [];
|
||||
glSamplers : WebGLGPUUniformSampler[] = [];
|
||||
gpuStages: WebGLGPUShaderStage[] = [];
|
||||
glProgram: WebGLProgram = 0;
|
||||
glInputs: WebGLGPUInput[] = [];
|
||||
glUniforms: WebGLGPUUniform[] = [];
|
||||
glBlocks: WebGLGPUUniformBlock[] = [];
|
||||
glSamplers: WebGLGPUUniformSampler[] = [];
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.SHADER);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export class WebGLGPUPipelineLayout extends WebGLGPUObject {
|
||||
|
||||
};
|
||||
|
||||
export class WebGLGPUPipelineState extends WebGLGPUObject {
|
||||
|
||||
glPrimitive: GLenum = WebGLRenderingContext.TRIANGLES;
|
||||
gpuShader: WebGLGPUShader | null = null;
|
||||
rs: GFXRasterizerState | null = null;
|
||||
dss: GFXDepthStencilState | null = null;
|
||||
bs: GFXBlendState | null = null;
|
||||
gpuLayout: WebGLGPUPipelineLayout | null = null;
|
||||
gpuRenderPass: WebGLGPURenderPass | null = null;
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.PIPELINE_STATE);
|
||||
}
|
||||
};
|
||||
|
||||
export class WebGLGPUBinding {
|
||||
binding: number = 0;
|
||||
type: GFXBindingType = GFXBindingType.UNKNOWN;
|
||||
name: string = "";
|
||||
gpuBuffer: WebGLGPUBuffer | null = null;
|
||||
gpuTexView: WebGLGPUTextureView | null = null;
|
||||
gpuSampler: WebGLGPUSampler | null = null;
|
||||
};
|
||||
|
||||
export class WebGLGPUBindingSetLayout extends WebGLGPUObject {
|
||||
|
||||
gpuBinding: WebGLGPUBinding[] = [];
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.BINDING_SET_LAYOUT);
|
||||
}
|
||||
};
|
||||
|
||||
export class WebGLAttrib {
|
||||
glBuffer: WebGLBuffer = 0;
|
||||
glLoc: number = 0;
|
||||
glType: GLenum = 0;
|
||||
size: number = 0;
|
||||
count: number = 0;
|
||||
stride: number = 0;
|
||||
componentCount: number = 1;
|
||||
isInstanced: boolean = false;
|
||||
offset: number = 0;
|
||||
};
|
||||
|
||||
export class WebGLGPUInputAssembler extends WebGLGPUObject {
|
||||
attributes: GFXInputAttribute[] = [];
|
||||
gpuShader: WebGLGPUShader | null = null;
|
||||
gpuVertexBuffers: WebGLGPUBuffer[] = [];
|
||||
gpuIndexBuffer: WebGLGPUBuffer | null = null;
|
||||
|
||||
glAttribs: WebGLAttrib[] = [];
|
||||
glIndexType: GLenum = 0;
|
||||
glVAO: WebGLVertexArrayObjectOES = 0;
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.INPUT_ASSEMBLER);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { GFX_MAX_TEXTURE_UNITS } from "../gfx-define";
|
||||
import { GFX_MAX_TEXTURE_UNITS, GFX_MAX_VERTEX_ATTRIBUTES } from "../gfx-define";
|
||||
import { GFXRasterizerState, GFXDepthStencilState, GFXBlendState } from "../gfx-pipeline-state";
|
||||
|
||||
export class WebGLStateCache {
|
||||
glArrayBuffer : WebGLBuffer | null = null;
|
||||
@@ -7,14 +8,32 @@ export class WebGLStateCache {
|
||||
glTex2DUnits : (WebGLTexture | null)[];
|
||||
glTexCubeUnits : (WebGLTexture | null)[];
|
||||
glFramebuffer : WebGLFramebuffer | null = null;
|
||||
viewport : number[] = [0.0, 0.0, 0.0, 0.0];
|
||||
scissorRect : number[] = [0.0, 0.0, 0.0, 0.0];
|
||||
rs : GFXRasterizerState;
|
||||
dss : GFXDepthStencilState;
|
||||
bs : GFXBlendState;
|
||||
glProgram : WebGLProgram | null = null;
|
||||
glEnabledAttribLocs : boolean[];
|
||||
glCurrentAttribLocs : boolean[];
|
||||
|
||||
constructor() {
|
||||
this.glTex2DUnits = new Array<WebGLTexture | null>(GFX_MAX_TEXTURE_UNITS);
|
||||
this.glTexCubeUnits = new Array<WebGLTexture | null>(GFX_MAX_TEXTURE_UNITS);
|
||||
this.rs = new GFXRasterizerState;
|
||||
this.dss = new GFXDepthStencilState;
|
||||
this.bs = new GFXBlendState;
|
||||
this.glEnabledAttribLocs = new Array<boolean>(GFX_MAX_VERTEX_ATTRIBUTES);
|
||||
this.glCurrentAttribLocs = new Array<boolean>(GFX_MAX_VERTEX_ATTRIBUTES);
|
||||
|
||||
for(let i = 0; i < GFX_MAX_TEXTURE_UNITS; ++i) {
|
||||
this.glTex2DUnits[i] = null;
|
||||
this.glTexCubeUnits[i] = null;
|
||||
}
|
||||
|
||||
for(let i = 0; i < GFX_MAX_VERTEX_ATTRIBUTES; ++i) {
|
||||
this.glEnabledAttribLocs[i] = false;
|
||||
this.glCurrentAttribLocs[i] = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user