mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix crashes
This commit is contained in:
@@ -38,6 +38,7 @@ import NodeActivator from '../scene-graph/node-activator';
|
||||
import RenderSystem from '../3d/framework/render-system';
|
||||
import { PhysicsSystem } from '../3d/framework/physics/physics-system';
|
||||
import { getClassByName } from './utils/js';
|
||||
import { Root } from './root';
|
||||
|
||||
// const ComponentScheduler = require('./component-scheduler');
|
||||
// const NodeActivator = require('./node-activator');
|
||||
@@ -122,6 +123,9 @@ class Director extends EventTarget {
|
||||
// purge?
|
||||
this._purgeDirectorInNextLoop = false;
|
||||
|
||||
// root
|
||||
this._root = null;
|
||||
|
||||
// scenes
|
||||
this._loadingScene = '';
|
||||
this._scene = null;
|
||||
@@ -156,6 +160,13 @@ class Director extends EventTarget {
|
||||
}
|
||||
|
||||
init () {
|
||||
|
||||
this._root = new Root(game._gfxDevice);
|
||||
let rootInfo = {};
|
||||
if(!this._root.initialize(rootInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._totalFrames = 0;
|
||||
this._lastUpdate = performance.now();
|
||||
this._paused = false;
|
||||
@@ -349,6 +360,9 @@ class Director extends EventTarget {
|
||||
|
||||
this.stopAnimation();
|
||||
|
||||
this._root.destroy();
|
||||
this._root = null;
|
||||
|
||||
// Clear all caches
|
||||
cc.loader.releaseAll();
|
||||
}
|
||||
@@ -902,7 +916,11 @@ class Director extends EventTarget {
|
||||
// Render
|
||||
this._physicsSystem.update(this._deltaTime);
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
this._renderSystem.update(this._deltaTime);
|
||||
//this._renderSystem.update(this._deltaTime);
|
||||
|
||||
|
||||
this._root.frameMove(this._deltaTime);
|
||||
|
||||
// After draw
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
|
||||
|
||||
+18
-9
@@ -30,7 +30,7 @@ import debug from './platform/CCDebug';
|
||||
import { addon } from './utils/js';
|
||||
|
||||
import renderer from '../renderer';
|
||||
import gfx from '../renderer/gfx';
|
||||
import '../gfx';
|
||||
import builtinResMgr from '../3d/builtin/init';
|
||||
|
||||
/**
|
||||
@@ -343,6 +343,12 @@ var game = {
|
||||
* @method end
|
||||
*/
|
||||
end: function () {
|
||||
|
||||
if(this._gfxDevice) {
|
||||
this._gfxDevice.destroy();
|
||||
this._gfxDevice = null;
|
||||
}
|
||||
|
||||
close();
|
||||
},
|
||||
|
||||
@@ -366,7 +372,7 @@ var game = {
|
||||
// Init engine
|
||||
this._initEngine();
|
||||
|
||||
this._initBuiltins();
|
||||
//this._initBuiltins();
|
||||
|
||||
// Log engine version
|
||||
console.log('Cocos3D v' + cc.ENGINE_VERSION);
|
||||
@@ -768,26 +774,29 @@ var game = {
|
||||
{
|
||||
// todo, adjust opts here
|
||||
|
||||
let device = this._renderContext = new gfx.Device(localCanvas, {});
|
||||
|
||||
/*
|
||||
this._gfxDevice = new WebGLGFXDevice;
|
||||
this._gfxDevice = new cc.WebGLGFXDevice;
|
||||
this._gfxDevice.initialize({
|
||||
canvasElm : localCanvas,
|
||||
});
|
||||
*/
|
||||
|
||||
//let device = this._renderContext = new gfx.Device(localCanvas, {});
|
||||
|
||||
/*
|
||||
renderer.addStage('opaque');
|
||||
renderer.addStage('transparent');
|
||||
renderer.addStage('ui');
|
||||
renderer.addStage('shadowcast');
|
||||
*/
|
||||
|
||||
this._renderer = new renderer.ForwardRenderer(device);
|
||||
//this._renderer = new renderer.ForwardRenderer(device);
|
||||
}
|
||||
// renderer.initWebGL(localCanvas, opts);
|
||||
// this._renderContext = renderer.device._gl;
|
||||
}
|
||||
if (!this._renderContext) {
|
||||
|
||||
if (!this._gfxDevice) {
|
||||
//if (!this._renderContext) {
|
||||
|
||||
// todo fix here for wechat game
|
||||
console.error('can not support canvas rendering in 3D');
|
||||
this._renderer = null;
|
||||
|
||||
+7
-13
@@ -1,26 +1,20 @@
|
||||
import { Scene } from "../renderer/scene/scene";
|
||||
import { ForwardPipeline } from "../renderer/pipeline/forward/forward-pipeline";
|
||||
import { GFXWindowInfo, GFXWindow } from "../gfx/window";
|
||||
import Scene from "../renderer/scene/scene";
|
||||
import { GFXWindow, GFXWindowInfo } from "../gfx/window";
|
||||
import { GFXDevice } from "../gfx/device";
|
||||
import { RenderView, RenderViewInfo } from "../pipeline/render-view";
|
||||
import { RenderPipeline } from "../pipeline/render-pipeline";
|
||||
import { ForwardPipeline } from "../pipeline/forward/forward-pipeline";
|
||||
|
||||
export interface RootInfo {
|
||||
device: GFXDevice;
|
||||
};
|
||||
|
||||
export class Root {
|
||||
|
||||
constructor() {
|
||||
constructor(device: GFXDevice) {
|
||||
this._device = device;
|
||||
}
|
||||
|
||||
public initialize(info: RootInfo): boolean {
|
||||
|
||||
if(!info.device) {
|
||||
console.error("RootInfo.device is null.");
|
||||
return false;
|
||||
}
|
||||
this._device = info.device;
|
||||
this._mainWindow = this._device.mainWindow;
|
||||
|
||||
let pipeline = new ForwardPipeline(this);
|
||||
@@ -133,7 +127,7 @@ export class Root {
|
||||
this._views = [];
|
||||
}
|
||||
|
||||
public get device(): GFXDevice | null {
|
||||
public get device(): GFXDevice {
|
||||
return this._device;
|
||||
}
|
||||
|
||||
@@ -153,7 +147,7 @@ export class Root {
|
||||
return this._views;
|
||||
}
|
||||
|
||||
private _device: GFXDevice | null = null;
|
||||
private _device: GFXDevice;
|
||||
private _mainWindow: GFXWindow | null = null;
|
||||
private _windows: GFXWindow[] = [];
|
||||
private _pipeline: RenderPipeline | null = null;
|
||||
|
||||
@@ -2,22 +2,16 @@ import { GFXDevice } from './device';
|
||||
import { GFXBuffer } from './buffer';
|
||||
import { GFXTextureView } from './texture-view';
|
||||
import { GFXSampler } from './sampler';
|
||||
import { GFXBindingType } from './gfx-define';
|
||||
|
||||
export enum GFXBindingType {
|
||||
UNKNOWN,
|
||||
UNIFORM_BUFFER,
|
||||
SAMPLER,
|
||||
STORAGE_BUFFER,
|
||||
export interface GFXBinding {
|
||||
binding : number;
|
||||
type : GFXBindingType;
|
||||
name : string;
|
||||
};
|
||||
|
||||
export class GFXBinding {
|
||||
binding : number = 0;
|
||||
type : GFXBindingType = GFXBindingType.UNKNOWN;
|
||||
name : string = "";
|
||||
};
|
||||
|
||||
export class GFXBindingLayoutInfo {
|
||||
bindings : GFXBinding[] = [];
|
||||
export interface GFXBindingLayoutInfo {
|
||||
bindings : GFXBinding[];
|
||||
};
|
||||
|
||||
export class GFXBindingUnit {
|
||||
|
||||
+3
-31
@@ -1,33 +1,5 @@
|
||||
import { GFXDevice } from './device';
|
||||
import { BufferView } from './define';
|
||||
|
||||
export enum GFXBufferUsageBit {
|
||||
NONE = 0,
|
||||
TRANSFER_SRC = 0x1,
|
||||
TRANSFER_DST = 0x2,
|
||||
INDEX = 0x4,
|
||||
VERTEX = 0x8,
|
||||
UNIFORM = 0x10,
|
||||
STORAGE = 0x20,
|
||||
};
|
||||
|
||||
export type GFXBufferUsage = GFXBufferUsageBit;
|
||||
|
||||
export enum GFXMemoryUsageBit {
|
||||
NONE = 0,
|
||||
DEVICE = 0x1,
|
||||
HOST = 0x2,
|
||||
};
|
||||
|
||||
export type GFXMemoryUsage = GFXMemoryUsageBit;
|
||||
|
||||
export enum GFXBufferAccessBit {
|
||||
NONE = 0,
|
||||
READ = 0x1,
|
||||
WRITE = 0x2,
|
||||
};
|
||||
|
||||
export type GFXBufferAccess = GFXBufferAccessBit;
|
||||
import { GFXBufferUsage, GFXMemoryUsage, GFXBufferUsageBit, GFXMemoryUsageBit } from './gfx-define';
|
||||
|
||||
export interface GFXBufferInfo {
|
||||
usage: GFXBufferUsage;
|
||||
@@ -44,7 +16,7 @@ export abstract class GFXBuffer {
|
||||
|
||||
public abstract initialize(info: GFXBufferInfo): boolean;
|
||||
public abstract destroy(): void;
|
||||
public abstract update(buffer: Buffer, offset: number);
|
||||
public abstract update(buffer: ArrayBuffer, offset?: number);
|
||||
|
||||
public get usage(): GFXBufferUsage {
|
||||
return this._usage;
|
||||
@@ -72,5 +44,5 @@ export abstract class GFXBuffer {
|
||||
protected _size: number = 0;
|
||||
protected _stride: number = 1;
|
||||
protected _buffer: ArrayBuffer | null = null;
|
||||
protected _bufferView: BufferView | null = null;
|
||||
protected _bufferView: Uint8Array | null = null;
|
||||
};
|
||||
|
||||
@@ -4,39 +4,9 @@ import { GFXBuffer } from './buffer';
|
||||
import { GFXInputAssembler } from './input-assembler';
|
||||
import { GFXPipelineState } from './pipeline-state';
|
||||
import { GFXBindingLayout } from './binding-layout';
|
||||
import { GFXTextureLayout } from './render-pass';
|
||||
import { GFXTexture } from './texture';
|
||||
import { GFXFramebuffer } from './framebuffer';
|
||||
|
||||
export class GFXTextureSubres
|
||||
{
|
||||
baseMipLevel: number = 0;
|
||||
levelCount: number = 1;
|
||||
baseArrayLayer: number = 0;
|
||||
layerCount: number = 1;
|
||||
};
|
||||
|
||||
export class GFXTextureCopy {
|
||||
srcSubres: GFXTextureSubres = new GFXTextureSubres;
|
||||
srcOffset: number[] = [0, 0, 0];
|
||||
dstSubres: GFXTextureSubres = new GFXTextureSubres;
|
||||
dstOffset: number[] = [0, 0, 0];
|
||||
extent: number[] = [0, 0, 0];
|
||||
};
|
||||
|
||||
export class GFXBufferTextureCopy {
|
||||
buffOffset: number = 0;
|
||||
buffStride: number = 0;
|
||||
buffTexHeight: number = 0;
|
||||
texOffset: number[] = [0, 0, 0];
|
||||
texExtent: number[] = [0, 0, 0];
|
||||
texSubres: GFXTextureSubres = new GFXTextureSubres;
|
||||
};
|
||||
|
||||
export enum GFXCommandBufferType {
|
||||
PRIMARY,
|
||||
SECONDARY,
|
||||
};
|
||||
import { GFXColor, GFXRect, GFXCommandBufferType, GFXBufferTextureCopy, GFXTextureLayout } from './gfx-define';
|
||||
|
||||
export interface GFXCommandBufferInfo {
|
||||
allocator : GFXCommandAllocator;
|
||||
@@ -54,7 +24,7 @@ export abstract class GFXCommandBuffer {
|
||||
|
||||
public abstract begin();
|
||||
public abstract end();
|
||||
public abstract beginRenderPass(framebuffer : GFXFramebuffer, viewport : number[], numClearColors : number, clearColors : number[], clearStencil : number);
|
||||
public abstract beginRenderPass(framebuffer : GFXFramebuffer, renderArea : GFXRect, clearColors : GFXColor[], clearDepth: number, clearStencil : number);
|
||||
public abstract endRenderPass();
|
||||
public abstract bindPipelineState(pipelineState : GFXPipelineState);
|
||||
public abstract bindBindingLayout(bindingLayout : GFXBindingLayout);
|
||||
|
||||
@@ -1,407 +0,0 @@
|
||||
// Extensions
|
||||
export enum WebGLEXT {
|
||||
COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
|
||||
COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1,
|
||||
COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
|
||||
COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,
|
||||
|
||||
COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F,
|
||||
|
||||
COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
|
||||
COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01,
|
||||
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02,
|
||||
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03,
|
||||
|
||||
COMPRESSED_RGB_ETC1_WEBGL = 0x8D64,
|
||||
};
|
||||
|
||||
export const GFX_MAX_VERTEX_ATTRIBUTES : number = 8;
|
||||
export const GFX_MAX_TEXTURE_UNITS : number = 16;
|
||||
export const GFX_MAX_ATTACHMENTS : number = 4;
|
||||
|
||||
export enum GFXType {
|
||||
UNKNOWN,
|
||||
BOOL,
|
||||
BOOL2,
|
||||
BOOL3,
|
||||
BOOL4,
|
||||
INT,
|
||||
INT2,
|
||||
INT3,
|
||||
INT4,
|
||||
UINT,
|
||||
UINT2,
|
||||
UINT3,
|
||||
UINT4,
|
||||
FLOAT,
|
||||
FLOAT2,
|
||||
FLOAT3,
|
||||
FLOAT4,
|
||||
MAT2,
|
||||
MAT2X3,
|
||||
MAT2X4,
|
||||
MAT3X2,
|
||||
MAT3,
|
||||
MAT3X4,
|
||||
MAT4X2,
|
||||
MAT4X3,
|
||||
MAT4,
|
||||
SAMPLER1D,
|
||||
SAMPLER1D_ARRAY,
|
||||
SAMPLER2D,
|
||||
SAMPLER2D_ARRAY,
|
||||
SAMPLER3D,
|
||||
SAMPLER_CUBE,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
export enum GFXFormat {
|
||||
|
||||
UNKNOWN,
|
||||
|
||||
A8,
|
||||
L8,
|
||||
LA8,
|
||||
|
||||
R8,
|
||||
R8SN,
|
||||
R8UI,
|
||||
R8I,
|
||||
R16F,
|
||||
R16UI,
|
||||
R16I,
|
||||
R32F,
|
||||
R32UI,
|
||||
R32I,
|
||||
|
||||
RG8,
|
||||
RG8SN,
|
||||
RG8UI,
|
||||
RG8I,
|
||||
RG16F,
|
||||
RG16UI,
|
||||
RG16I,
|
||||
RG32F,
|
||||
RG32UI,
|
||||
RG32I,
|
||||
|
||||
RGB8,
|
||||
SRGB8,
|
||||
RGB8SN,
|
||||
RGB8UI,
|
||||
RGB8I,
|
||||
RGB16F,
|
||||
RGB16UI,
|
||||
RGB16I,
|
||||
RGB32F,
|
||||
RGB32UI,
|
||||
RGB32I,
|
||||
|
||||
RGBA8,
|
||||
SRGB8_A8,
|
||||
RGBA8SN,
|
||||
RGBA8UI,
|
||||
RGBA8I,
|
||||
RGBA16F,
|
||||
RGBA16UI,
|
||||
RGBA16I,
|
||||
RGBA32F,
|
||||
RGBA32UI,
|
||||
RGBA32I,
|
||||
|
||||
// Special Format
|
||||
R5G6B5,
|
||||
R11G11B10F,
|
||||
RGB5A1,
|
||||
RGBA4,
|
||||
RGB10A2,
|
||||
RGB10A2UI,
|
||||
RGB9E5,
|
||||
|
||||
// Depth-Stencil Format
|
||||
D16,
|
||||
D16S8,
|
||||
D24,
|
||||
D24S8,
|
||||
D32F,
|
||||
D32F_S8,
|
||||
|
||||
// Compressed Format
|
||||
|
||||
// Block Compression Format, DDS (DirectDraw Surface)
|
||||
// DXT1: 3 channels (5:6:5), 1/8 origianl size, with 0 or 1 bit of alpha
|
||||
BC1,
|
||||
BC1_ALPHA,
|
||||
BC1_SRGB,
|
||||
BC1_SRGB_ALPHA,
|
||||
// DXT3: 4 channels (5:6:5), 1/4 origianl size, with 4 bits of alpha
|
||||
BC2,
|
||||
BC2_SRGB,
|
||||
// DXT5: 4 channels (5:6:5), 1/4 origianl size, with 8 bits of alpha
|
||||
BC3,
|
||||
BC3_SRGB,
|
||||
// 1 channel (8), 1/4 origianl size
|
||||
BC4,
|
||||
BC4_SNORM,
|
||||
// 2 channels (8:8), 1/2 origianl size
|
||||
BC5,
|
||||
BC5_SNORM,
|
||||
// 3 channels (16:16:16), half-floating point, 1/6 origianl size
|
||||
// UF16: unsigned float, 5 exponent bits + 11 mantissa bits
|
||||
// SF16: signed float, 1 signed bit + 5 exponent bits + 10 mantissa bits
|
||||
BC6H_UF16,
|
||||
BC6H_SF16,
|
||||
// 4 channels (4~7 bits per channel) with 0 to 8 bits of alpha, 1/3 original size
|
||||
BC7,
|
||||
BC7_SRGB,
|
||||
|
||||
// Ericsson Texture Compression Format
|
||||
ETC_RGB8,
|
||||
ETC2_RGB8,
|
||||
ETC2_SRGB8,
|
||||
ETC2_RGB8_A1,
|
||||
ETC2_SRGB8_A1,
|
||||
ETC2_RGBA8,
|
||||
ETC2_SRGB8_A8,
|
||||
EAC_R11,
|
||||
EAC_R11SN,
|
||||
EAC_RG11,
|
||||
EAC_RG11SN,
|
||||
|
||||
// PVRTC (PowerVR)
|
||||
PVRTC_RGB2,
|
||||
PVRTC_RGBA2,
|
||||
PVRTC_RGB4,
|
||||
PVRTC_RGBA4,
|
||||
PVRTC2_2BPP,
|
||||
PVRTC2_4BPP,
|
||||
};
|
||||
|
||||
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;
|
||||
readonly hasStencil : boolean = false;
|
||||
readonly isCompressed : boolean = false;
|
||||
};
|
||||
|
||||
export const GFXFormatInfos : GFXFormatInfo[] = [
|
||||
|
||||
{ name : "UNKNOWN", size : 0, count : 0, isFloating : false, hasAlpha : false, 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, 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, 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, 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, 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, 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, count : 1, isFloating : false, hasAlpha : false, hasDepth : true, hasStencil : false, isCompressed : false },
|
||||
{ name : "D16S8", size : 3, count : 2, isFloating : false, hasAlpha : false, hasDepth : true, hasStencil : true, 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, 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, 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, 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 {
|
||||
|
||||
if(!GFXFormatInfos[format].isCompressed) {
|
||||
return (width * height * depth * GFXFormatInfos[format].size);
|
||||
} else {
|
||||
switch(format) {
|
||||
case GFXFormat.BC1:
|
||||
case GFXFormat.BC1_ALPHA:
|
||||
case GFXFormat.BC1_SRGB:
|
||||
case GFXFormat.BC1_SRGB_ALPHA:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 8 * depth;
|
||||
case GFXFormat.BC2:
|
||||
case GFXFormat.BC2_SRGB:
|
||||
case GFXFormat.BC3:
|
||||
case GFXFormat.BC3_SRGB:
|
||||
case GFXFormat.BC4:
|
||||
case GFXFormat.BC4_SNORM:
|
||||
case GFXFormat.BC6H_SF16:
|
||||
case GFXFormat.BC6H_UF16:
|
||||
case GFXFormat.BC7:
|
||||
case GFXFormat.BC7_SRGB:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16 * depth;
|
||||
case GFXFormat.BC5:
|
||||
case GFXFormat.BC5_SNORM:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 32 * depth;
|
||||
|
||||
case GFXFormat.ETC_RGB8:
|
||||
case GFXFormat.ETC2_RGB8:
|
||||
case GFXFormat.ETC2_SRGB8:
|
||||
case GFXFormat.ETC2_RGB8_A1:
|
||||
case GFXFormat.ETC2_SRGB8_A1:
|
||||
case GFXFormat.EAC_R11:
|
||||
case GFXFormat.EAC_R11SN:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 8 * depth;
|
||||
case GFXFormat.EAC_RG11:
|
||||
case GFXFormat.EAC_RG11SN:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16 * depth;
|
||||
|
||||
case GFXFormat.PVRTC_RGB2:
|
||||
case GFXFormat.PVRTC_RGBA2:
|
||||
case GFXFormat.PVRTC2_2BPP:
|
||||
return Math.ceil(Math.max(width, 16) * Math.max(height, 8) / 4) * depth;
|
||||
case GFXFormat.PVRTC_RGB4:
|
||||
case GFXFormat.PVRTC_RGBA4:
|
||||
case GFXFormat.PVRTC2_4BPP:
|
||||
return Math.ceil(Math.max(width, 16) * Math.max(height, 8) / 2) * depth;
|
||||
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function GFXFormatSurfaceSize(format : GFXFormat, width : number, height : number, depth : number, mips : number) : number {
|
||||
|
||||
let size = 0;
|
||||
|
||||
for(let i = 0; i < mips; ++i) {
|
||||
size += GFXFormatSize(format, width, height, depth);
|
||||
width = Math.max(width >> 1, 1);
|
||||
height = Math.max(height >> 1, 1);
|
||||
depth = Math.max(depth >> 1, 1);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
export function GFXGetTypeSize(type : GFXType) : number {
|
||||
switch(type) {
|
||||
case GFXType.BOOL:
|
||||
case GFXType.INT:
|
||||
case GFXType.UINT:
|
||||
case GFXType.FLOAT: return 4;
|
||||
case GFXType.BOOL2:
|
||||
case GFXType.INT2:
|
||||
case GFXType.UINT2:
|
||||
case GFXType.FLOAT2: return 8;
|
||||
case GFXType.BOOL3:
|
||||
case GFXType.INT3:
|
||||
case GFXType.UINT3:
|
||||
case GFXType.FLOAT3: return 12;
|
||||
case GFXType.BOOL4:
|
||||
case GFXType.INT4:
|
||||
case GFXType.UINT4:
|
||||
case GFXType.FLOAT4:
|
||||
case GFXType.MAT2: return 16;
|
||||
case GFXType.MAT2X3: return 24;
|
||||
case GFXType.MAT2X4: return 32;
|
||||
case GFXType.MAT3X2: return 24;
|
||||
case GFXType.MAT3: return 36;
|
||||
case GFXType.MAT3X4: return 48;
|
||||
case GFXType.MAT4X2: return 32;
|
||||
case GFXType.MAT4X2: return 32;
|
||||
case GFXType.MAT4: return 64;
|
||||
case GFXType.SAMPLER1D:
|
||||
case GFXType.SAMPLER1D_ARRAY:
|
||||
case GFXType.SAMPLER2D:
|
||||
case GFXType.SAMPLER2D_ARRAY:
|
||||
case GFXType.SAMPLER3D:
|
||||
case GFXType.SAMPLER_CUBE: return 4;
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type BufferView = Uint8Array;
|
||||
+6
-2
@@ -43,7 +43,7 @@ export abstract class GFXDevice {
|
||||
public abstract createQueue(info: GFXQueueInfo) : GFXQueue | null;
|
||||
public abstract createWindow(info: GFXWindowInfo) : GFXWindow | null;
|
||||
public abstract present();
|
||||
|
||||
|
||||
public get queue(): GFXQueue {
|
||||
return <GFXQueue>this._queue;
|
||||
}
|
||||
@@ -52,6 +52,10 @@ export abstract class GFXDevice {
|
||||
return this._mainWindow;
|
||||
}
|
||||
|
||||
public get commandAllocator(): GFXCommandAllocator {
|
||||
return <GFXCommandAllocator>this._cmdAllocator;
|
||||
}
|
||||
|
||||
public get maxVertexAttributes(): number {
|
||||
return this._maxVertexAttributes;
|
||||
}
|
||||
@@ -59,6 +63,6 @@ export abstract class GFXDevice {
|
||||
protected _deviceName : string = "";
|
||||
protected _queue : GFXQueue | null = null;
|
||||
protected _mainWindow : GFXWindow | null = null;
|
||||
|
||||
protected _cmdAllocator: GFXCommandAllocator | null = null;
|
||||
protected _maxVertexAttributes : number = 0;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,20 @@ export abstract class GFXFramebuffer {
|
||||
public abstract initialize(info: GFXFramebufferInfo): boolean;
|
||||
public abstract destroy(): void;
|
||||
|
||||
public get renderPass(): GFXRenderPass | null {
|
||||
return this._renderPass;
|
||||
}
|
||||
|
||||
public get colorViews(): GFXTextureView[] {
|
||||
return this._colorViews;
|
||||
}
|
||||
|
||||
public get depthStencilView(): GFXTextureView | null {
|
||||
return this._depthStencilView;
|
||||
}
|
||||
|
||||
protected _device: GFXDevice;
|
||||
protected _renderPass: GFXRenderPass | null = null;
|
||||
protected _colorViews: GFXTextureView[] = [];
|
||||
protected _depthStencilView: GFXTextureView | null = null;
|
||||
protected _isOffscreen: boolean = true;
|
||||
|
||||
@@ -0,0 +1,710 @@
|
||||
// Extensions
|
||||
export enum WebGLEXT {
|
||||
COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
|
||||
COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1,
|
||||
COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
|
||||
COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,
|
||||
|
||||
COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E,
|
||||
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F,
|
||||
|
||||
COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
|
||||
COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01,
|
||||
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02,
|
||||
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03,
|
||||
|
||||
COMPRESSED_RGB_ETC1_WEBGL = 0x8D64,
|
||||
};
|
||||
|
||||
export const GFX_MAX_VERTEX_ATTRIBUTES: number = 8;
|
||||
export const GFX_MAX_TEXTURE_UNITS: number = 16;
|
||||
export const GFX_MAX_ATTACHMENTS: number = 4;
|
||||
|
||||
export enum GFXType {
|
||||
UNKNOWN,
|
||||
BOOL,
|
||||
BOOL2,
|
||||
BOOL3,
|
||||
BOOL4,
|
||||
INT,
|
||||
INT2,
|
||||
INT3,
|
||||
INT4,
|
||||
UINT,
|
||||
UINT2,
|
||||
UINT3,
|
||||
UINT4,
|
||||
FLOAT,
|
||||
FLOAT2,
|
||||
FLOAT3,
|
||||
FLOAT4,
|
||||
MAT2,
|
||||
MAT2X3,
|
||||
MAT2X4,
|
||||
MAT3X2,
|
||||
MAT3,
|
||||
MAT3X4,
|
||||
MAT4X2,
|
||||
MAT4X3,
|
||||
MAT4,
|
||||
SAMPLER1D,
|
||||
SAMPLER1D_ARRAY,
|
||||
SAMPLER2D,
|
||||
SAMPLER2D_ARRAY,
|
||||
SAMPLER3D,
|
||||
SAMPLER_CUBE,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
export enum GFXFormat {
|
||||
|
||||
UNKNOWN,
|
||||
|
||||
A8,
|
||||
L8,
|
||||
LA8,
|
||||
|
||||
R8,
|
||||
R8SN,
|
||||
R8UI,
|
||||
R8I,
|
||||
R16F,
|
||||
R16UI,
|
||||
R16I,
|
||||
R32F,
|
||||
R32UI,
|
||||
R32I,
|
||||
|
||||
RG8,
|
||||
RG8SN,
|
||||
RG8UI,
|
||||
RG8I,
|
||||
RG16F,
|
||||
RG16UI,
|
||||
RG16I,
|
||||
RG32F,
|
||||
RG32UI,
|
||||
RG32I,
|
||||
|
||||
RGB8,
|
||||
SRGB8,
|
||||
RGB8SN,
|
||||
RGB8UI,
|
||||
RGB8I,
|
||||
RGB16F,
|
||||
RGB16UI,
|
||||
RGB16I,
|
||||
RGB32F,
|
||||
RGB32UI,
|
||||
RGB32I,
|
||||
|
||||
RGBA8,
|
||||
SRGB8_A8,
|
||||
RGBA8SN,
|
||||
RGBA8UI,
|
||||
RGBA8I,
|
||||
RGBA16F,
|
||||
RGBA16UI,
|
||||
RGBA16I,
|
||||
RGBA32F,
|
||||
RGBA32UI,
|
||||
RGBA32I,
|
||||
|
||||
// Special Format
|
||||
R5G6B5,
|
||||
R11G11B10F,
|
||||
RGB5A1,
|
||||
RGBA4,
|
||||
RGB10A2,
|
||||
RGB10A2UI,
|
||||
RGB9E5,
|
||||
|
||||
// Depth-Stencil Format
|
||||
D16,
|
||||
D16S8,
|
||||
D24,
|
||||
D24S8,
|
||||
D32F,
|
||||
D32F_S8,
|
||||
|
||||
// Compressed Format
|
||||
|
||||
// Block Compression Format, DDS (DirectDraw Surface)
|
||||
// DXT1: 3 channels (5:6:5), 1/8 origianl size, with 0 or 1 bit of alpha
|
||||
BC1,
|
||||
BC1_ALPHA,
|
||||
BC1_SRGB,
|
||||
BC1_SRGB_ALPHA,
|
||||
// DXT3: 4 channels (5:6:5), 1/4 origianl size, with 4 bits of alpha
|
||||
BC2,
|
||||
BC2_SRGB,
|
||||
// DXT5: 4 channels (5:6:5), 1/4 origianl size, with 8 bits of alpha
|
||||
BC3,
|
||||
BC3_SRGB,
|
||||
// 1 channel (8), 1/4 origianl size
|
||||
BC4,
|
||||
BC4_SNORM,
|
||||
// 2 channels (8:8), 1/2 origianl size
|
||||
BC5,
|
||||
BC5_SNORM,
|
||||
// 3 channels (16:16:16), half-floating point, 1/6 origianl size
|
||||
// UF16: unsigned float, 5 exponent bits + 11 mantissa bits
|
||||
// SF16: signed float, 1 signed bit + 5 exponent bits + 10 mantissa bits
|
||||
BC6H_UF16,
|
||||
BC6H_SF16,
|
||||
// 4 channels (4~7 bits per channel) with 0 to 8 bits of alpha, 1/3 original size
|
||||
BC7,
|
||||
BC7_SRGB,
|
||||
|
||||
// Ericsson Texture Compression Format
|
||||
ETC_RGB8,
|
||||
ETC2_RGB8,
|
||||
ETC2_SRGB8,
|
||||
ETC2_RGB8_A1,
|
||||
ETC2_SRGB8_A1,
|
||||
ETC2_RGBA8,
|
||||
ETC2_SRGB8_A8,
|
||||
EAC_R11,
|
||||
EAC_R11SN,
|
||||
EAC_RG11,
|
||||
EAC_RG11SN,
|
||||
|
||||
// PVRTC (PowerVR)
|
||||
PVRTC_RGB2,
|
||||
PVRTC_RGBA2,
|
||||
PVRTC_RGB4,
|
||||
PVRTC_RGBA4,
|
||||
PVRTC2_2BPP,
|
||||
PVRTC2_4BPP,
|
||||
};
|
||||
|
||||
export enum GFXVertexSemantic {
|
||||
UNKNOWN,
|
||||
POSITION,
|
||||
POSITION1,
|
||||
POSITION2,
|
||||
POSITION3,
|
||||
COLOR,
|
||||
COLOR1,
|
||||
COLOR2,
|
||||
COLOR3,
|
||||
NORMAL,
|
||||
NORMAL1,
|
||||
NORMAL2,
|
||||
NORMAL3,
|
||||
TANGENT,
|
||||
BINORMAL,
|
||||
TEXCOORD,
|
||||
TEXCOORD1,
|
||||
TEXCOORD2,
|
||||
TEXCOORD3,
|
||||
JOINTS,
|
||||
WEIGHTS,
|
||||
SV_INSTANCE_ID,
|
||||
};
|
||||
|
||||
export enum GFXBufferUsageBit {
|
||||
NONE = 0,
|
||||
TRANSFER_SRC = 0x1,
|
||||
TRANSFER_DST = 0x2,
|
||||
INDEX = 0x4,
|
||||
VERTEX = 0x8,
|
||||
UNIFORM = 0x10,
|
||||
STORAGE = 0x20,
|
||||
};
|
||||
|
||||
export type GFXBufferUsage = GFXBufferUsageBit;
|
||||
|
||||
export enum GFXMemoryUsageBit {
|
||||
NONE = 0,
|
||||
DEVICE = 0x1,
|
||||
HOST = 0x2,
|
||||
};
|
||||
|
||||
export type GFXMemoryUsage = GFXMemoryUsageBit;
|
||||
|
||||
export enum GFXBufferAccessBit {
|
||||
NONE = 0,
|
||||
READ = 0x1,
|
||||
WRITE = 0x2,
|
||||
};
|
||||
|
||||
export type GFXBufferAccess = GFXBufferAccessBit;
|
||||
|
||||
export enum GFXPrimitiveMode {
|
||||
POINT_LIST,
|
||||
LINE_LIST,
|
||||
LINE_STRIP,
|
||||
LINE_LOOP,
|
||||
TRIANGLE_LIST,
|
||||
TRIANGLE_STRIP,
|
||||
TRIANGLE_FAN,
|
||||
LINE_LIST_ADJACENCY,
|
||||
LINE_STRIP_ADJACENCY,
|
||||
TRIANGLE_LIST_ADJACENCY,
|
||||
TRIANGLE_STRIP_ADJACENCY,
|
||||
TRIANGLE_PATCH_ADJACENCY,
|
||||
QUAD_PATCH_LIST,
|
||||
ISO_LINE_LIST,
|
||||
};
|
||||
|
||||
export enum GFXPolygonMode {
|
||||
FILL,
|
||||
LINE,
|
||||
POINT,
|
||||
};
|
||||
|
||||
export enum GFXShadeModel {
|
||||
GOURAND,
|
||||
FLAT,
|
||||
};
|
||||
|
||||
export enum GFXCullMode {
|
||||
NONE,
|
||||
FRONT,
|
||||
BACK,
|
||||
};
|
||||
|
||||
export enum GFXComparisonFunc {
|
||||
NEVER,
|
||||
LESS,
|
||||
EQUAL,
|
||||
LESS_EQUAL,
|
||||
GREATER,
|
||||
NOT_EQUAL,
|
||||
GREATER_EQUAL,
|
||||
ALWAYS,
|
||||
};
|
||||
|
||||
export enum GFXStencilOp {
|
||||
KEEP,
|
||||
ZERO,
|
||||
REPLACE,
|
||||
INCR,
|
||||
DECR,
|
||||
INVERT,
|
||||
INCR_WRAP,
|
||||
DECR_WRAP,
|
||||
};
|
||||
|
||||
export enum GFXBlendOp {
|
||||
ADD,
|
||||
SUB,
|
||||
REV_SUB,
|
||||
MIN,
|
||||
MAX,
|
||||
};
|
||||
|
||||
export enum GFXBlendFactor {
|
||||
ZERO,
|
||||
ONE,
|
||||
SRC_ALPHA,
|
||||
DST_ALPHA,
|
||||
ONE_MINUS_SRC_ALPHA,
|
||||
ONE_MINUS_DST_ALPHA,
|
||||
SRC_COLOR,
|
||||
DST_COLOR,
|
||||
ONE_MINUS_SRC_COLOR,
|
||||
ONE_MINUS_DST_COLOR,
|
||||
SRC_ALPHA_SATURATE,
|
||||
CONSTANT_COLOR,
|
||||
ONE_MINUS_CONSTANT_COLOR,
|
||||
CONSTANT_ALPHA,
|
||||
ONE_MINUS_CONSTANT_ALPHA,
|
||||
};
|
||||
|
||||
export enum GFXColorMask {
|
||||
NONE = 0x0,
|
||||
R = 0x1,
|
||||
G = 0x2,
|
||||
B = 0x4,
|
||||
A = 0x8,
|
||||
ALL = R | G | B | A,
|
||||
};
|
||||
|
||||
export enum GFXFilter {
|
||||
NONE,
|
||||
POINT,
|
||||
LINEAR,
|
||||
ANISOTROPIC,
|
||||
};
|
||||
|
||||
export enum GFXAddress {
|
||||
WRAP,
|
||||
MIRROR,
|
||||
CLAMP,
|
||||
BORDER,
|
||||
};
|
||||
|
||||
export enum GFXTextureType {
|
||||
TEX1D,
|
||||
TEX2D,
|
||||
TEX3D,
|
||||
};
|
||||
|
||||
export enum GFXTextureUsageBit {
|
||||
NONE = 0,
|
||||
TRANSFER_SRC = 0x1,
|
||||
TRANSFER_DST = 0x2,
|
||||
SAMPLED = 0x4,
|
||||
STORAGE = 0x8,
|
||||
COLOR_ATTACHMENT = 0x10,
|
||||
DEPTH_STENCIL_ATTACHMENT = 0x20,
|
||||
TRANSIENT_ATTACHMENT = 0x40,
|
||||
INPUT_ATTACHMENT = 0x80,
|
||||
};
|
||||
|
||||
export type GFXTextureUsage = GFXTextureUsageBit;
|
||||
|
||||
export enum GFXTextureFlagBit {
|
||||
NONE = 0,
|
||||
GEN_MIPMAP = 0x1,
|
||||
CUBEMAP = 0x2,
|
||||
BAKUP_BUFFER = 0x4,
|
||||
};
|
||||
|
||||
export type GFXTextureFlags = GFXTextureFlagBit;
|
||||
|
||||
export enum GFXTextureViewType {
|
||||
TV1D,
|
||||
TV2D,
|
||||
TV3D,
|
||||
CUBE,
|
||||
TV1D_ARRAY,
|
||||
TV2D_ARRAY,
|
||||
};
|
||||
|
||||
export enum GFXShaderType {
|
||||
VERTEX,
|
||||
HULL,
|
||||
DOMAIN,
|
||||
GEOMETRY,
|
||||
FRAGMENT,
|
||||
COMPUTE,
|
||||
COUNT,
|
||||
};
|
||||
|
||||
export enum GFXBindingType {
|
||||
UNKNOWN,
|
||||
UNIFORM_BUFFER,
|
||||
SAMPLER,
|
||||
STORAGE_BUFFER,
|
||||
};
|
||||
|
||||
export enum GFXCommandBufferType {
|
||||
PRIMARY,
|
||||
SECONDARY,
|
||||
};
|
||||
|
||||
// Enumeration all possible values of operations to be performed on initially Loading a Framebuffer Object.
|
||||
export enum GFXLoadOp {
|
||||
LOAD, // Load the contents from the fbo from previous
|
||||
CLEAR, // Clear the fbo
|
||||
DISCARD, // Ignore writing to the fbo and keep old data
|
||||
};
|
||||
|
||||
// Enumerates all possible values of operations to be performed when Storing to a Framebuffer Object.
|
||||
export enum GFXStoreOp {
|
||||
STORE, // Write the source to the destination
|
||||
DISCARD, // Don't write the source to the destination
|
||||
};
|
||||
|
||||
export enum GFXTextureLayout {
|
||||
UNDEFINED,
|
||||
GENERAL,
|
||||
COLOR_ATTACHMENT_OPTIMAL,
|
||||
DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
DEPTH_STENCIL_READONLY_OPTIMAL,
|
||||
SHADER_READONLY_OPTIMAL,
|
||||
TRANSFER_SRC_OPTIMAL,
|
||||
TRANSFER_DST_OPTIMAL,
|
||||
PREINITIALIZED,
|
||||
PRESENT_SRC,
|
||||
};
|
||||
|
||||
export enum GFXPipelineBindPoint {
|
||||
GRAPHICS,
|
||||
COMPUTE,
|
||||
RAY_TRACING,
|
||||
};
|
||||
|
||||
export enum GFXQueueType {
|
||||
GRAPHICS,
|
||||
COMPUTE,
|
||||
TRANSFER,
|
||||
};
|
||||
|
||||
// Interfaces
|
||||
|
||||
export interface GFXRect {
|
||||
left: number;
|
||||
top: number;
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
export interface GFXViewport {
|
||||
left: number;
|
||||
top: number;
|
||||
width: number;
|
||||
height: number;
|
||||
minDepth: number;
|
||||
maxDepth: number;
|
||||
};
|
||||
|
||||
export interface GFXColor {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
a: number;
|
||||
};
|
||||
|
||||
export interface GFXTextureSubres {
|
||||
baseMipLevel: number;
|
||||
levelCount: number;
|
||||
baseArrayLayer: number;
|
||||
layerCount: number;
|
||||
};
|
||||
|
||||
export interface GFXTextureCopy {
|
||||
srcSubres: GFXTextureSubres;
|
||||
srcOffset: number[];
|
||||
dstSubres: GFXTextureSubres;
|
||||
dstOffset: number[];
|
||||
extent: number[];
|
||||
};
|
||||
|
||||
export interface GFXBufferTextureCopy {
|
||||
buffOffset: number;
|
||||
buffStride: number;
|
||||
buffTexHeight: number;
|
||||
texOffset: number[];
|
||||
texExtent: number[];
|
||||
texSubres: GFXTextureSubres;
|
||||
};
|
||||
|
||||
export interface GFXFormatInfo {
|
||||
readonly name: string;
|
||||
readonly size: number;
|
||||
readonly count: number;
|
||||
readonly isFloating: boolean;
|
||||
readonly hasAlpha: boolean;
|
||||
readonly hasDepth: boolean;
|
||||
readonly hasStencil: boolean;
|
||||
readonly isCompressed: boolean;
|
||||
};
|
||||
|
||||
export const GFXFormatInfos: GFXFormatInfo[] = [
|
||||
|
||||
{ name: "UNKNOWN", size: 0, count: 0, isFloating: false, hasAlpha: false, 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, 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, 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, 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, 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, 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, count: 1, isFloating: false, hasAlpha: false, hasDepth: true, hasStencil: false, isCompressed: false },
|
||||
{ name: "D16S8", size: 3, count: 2, isFloating: false, hasAlpha: false, hasDepth: true, hasStencil: true, 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, 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, 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, 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 {
|
||||
|
||||
if (!GFXFormatInfos[format].isCompressed) {
|
||||
return (width * height * depth * GFXFormatInfos[format].size);
|
||||
} else {
|
||||
switch (format) {
|
||||
case GFXFormat.BC1:
|
||||
case GFXFormat.BC1_ALPHA:
|
||||
case GFXFormat.BC1_SRGB:
|
||||
case GFXFormat.BC1_SRGB_ALPHA:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 8 * depth;
|
||||
case GFXFormat.BC2:
|
||||
case GFXFormat.BC2_SRGB:
|
||||
case GFXFormat.BC3:
|
||||
case GFXFormat.BC3_SRGB:
|
||||
case GFXFormat.BC4:
|
||||
case GFXFormat.BC4_SNORM:
|
||||
case GFXFormat.BC6H_SF16:
|
||||
case GFXFormat.BC6H_UF16:
|
||||
case GFXFormat.BC7:
|
||||
case GFXFormat.BC7_SRGB:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16 * depth;
|
||||
case GFXFormat.BC5:
|
||||
case GFXFormat.BC5_SNORM:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 32 * depth;
|
||||
|
||||
case GFXFormat.ETC_RGB8:
|
||||
case GFXFormat.ETC2_RGB8:
|
||||
case GFXFormat.ETC2_SRGB8:
|
||||
case GFXFormat.ETC2_RGB8_A1:
|
||||
case GFXFormat.ETC2_SRGB8_A1:
|
||||
case GFXFormat.EAC_R11:
|
||||
case GFXFormat.EAC_R11SN:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 8 * depth;
|
||||
case GFXFormat.EAC_RG11:
|
||||
case GFXFormat.EAC_RG11SN:
|
||||
return Math.ceil(width / 4) * Math.ceil(height / 4) * 16 * depth;
|
||||
|
||||
case GFXFormat.PVRTC_RGB2:
|
||||
case GFXFormat.PVRTC_RGBA2:
|
||||
case GFXFormat.PVRTC2_2BPP:
|
||||
return Math.ceil(Math.max(width, 16) * Math.max(height, 8) / 4) * depth;
|
||||
case GFXFormat.PVRTC_RGB4:
|
||||
case GFXFormat.PVRTC_RGBA4:
|
||||
case GFXFormat.PVRTC2_4BPP:
|
||||
return Math.ceil(Math.max(width, 16) * Math.max(height, 8) / 2) * depth;
|
||||
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function GFXFormatSurfaceSize(format: GFXFormat, width: number, height: number, depth: number, mips: number): number {
|
||||
|
||||
let size = 0;
|
||||
|
||||
for (let i = 0; i < mips; ++i) {
|
||||
size += GFXFormatSize(format, width, height, depth);
|
||||
width = Math.max(width >> 1, 1);
|
||||
height = Math.max(height >> 1, 1);
|
||||
depth = Math.max(depth >> 1, 1);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
export function GFXGetTypeSize(type: GFXType): number {
|
||||
switch (type) {
|
||||
case GFXType.BOOL:
|
||||
case GFXType.INT:
|
||||
case GFXType.UINT:
|
||||
case GFXType.FLOAT: return 4;
|
||||
case GFXType.BOOL2:
|
||||
case GFXType.INT2:
|
||||
case GFXType.UINT2:
|
||||
case GFXType.FLOAT2: return 8;
|
||||
case GFXType.BOOL3:
|
||||
case GFXType.INT3:
|
||||
case GFXType.UINT3:
|
||||
case GFXType.FLOAT3: return 12;
|
||||
case GFXType.BOOL4:
|
||||
case GFXType.INT4:
|
||||
case GFXType.UINT4:
|
||||
case GFXType.FLOAT4:
|
||||
case GFXType.MAT2: return 16;
|
||||
case GFXType.MAT2X3: return 24;
|
||||
case GFXType.MAT2X4: return 32;
|
||||
case GFXType.MAT3X2: return 24;
|
||||
case GFXType.MAT3: return 36;
|
||||
case GFXType.MAT3X4: return 48;
|
||||
case GFXType.MAT4X2: return 32;
|
||||
case GFXType.MAT4X2: return 32;
|
||||
case GFXType.MAT4: return 64;
|
||||
case GFXType.SAMPLER1D:
|
||||
case GFXType.SAMPLER1D_ARRAY:
|
||||
case GFXType.SAMPLER2D:
|
||||
case GFXType.SAMPLER2D_ARRAY:
|
||||
case GFXType.SAMPLER3D:
|
||||
case GFXType.SAMPLER_CUBE: return 4;
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import { GFXDevice } from './device';
|
||||
import { GFXFormat } from './define';
|
||||
import { GFXFormat, GFXVertexSemantic } from './gfx-define';
|
||||
import { GFXBuffer } from './buffer';
|
||||
import { GFXShader } from './shader';
|
||||
|
||||
export interface GFXInputAttribute {
|
||||
name: string;
|
||||
semantic: GFXVertexSemantic;
|
||||
format: GFXFormat;
|
||||
stream?: number;
|
||||
isInstanced?: boolean;
|
||||
@@ -12,7 +12,6 @@ export interface GFXInputAttribute {
|
||||
|
||||
export interface GFXInputAssemblerInfo {
|
||||
attributes: GFXInputAttribute[];
|
||||
shader: GFXShader;
|
||||
vertexBuffers: GFXBuffer[];
|
||||
indexBuffer?: GFXBuffer;
|
||||
isIndirect?: boolean;
|
||||
@@ -43,6 +42,10 @@ export abstract class GFXInputAssembler {
|
||||
}
|
||||
}
|
||||
|
||||
public get attributes(): GFXInputAttribute[] {
|
||||
return this._attributes;
|
||||
}
|
||||
|
||||
public get vertexCount(): number {
|
||||
return this._vertexCount;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { GFXDevice } from './device';
|
||||
import { GFXBindingLayout } from './binding-layout';
|
||||
import { GFXShaderType } from './shader';
|
||||
import { GFXShaderType } from './gfx-define';
|
||||
|
||||
export class GFXPushConstantRange {
|
||||
shaderType : GFXShaderType = GFXShaderType.VERTEX;
|
||||
offset : number = 0;
|
||||
count : number = 0;
|
||||
export interface GFXPushConstantRange {
|
||||
shaderType : GFXShaderType;
|
||||
offset : number;
|
||||
count : number;
|
||||
};
|
||||
|
||||
export interface GFXPipelineLayoutInfo {
|
||||
|
||||
@@ -3,97 +3,7 @@ import { GFXShader } from './shader';
|
||||
import { GFXRenderPass } from './render-pass';
|
||||
import { GFXPipelineLayout } from './pipeline-layout';
|
||||
import { GFXInputAttribute } from './input-assembler';
|
||||
|
||||
export enum GFXPrimitiveMode {
|
||||
POINT_LIST,
|
||||
LINE_LIST,
|
||||
LINE_STRIP,
|
||||
LINE_LOOP,
|
||||
TRIANGLE_LIST,
|
||||
TRIANGLE_STRIP,
|
||||
TRIANGLE_FAN,
|
||||
LINE_LIST_ADJACENCY,
|
||||
LINE_STRIP_ADJACENCY,
|
||||
TRIANGLE_LIST_ADJACENCY,
|
||||
TRIANGLE_STRIP_ADJACENCY,
|
||||
TRIANGLE_PATCH_ADJACENCY,
|
||||
QUAD_PATCH_LIST,
|
||||
ISO_LINE_LIST,
|
||||
};
|
||||
|
||||
export enum GFXPolygonMode {
|
||||
FILL,
|
||||
LINE,
|
||||
POINT,
|
||||
};
|
||||
|
||||
export enum GFXShadeModel {
|
||||
GOURAND,
|
||||
FLAT,
|
||||
};
|
||||
|
||||
export enum GFXCullMode {
|
||||
NONE,
|
||||
FRONT,
|
||||
BACK,
|
||||
};
|
||||
|
||||
export enum GFXComparisonFunc {
|
||||
NEVER,
|
||||
LESS,
|
||||
EQUAL,
|
||||
LESS_EQUAL,
|
||||
GREATER,
|
||||
NOT_EQUAL,
|
||||
GREATER_EQUAL,
|
||||
ALWAYS,
|
||||
};
|
||||
|
||||
export enum GFXStencilOp {
|
||||
KEEP,
|
||||
ZERO,
|
||||
REPLACE,
|
||||
INCR,
|
||||
DECR,
|
||||
INVERT,
|
||||
INCR_WRAP,
|
||||
DECR_WRAP,
|
||||
};
|
||||
|
||||
export enum GFXBlendOp {
|
||||
ADD,
|
||||
SUB,
|
||||
REV_SUB,
|
||||
MIN,
|
||||
MAX,
|
||||
};
|
||||
|
||||
export enum GFXBlendFactor {
|
||||
ZERO,
|
||||
ONE,
|
||||
SRC_ALPHA,
|
||||
DST_ALPHA,
|
||||
ONE_MINUS_SRC_ALPHA,
|
||||
ONE_MINUS_DST_ALPHA,
|
||||
SRC_COLOR,
|
||||
DST_COLOR,
|
||||
ONE_MINUS_SRC_COLOR,
|
||||
ONE_MINUS_DST_COLOR,
|
||||
SRC_ALPHA_SATURATE,
|
||||
CONSTANT_COLOR,
|
||||
ONE_MINUS_CONSTANT_COLOR,
|
||||
CONSTANT_ALPHA,
|
||||
ONE_MINUS_CONSTANT_ALPHA,
|
||||
};
|
||||
|
||||
export enum GFXColorMask {
|
||||
NONE = 0x0,
|
||||
R = 0x1,
|
||||
G = 0x2,
|
||||
B = 0x4,
|
||||
A = 0x8,
|
||||
ALL = R | G | B | A,
|
||||
};
|
||||
import { GFXPolygonMode, GFXShadeModel, GFXCullMode, GFXComparisonFunc, GFXStencilOp, GFXBlendFactor, GFXBlendOp, GFXColorMask, GFXPrimitiveMode } from './gfx-define';
|
||||
|
||||
export class GFXRasterizerState {
|
||||
isDiscard: boolean = false;
|
||||
|
||||
+3
-6
@@ -1,10 +1,6 @@
|
||||
import { GFXDevice } from './device';
|
||||
|
||||
export enum GFXQueueType {
|
||||
GRAPHICS,
|
||||
COMPUTE,
|
||||
TRANSFER,
|
||||
};
|
||||
import { GFXCommandBuffer } from './command-buffer';
|
||||
import { GFXQueueType } from './gfx-define';
|
||||
|
||||
export interface GFXQueueInfo {
|
||||
type : GFXQueueType;
|
||||
@@ -18,6 +14,7 @@ export abstract class GFXQueue {
|
||||
|
||||
public abstract initialize(info : GFXQueueInfo) : boolean;
|
||||
public abstract destroy();
|
||||
public abstract submit(cmdBuffs: GFXCommandBuffer[], fence?);
|
||||
|
||||
public get type(): number {
|
||||
return this._type;
|
||||
|
||||
+12
-48
@@ -1,35 +1,6 @@
|
||||
import { GFXFormat, GFXFormatInfo } from './define';
|
||||
import { GFXFormat, GFXLoadOp, GFXStoreOp, GFXTextureLayout, GFXPipelineBindPoint } from './gfx-define';
|
||||
import { GFXDevice } from './device';
|
||||
|
||||
// Enumeration all possible values of operations to be performed on initially Loading a Framebuffer Object.
|
||||
export enum GFXLoadOp
|
||||
{
|
||||
LOAD, // Load the contents from the fbo from previous
|
||||
CLEAR, // Clear the fbo
|
||||
DISCARD, // Ignore writing to the fbo and keep old data
|
||||
};
|
||||
|
||||
// Enumerates all possible values of operations to be performed when Storing to a Framebuffer Object.
|
||||
export enum GFXStoreOp
|
||||
{
|
||||
STORE, // Write the source to the destination
|
||||
DISCARD, // Don't write the source to the destination
|
||||
};
|
||||
|
||||
export enum GFXTextureLayout
|
||||
{
|
||||
UNDEFINED,
|
||||
GENERAL,
|
||||
COLOR_ATTACHMENT_OPTIMAL,
|
||||
DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
||||
DEPTH_STENCIL_READONLY_OPTIMAL,
|
||||
SHADER_READONLY_OPTIMAL,
|
||||
TRANSFER_SRC_OPTIMAL,
|
||||
TRANSFER_DST_OPTIMAL,
|
||||
PREINITIALIZED,
|
||||
PRESENT_SRC,
|
||||
};
|
||||
|
||||
export class GFXColorAttachment
|
||||
{
|
||||
format : GFXFormat = GFXFormat.UNKNOWN;
|
||||
@@ -52,28 +23,21 @@ export class GFXDepthStencilAttachment
|
||||
endLayout : GFXTextureLayout = GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
};
|
||||
|
||||
export enum GFXPipelineBindPoint
|
||||
export interface GFXSubPassInfo
|
||||
{
|
||||
GRAPHICS,
|
||||
COMPUTE,
|
||||
RAY_TRACING,
|
||||
bindPoint : GFXPipelineBindPoint;
|
||||
inputs : number[];
|
||||
colors : number[];
|
||||
resolves : number[];
|
||||
depthStencil : number;
|
||||
preserves : number[];
|
||||
};
|
||||
|
||||
export class GFXSubPassInfo
|
||||
export interface GFXRenderPassInfo
|
||||
{
|
||||
bindPoint : GFXPipelineBindPoint = GFXPipelineBindPoint.GRAPHICS;
|
||||
inputs : number[] = [];
|
||||
colors : number[] = [];
|
||||
resolves : number[] = [];
|
||||
depthStencil : number = -1;
|
||||
preserves : number[] = [];
|
||||
};
|
||||
|
||||
export class GFXRenderPassInfo
|
||||
{
|
||||
colorAttachment : GFXColorAttachment[] = [];
|
||||
depthStencilAttachment : GFXDepthStencilAttachment | null = null;
|
||||
//subPasses : GFXSubPassInfo[] = [];
|
||||
colorAttachment? : GFXColorAttachment[];
|
||||
depthStencilAttachment? : GFXDepthStencilAttachment;
|
||||
//subPasses? : GFXSubPassInfo[];
|
||||
};
|
||||
|
||||
export abstract class GFXRenderPass {
|
||||
|
||||
+23
-16
@@ -1,21 +1,23 @@
|
||||
import { GFXDevice } from './device';
|
||||
import { GFXComparisonFunc } from './pipeline-state';
|
||||
import { GFXFilter, GFXAddress, GFXComparisonFunc } from './gfx-define';
|
||||
|
||||
export enum GFXFilter {
|
||||
NONE,
|
||||
POINT,
|
||||
LINEAR,
|
||||
ANISOTROPIC,
|
||||
export interface GFXSamplerInfo {
|
||||
name? : string;
|
||||
minFilter? : GFXFilter;
|
||||
magFilter? : GFXFilter;
|
||||
mipFilter? : GFXFilter;
|
||||
addressU? : GFXAddress;
|
||||
addressV? : GFXAddress;
|
||||
addressW? : GFXAddress;
|
||||
maxAnisotropy? : number;
|
||||
cmpFunc? : GFXComparisonFunc;
|
||||
borderColor? : number[];
|
||||
minLOD? : number;
|
||||
maxLOD? : number;
|
||||
mipLODBias? : number;
|
||||
};
|
||||
|
||||
export enum GFXAddress {
|
||||
WRAP,
|
||||
MIRROR,
|
||||
CLAMP,
|
||||
BORDER,
|
||||
};
|
||||
|
||||
export class GFXSamplerInfo {
|
||||
export class GFXSamplerState {
|
||||
name : string = "";
|
||||
minFilter : GFXFilter = GFXFilter.LINEAR;
|
||||
magFilter : GFXFilter = GFXFilter.LINEAR;
|
||||
@@ -30,7 +32,7 @@ export class GFXSamplerInfo {
|
||||
maxLOD : number = 1000;
|
||||
mipLODBias : number = 0.0;
|
||||
|
||||
public compare(state : GFXSamplerInfo) : boolean {
|
||||
public compare(state : GFXSamplerState) : boolean {
|
||||
return (this.minFilter === state.minFilter) &&
|
||||
(this.magFilter === state.magFilter) &&
|
||||
(this.mipFilter === state.mipFilter) &&
|
||||
@@ -50,11 +52,16 @@ export abstract class GFXSampler {
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
this._device = device;
|
||||
this._state = new GFXSamplerState;
|
||||
}
|
||||
|
||||
public abstract initialize(info : GFXSamplerInfo) : boolean;
|
||||
public abstract destroy() : void;
|
||||
|
||||
public get state(): GFXSamplerState {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
protected _device : GFXDevice;
|
||||
protected _state : GFXSamplerInfo | null = null;
|
||||
protected _state : GFXSamplerState;
|
||||
};
|
||||
|
||||
+8
-19
@@ -1,22 +1,17 @@
|
||||
import { GFXDevice } from './device';
|
||||
import { GFXBinding } from './binding-layout';
|
||||
import { GFXType } from './define';
|
||||
|
||||
export enum GFXShaderType {
|
||||
VERTEX,
|
||||
HULL,
|
||||
DOMAIN,
|
||||
GEOMETRY,
|
||||
FRAGMENT,
|
||||
COMPUTE,
|
||||
COUNT,
|
||||
};
|
||||
import { GFXType, GFXShaderType } from './gfx-define';
|
||||
|
||||
export interface GFXShaderMacro {
|
||||
macro: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
export interface GFXShaderStage {
|
||||
type: GFXShaderType;
|
||||
source: string;
|
||||
macros?: GFXShaderMacro[];
|
||||
};
|
||||
|
||||
export interface GFXUniform {
|
||||
name: string;
|
||||
type: GFXType;
|
||||
@@ -37,14 +32,8 @@ export interface GFXUniformSampler {
|
||||
count: number;
|
||||
};
|
||||
|
||||
export interface GFXShaderStage {
|
||||
type: GFXShaderType;
|
||||
source: string;
|
||||
macros?: GFXShaderMacro[];
|
||||
};
|
||||
|
||||
export interface GFXShaderInfo {
|
||||
name?: string;
|
||||
name: string;
|
||||
stages: GFXShaderStage[];
|
||||
//bindings: GFXBinding[];
|
||||
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { GFXFormat, GFXFormatInfo } from './define';
|
||||
import { GFXFormat, GFXTextureViewType } from './gfx-define';
|
||||
import { GFXDevice } from './device';
|
||||
import { GFXTexture } from './texture';
|
||||
|
||||
export enum GFXTextureViewType {
|
||||
TV1D,
|
||||
TV2D,
|
||||
TV3D,
|
||||
CUBE,
|
||||
TV1D_ARRAY,
|
||||
TV2D_ARRAY,
|
||||
};
|
||||
|
||||
export interface GFXTextureViewInfo {
|
||||
texture: GFXTexture;
|
||||
type: GFXTextureViewType;
|
||||
|
||||
+1
-30
@@ -1,35 +1,6 @@
|
||||
import { GFXFormat, GFXFormatInfo } from './define';
|
||||
import { GFXFormat, GFXTextureType, GFXTextureUsage, GFXTextureFlags, GFXTextureUsageBit, GFXTextureFlagBit } from './gfx-define';
|
||||
import { GFXDevice } from './device';
|
||||
|
||||
export enum GFXTextureType {
|
||||
TEX1D,
|
||||
TEX2D,
|
||||
TEX3D,
|
||||
};
|
||||
|
||||
export enum GFXTextureUsageBit {
|
||||
NONE = 0,
|
||||
TRANSFER_SRC = 0x1,
|
||||
TRANSFER_DST = 0x2,
|
||||
SAMPLED = 0x4,
|
||||
STORAGE = 0x8,
|
||||
COLOR_ATTACHMENT = 0x10,
|
||||
DEPTH_STENCIL_ATTACHMENT = 0x20,
|
||||
TRANSIENT_ATTACHMENT = 0x40,
|
||||
INPUT_ATTACHMENT = 0x80,
|
||||
};
|
||||
|
||||
export type GFXTextureUsage = GFXTextureUsageBit;
|
||||
|
||||
export enum GFXTextureFlagBit {
|
||||
NONE = 0,
|
||||
GEN_MIPMAP = 0x1,
|
||||
CUBEMAP = 0x2,
|
||||
BAKUP_BUFFER = 0x4,
|
||||
};
|
||||
|
||||
export type GFXTextureFlags = GFXTextureFlagBit;
|
||||
|
||||
export interface GFXTextureInfo {
|
||||
type: GFXTextureType;
|
||||
usage: GFXTextureUsage;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { GFXBufferInfo, GFXBuffer, GFXMemoryUsageBit, GFXBufferAccess, GFXBufferAccessBit, GFXBufferUsageBit } from '../buffer';
|
||||
import { GFXBufferInfo, GFXBuffer } from '../buffer';
|
||||
import { GFXDevice } from '../device';
|
||||
import { WebGLGPUBuffer } from './webgl-gpu-objects';
|
||||
import { WebGLGFXDevice } from './webgl-device';
|
||||
import { BufferView } from '../define';
|
||||
import { GFXMemoryUsageBit } from '../gfx-define';
|
||||
|
||||
export class WebGLGFXBuffer extends GFXBuffer {
|
||||
|
||||
@@ -23,7 +23,7 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
}
|
||||
|
||||
//this._isSimulate = (this._usage & GFXBufferUsageBit.TRANSFER_SRC) != GFXBufferUsageBit.NONE;
|
||||
this._gpuBuffer = this.webGLDevice.emitCmdCreateGPUBuffer(info, this._bufferView);
|
||||
this._gpuBuffer = this.webGLDevice.emitCmdCreateGPUBuffer(info, this._buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -38,13 +38,13 @@ export class WebGLGFXBuffer extends GFXBuffer {
|
||||
this._bufferView = null;
|
||||
}
|
||||
|
||||
public update(buffer: BufferView, offset: number) {
|
||||
public update(buffer: ArrayBuffer, offset?: number) {
|
||||
|
||||
if (this._bufferView) {
|
||||
this._bufferView.set(buffer, offset);
|
||||
this._bufferView.set(new Uint8Array(buffer), offset);
|
||||
}
|
||||
|
||||
this.webGLDevice.emitCmdUpdateGPUBuffer(<WebGLGPUBuffer>this._gpuBuffer, offset, buffer);
|
||||
this.webGLDevice.emitCmdUpdateGPUBuffer(<WebGLGPUBuffer>this._gpuBuffer, offset? offset : 0, buffer);
|
||||
}
|
||||
|
||||
public get webGLDevice(): WebGLGFXDevice {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GFXDevice } from '../device';
|
||||
import { GFXCommandBuffer, GFXCommandBufferInfo, GFXBufferTextureCopy } from '../command-buffer';
|
||||
import { GFXCommandBuffer, GFXCommandBufferInfo } from '../command-buffer';
|
||||
import { GFXBuffer } from '../buffer';
|
||||
import { WebGLCmdUpdateBuffer, WebGLCmd, WebGLCmdBeginRenderPass, WebGLCmdPackage, WebGLCmdBindInputAssembler, WebGLCmdBindPipelineState, WebGLCmdDraw, WebGLCmdBindBindingLayout, WebGLCmdCopyBufferToTexture } from './webgl-commands';
|
||||
import { WebGLGFXCommandAllocator } from './webgl-command-allocator';
|
||||
@@ -14,8 +14,8 @@ import { WebGLGFXPipelineState } from './webgl-pipeline-state';
|
||||
import { GFXBindingLayout } from '../binding-layout';
|
||||
import { WebGLGFXBindingLayout } from './webgl-binding-layout';
|
||||
import { GFXTexture } from '../texture';
|
||||
import { GFXTextureLayout } from '../render-pass';
|
||||
import { WebGLGFXTexture } from './webgl-texture';
|
||||
import { GFXColor, GFXViewport, GFXRect, GFXBufferTextureCopy, GFXTextureLayout } from '../gfx-define';
|
||||
|
||||
export class WebGLGFXCommandBuffer extends GFXCommandBuffer {
|
||||
|
||||
@@ -52,12 +52,11 @@ export class WebGLGFXCommandBuffer extends GFXCommandBuffer {
|
||||
public end() {
|
||||
}
|
||||
|
||||
public beginRenderPass(framebuffer : GFXFramebuffer, viewport : number[], numClearColors : number, clearColors : number[], clearStencil : number) {
|
||||
public beginRenderPass(framebuffer : GFXFramebuffer, renderArea : GFXRect, clearColors : GFXColor[], clearDepth: 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.renderArea = renderArea;
|
||||
cmd.clearColors = clearColors.slice();
|
||||
cmd.clearStencil = clearStencil;
|
||||
this.cmdPackage.beginRenderPassCmds.push(cmd);
|
||||
@@ -117,13 +116,13 @@ export class WebGLGFXCommandBuffer extends GFXCommandBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
public updateBuffer(buffer : GFXBuffer, data : Buffer, offset : number) {
|
||||
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.buffer = data.slice(0);
|
||||
cmd.buffer = data;
|
||||
cmd.offset = offset;
|
||||
this.cmdPackage.updateBufferCmds.push(cmd);
|
||||
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
import { WebGLGPUBuffer, WebGLGPUTexture, WebGLGPUInputAssembler, WebGLGPUFramebuffer, WebGLGPUShader, WebGLGPUInput, WebGLAttrib, WebGLGPUPipelineState, WebGLGPUUniformBlock, WebGLGPUBindingLayout, WebGLGPUUniform, WebGLGPUUniformSampler } from "./webgl-gpu-objects";
|
||||
import { WebGLGFXDevice } from "./webgl-device";
|
||||
import { GFXBufferUsageBit, GFXMemoryUsageBit } from "../buffer";
|
||||
import { GFXTextureViewType } from "../texture-view";
|
||||
import { GFXFormatInfos, GFXFormat, WebGLEXT, GFXType, GFX_MAX_VERTEX_ATTRIBUTES, GFXFormatSize, BufferView } from "../define";
|
||||
import { GFXShaderType } from "../shader";
|
||||
import { GFXLoadOp, GFXTextureLayout } from "../render-pass";
|
||||
import { GFXColorMask, GFXCullMode } from "../pipeline-state";
|
||||
import { GFXFormatInfos, GFXFormat, WebGLEXT, GFXType, GFX_MAX_VERTEX_ATTRIBUTES, GFXFormatSize, GFXColor, GFXViewport, GFXRect, GFXBindingType, GFXBufferTextureCopy, GFXColorMask, GFXCullMode, GFXShaderType, GFXTextureViewType, GFXTextureLayout, GFXLoadOp, GFXTextureFlagBit, GFXMemoryUsageBit, GFXBufferUsageBit } from "../gfx-define";
|
||||
import { WebGLGFXCommandAllocator } from "./webgl-command-allocator";
|
||||
import { GFXBindingType } from "../binding-layout";
|
||||
import { WebGLTexUnit } from "./webgl-state-cache";
|
||||
import { GFXBufferTextureCopy } from "../command-buffer";
|
||||
import { GFXTextureFlagBit } from "../texture";
|
||||
|
||||
function GFXFormatToWebGLType(format: GFXFormat, device : WebGLGFXDevice): GLenum {
|
||||
function GFXFormatToWebGLType(format: GFXFormat, device: WebGLGFXDevice): GLenum {
|
||||
switch (format) {
|
||||
case GFXFormat.R8: return WebGLRenderingContext.UNSIGNED_BYTE;
|
||||
case GFXFormat.R8SN: return WebGLRenderingContext.BYTE;
|
||||
@@ -71,7 +63,7 @@ function GFXFormatToWebGLType(format: GFXFormat, device : WebGLGFXDevice): GLenu
|
||||
case GFXFormat.D16: return WebGLRenderingContext.UNSIGNED_SHORT;
|
||||
case GFXFormat.D16S8: return WebGLRenderingContext.UNSIGNED_SHORT;
|
||||
case GFXFormat.D24: return WebGLRenderingContext.UNSIGNED_INT;
|
||||
case GFXFormat.D24S8: return device.WEBGL_depth_texture? device.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL : WebGLRenderingContext.UNSIGNED_INT;
|
||||
case GFXFormat.D24S8: return device.WEBGL_depth_texture ? device.WEBGL_depth_texture.UNSIGNED_INT_24_8_WEBGL : WebGLRenderingContext.UNSIGNED_INT;
|
||||
case GFXFormat.D32F: return WebGLRenderingContext.FLOAT;
|
||||
case GFXFormat.D32F_S8: return WebGLRenderingContext.FLOAT;
|
||||
|
||||
@@ -282,8 +274,7 @@ function WebGLGetComponentCount(glType: GLenum): GFXType {
|
||||
case WebGLRenderingContext.FLOAT_MAT3: return 3;
|
||||
case WebGLRenderingContext.FLOAT_MAT4: return 4;
|
||||
default: {
|
||||
console.error("Unsupported GLType, get component count failed.");
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,9 +348,8 @@ export class WebGLCmdObject {
|
||||
export class WebGLCmdBeginRenderPass extends WebGLCmdObject {
|
||||
|
||||
gpuFramebuffer: WebGLGPUFramebuffer | null = null;
|
||||
viewport: number[] = [];
|
||||
numClearColors: number = 0;
|
||||
clearColors: number[] = [];
|
||||
renderArea: GFXRect = { left: 0.0, top: 0.0, width: 0.0, height: 0.0 };
|
||||
clearColors: GFXColor[] = [];
|
||||
clearDepth: number = 1.0;
|
||||
clearStencil: number = 0;
|
||||
|
||||
@@ -415,7 +405,7 @@ export class WebGLCmdDraw extends WebGLCmdObject {
|
||||
export class WebGLCmdUpdateBuffer extends WebGLCmdObject {
|
||||
|
||||
gpuBuffer: WebGLGPUBuffer | null = null;
|
||||
buffer: Buffer | null = null;
|
||||
buffer: ArrayBuffer | null = null;
|
||||
offset: number = 0;
|
||||
|
||||
constructor() {
|
||||
@@ -560,7 +550,7 @@ export function WebGLCmdFuncDestroyBuffer(device: WebGLGFXDevice, gpuBuffer: Web
|
||||
}
|
||||
}
|
||||
|
||||
export function WebGLCmdFuncUpdateBuffer(device: WebGLGFXDevice, gpuBuffer: WebGLGPUBuffer, offset: number, buffer: BufferView) {
|
||||
export function WebGLCmdFuncUpdateBuffer(device: WebGLGFXDevice, gpuBuffer: WebGLGPUBuffer, offset: number, buffer: ArrayBuffer) {
|
||||
|
||||
let gl = device.gl;
|
||||
|
||||
@@ -570,7 +560,7 @@ export function WebGLCmdFuncUpdateBuffer(device: WebGLGFXDevice, gpuBuffer: WebG
|
||||
gl.bindBuffer(WebGLRenderingContext.ARRAY_BUFFER, gpuBuffer.glBuffer);
|
||||
device.stateCache.glArrayBuffer = gpuBuffer.glBuffer;
|
||||
}
|
||||
gl.bufferSubData(gpuBuffer.glTarget, offset, buffer.buffer);
|
||||
gl.bufferSubData(gpuBuffer.glTarget, offset, buffer);
|
||||
break;
|
||||
}
|
||||
case WebGLRenderingContext.ELEMENT_ARRAY_BUFFER: {
|
||||
@@ -578,7 +568,7 @@ export function WebGLCmdFuncUpdateBuffer(device: WebGLGFXDevice, gpuBuffer: WebG
|
||||
gl.bindBuffer(WebGLRenderingContext.ELEMENT_ARRAY_BUFFER, gpuBuffer.glBuffer);
|
||||
device.stateCache.glElementArrayBuffer = gpuBuffer.glBuffer;
|
||||
}
|
||||
gl.bufferSubData(gpuBuffer.glTarget, offset, buffer.buffer);
|
||||
gl.bufferSubData(gpuBuffer.glTarget, offset, buffer);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@@ -775,8 +765,9 @@ export function WebGLCmdFuncCreateShader(device: WebGLGFXDevice, gpuShader: WebG
|
||||
var isSuccess = gl.getShaderParameter(gpuStage.glShader, gl.COMPILE_STATUS);
|
||||
if (!isSuccess) {
|
||||
console.error(shaderTypeStr + " in '" + gpuShader.name + "' compilation failed.");
|
||||
console.error(gpuStage.source);
|
||||
console.error(gl.getShaderInfoLog(gpuStage.glShader));
|
||||
} else {
|
||||
|
||||
gl.deleteShader(gpuStage.glShader);
|
||||
gpuStage.glShader = 0;
|
||||
}
|
||||
@@ -797,7 +788,9 @@ export function WebGLCmdFuncCreateShader(device: WebGLGFXDevice, gpuShader: WebG
|
||||
|
||||
gl.linkProgram(gpuShader.glProgram);
|
||||
var isSuccess = gl.getProgramParameter(gpuShader.glProgram, gl.LINK_STATUS);
|
||||
if (!isSuccess) {
|
||||
if (isSuccess) {
|
||||
console.info("Shader '" + gpuShader.name + "' compilation successed.");
|
||||
} else {
|
||||
console.error("Failed to link shader '" + gpuShader.name + "'.");
|
||||
console.error(gl.getProgramInfoLog(gpuShader.glProgram));
|
||||
|
||||
@@ -820,7 +813,7 @@ export function WebGLCmdFuncCreateShader(device: WebGLGFXDevice, gpuShader: WebG
|
||||
let glLoc = gl.getAttribLocation(gpuShader.glProgram, info.name);
|
||||
|
||||
let varName: string;
|
||||
let nameOffset = info.name.search('[');
|
||||
let nameOffset = info.name.indexOf('[');
|
||||
if (nameOffset !== -1) {
|
||||
varName = info.name.substr(0, nameOffset);
|
||||
} else {
|
||||
@@ -921,7 +914,7 @@ export function WebGLCmdFuncCreateShader(device: WebGLGFXDevice, gpuShader: WebG
|
||||
let glLoc = gl.getUniformLocation(gpuShader.glProgram, info.name);
|
||||
if (glLoc) {
|
||||
let varName: string;
|
||||
let nameOffset = info.name.search('[');
|
||||
let nameOffset = info.name.indexOf('[');
|
||||
if (nameOffset !== -1) {
|
||||
varName = info.name.substr(0, nameOffset);
|
||||
} else {
|
||||
@@ -996,6 +989,37 @@ export function WebGLCmdFuncDestroyShader(device: WebGLGFXDevice, gpuShader: Web
|
||||
|
||||
export function WebGLCmdFuncCreateInputAssember(device: WebGLGFXDevice, gpuInputAssembler: WebGLGPUInputAssembler) {
|
||||
|
||||
gpuInputAssembler.glAttribs = new Array<WebGLAttrib>(gpuInputAssembler.attributes.length);
|
||||
|
||||
let offsets = [0, 0, 0, 0, 0, 0, 0, 0];
|
||||
|
||||
for(let i = 0; i < gpuInputAssembler.attributes.length; ++i) {
|
||||
let attrib = gpuInputAssembler.attributes[i];
|
||||
|
||||
let stream = attrib.stream ? attrib.stream : 0;
|
||||
//if (stream < gpuInputAssembler.gpuVertexBuffers.length) {
|
||||
|
||||
let gpuBuffer = gpuInputAssembler.gpuVertexBuffers[stream];
|
||||
|
||||
let glType = GFXFormatToWebGLType(attrib.format, device);
|
||||
let size = WebGLGetTypeSize(glType);
|
||||
|
||||
gpuInputAssembler.glAttribs[i] = {
|
||||
glBuffer: gpuBuffer.glBuffer,
|
||||
glLoc: attrib.semantic,
|
||||
glType: glType,
|
||||
size: size,
|
||||
count: GFXFormatInfos[attrib.format].count,
|
||||
stride: gpuBuffer.stride,
|
||||
componentCount: WebGLGetComponentCount(glType),
|
||||
isInstanced: attrib.isInstanced? attrib.isInstanced : false,
|
||||
offset: offsets[stream],
|
||||
};
|
||||
|
||||
offsets[stream] += size;
|
||||
}
|
||||
|
||||
/*
|
||||
if (gpuInputAssembler.gpuShader) {
|
||||
let attribCount = gpuInputAssembler.gpuShader.glInputs.length;
|
||||
gpuInputAssembler.glAttribs = new Array<WebGLAttrib>(attribCount);
|
||||
@@ -1033,6 +1057,7 @@ export function WebGLCmdFuncCreateInputAssember(device: WebGLGFXDevice, gpuInput
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
export function WebGLCmdFuncDestroyInputAssembler(device: WebGLGFXDevice, gpuInputAssembler: WebGLGPUInputAssembler) {
|
||||
@@ -1067,30 +1092,30 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
device.stateCache.glFramebuffer = cmd.gpuFramebuffer.glFramebuffer;
|
||||
}
|
||||
|
||||
if (device.stateCache.viewport[0] !== cmd.viewport[0] ||
|
||||
device.stateCache.viewport[1] !== cmd.viewport[1] ||
|
||||
device.stateCache.viewport[2] !== cmd.viewport[2] ||
|
||||
device.stateCache.viewport[3] !== cmd.viewport[3]) {
|
||||
if (device.stateCache.viewport.left !== cmd.renderArea.left ||
|
||||
device.stateCache.viewport.top !== cmd.renderArea.top ||
|
||||
device.stateCache.viewport.width !== cmd.renderArea.width ||
|
||||
device.stateCache.viewport.height !== cmd.renderArea.height) {
|
||||
|
||||
gl.viewport(cmd.viewport[0], cmd.viewport[1], cmd.viewport[2], cmd.viewport[3]);
|
||||
gl.viewport(cmd.renderArea.left, cmd.renderArea.top, cmd.renderArea.width, cmd.renderArea.height);
|
||||
|
||||
device.stateCache.viewport[0] = cmd.viewport[0];
|
||||
device.stateCache.viewport[1] = cmd.viewport[1];
|
||||
device.stateCache.viewport[2] = cmd.viewport[2];
|
||||
device.stateCache.viewport[3] = cmd.viewport[3];
|
||||
device.stateCache.viewport.left = cmd.renderArea.left;
|
||||
device.stateCache.viewport.top = cmd.renderArea.top;
|
||||
device.stateCache.viewport.width = cmd.renderArea.width;
|
||||
device.stateCache.viewport.height = cmd.renderArea.height;
|
||||
}
|
||||
|
||||
if (device.stateCache.scissorRect[0] !== cmd.viewport[0] ||
|
||||
device.stateCache.scissorRect[1] !== cmd.viewport[1] ||
|
||||
device.stateCache.scissorRect[2] !== cmd.viewport[2] ||
|
||||
device.stateCache.scissorRect[3] !== cmd.viewport[3]) {
|
||||
if (device.stateCache.scissorRect.left !== cmd.renderArea.left ||
|
||||
device.stateCache.scissorRect.top !== cmd.renderArea.top ||
|
||||
device.stateCache.scissorRect.width !== cmd.renderArea.width ||
|
||||
device.stateCache.scissorRect.height !== cmd.renderArea.height) {
|
||||
|
||||
gl.scissor(cmd.viewport[0], cmd.viewport[1], cmd.viewport[2], cmd.viewport[3]);
|
||||
gl.scissor(cmd.renderArea.left, cmd.renderArea.top, cmd.renderArea.width, cmd.renderArea.height);
|
||||
|
||||
device.stateCache.scissorRect[0] = cmd.viewport[0];
|
||||
device.stateCache.scissorRect[1] = cmd.viewport[1];
|
||||
device.stateCache.scissorRect[2] = cmd.viewport[2];
|
||||
device.stateCache.scissorRect[3] = cmd.viewport[3];
|
||||
device.stateCache.scissorRect.left = cmd.renderArea.left;
|
||||
device.stateCache.scissorRect.top = cmd.renderArea.top;
|
||||
device.stateCache.scissorRect.width = cmd.renderArea.width;
|
||||
device.stateCache.scissorRect.height = cmd.renderArea.height;
|
||||
}
|
||||
|
||||
let curGPURenderPass = cmd.gpuFramebuffer.gpuRenderPass;
|
||||
@@ -1110,7 +1135,8 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
gl.colorMask(true, true, true, true);
|
||||
}
|
||||
|
||||
gl.clearColor(cmd.clearColors[0], cmd.clearColors[1], cmd.clearColors[2], cmd.clearColors[3]);
|
||||
let clearColor = cmd.clearColors[0];
|
||||
gl.clearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
clears |= WebGLRenderingContext.COLOR_BUFFER_BIT;
|
||||
|
||||
break;
|
||||
@@ -1520,9 +1546,9 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 2*m;
|
||||
let idx = 2 * m;
|
||||
if (glBlock.bufferView.getInt32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getInt32(offset+4) !== glUniform.bufferView[idx+1]) {
|
||||
glBlock.bufferView.getInt32(offset + 4) !== glUniform.bufferView[idx + 1]) {
|
||||
gl.uniform2iv(glUniform.glLoc, <Int32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
@@ -1534,10 +1560,10 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
case WebGLRenderingContext.INT_VEC3: {
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 3*m;
|
||||
let idx = 3 * m;
|
||||
if (glBlock.bufferView.getInt32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getInt32(offset+4) !== glUniform.bufferView[idx+1] ||
|
||||
glBlock.bufferView.getInt32(offset+8) !== glUniform.bufferView[idx+2]) {
|
||||
glBlock.bufferView.getInt32(offset + 4) !== glUniform.bufferView[idx + 1] ||
|
||||
glBlock.bufferView.getInt32(offset + 8) !== glUniform.bufferView[idx + 2]) {
|
||||
gl.uniform3iv(glUniform.glLoc, <Int32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
@@ -1550,11 +1576,11 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 4*m;
|
||||
let idx = 4 * m;
|
||||
if (glBlock.bufferView.getInt32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getInt32(offset+4) !== glUniform.bufferView[idx+1] ||
|
||||
glBlock.bufferView.getInt32(offset+8) !== glUniform.bufferView[idx+2] ||
|
||||
glBlock.bufferView.getInt32(offset+12) !== glUniform.bufferView[idx+3]) {
|
||||
glBlock.bufferView.getInt32(offset + 4) !== glUniform.bufferView[idx + 1] ||
|
||||
glBlock.bufferView.getInt32(offset + 8) !== glUniform.bufferView[idx + 2] ||
|
||||
glBlock.bufferView.getInt32(offset + 12) !== glUniform.bufferView[idx + 3]) {
|
||||
gl.uniform4iv(glUniform.glLoc, <Int32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
@@ -1578,9 +1604,9 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 2*m;
|
||||
let idx = 2 * m;
|
||||
if (glBlock.bufferView.getFloat32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getFloat32(offset+4) !== glUniform.bufferView[idx+1]) {
|
||||
glBlock.bufferView.getFloat32(offset + 4) !== glUniform.bufferView[idx + 1]) {
|
||||
gl.uniform2fv(glUniform.glLoc, <Float32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
@@ -1591,10 +1617,10 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
case WebGLRenderingContext.FLOAT_VEC3: {
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 3*m;
|
||||
let idx = 3 * m;
|
||||
if (glBlock.bufferView.getFloat32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getFloat32(offset+4) !== glUniform.bufferView[idx+1] ||
|
||||
glBlock.bufferView.getFloat32(offset+8) !== glUniform.bufferView[idx+2]) {
|
||||
glBlock.bufferView.getFloat32(offset + 4) !== glUniform.bufferView[idx + 1] ||
|
||||
glBlock.bufferView.getFloat32(offset + 8) !== glUniform.bufferView[idx + 2]) {
|
||||
gl.uniform3fv(glUniform.glLoc, <Float32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
@@ -1605,11 +1631,11 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
case WebGLRenderingContext.FLOAT_VEC4: {
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 4*m;
|
||||
let idx = 4 * m;
|
||||
if (glBlock.bufferView.getFloat32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getFloat32(offset+4) !== glUniform.bufferView[idx+1] ||
|
||||
glBlock.bufferView.getFloat32(offset+8) !== glUniform.bufferView[idx+2] ||
|
||||
glBlock.bufferView.getFloat32(offset+12) !== glUniform.bufferView[idx+3]) {
|
||||
glBlock.bufferView.getFloat32(offset + 4) !== glUniform.bufferView[idx + 1] ||
|
||||
glBlock.bufferView.getFloat32(offset + 8) !== glUniform.bufferView[idx + 2] ||
|
||||
glBlock.bufferView.getFloat32(offset + 12) !== glUniform.bufferView[idx + 3]) {
|
||||
gl.uniform4fv(glUniform.glLoc, <Float32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
@@ -1620,11 +1646,11 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
case WebGLRenderingContext.FLOAT_MAT2: {
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 4*m;
|
||||
let idx = 4 * m;
|
||||
if (glBlock.bufferView.getFloat32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getFloat32(offset+4) !== glUniform.bufferView[idx+1] ||
|
||||
glBlock.bufferView.getFloat32(offset+8) !== glUniform.bufferView[idx+2] ||
|
||||
glBlock.bufferView.getFloat32(offset+12) !== glUniform.bufferView[idx+3]) {
|
||||
glBlock.bufferView.getFloat32(offset + 4) !== glUniform.bufferView[idx + 1] ||
|
||||
glBlock.bufferView.getFloat32(offset + 8) !== glUniform.bufferView[idx + 2] ||
|
||||
glBlock.bufferView.getFloat32(offset + 12) !== glUniform.bufferView[idx + 3]) {
|
||||
gl.uniformMatrix2fv(glUniform.glLoc, false, <Float32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
@@ -1635,16 +1661,16 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
case WebGLRenderingContext.FLOAT_MAT3: {
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 9*m;
|
||||
let idx = 9 * m;
|
||||
if (glBlock.bufferView.getFloat32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getFloat32(offset+4) !== glUniform.bufferView[idx+1] ||
|
||||
glBlock.bufferView.getFloat32(offset+8) !== glUniform.bufferView[idx+2] ||
|
||||
glBlock.bufferView.getFloat32(offset+12) !== glUniform.bufferView[idx+3] ||
|
||||
glBlock.bufferView.getFloat32(offset+16) !== glUniform.bufferView[idx+4] ||
|
||||
glBlock.bufferView.getFloat32(offset+20) !== glUniform.bufferView[idx+5] ||
|
||||
glBlock.bufferView.getFloat32(offset+24) !== glUniform.bufferView[idx+6] ||
|
||||
glBlock.bufferView.getFloat32(offset+28) !== glUniform.bufferView[idx+7] ||
|
||||
glBlock.bufferView.getFloat32(offset+32) !== glUniform.bufferView[idx+8]) {
|
||||
glBlock.bufferView.getFloat32(offset + 4) !== glUniform.bufferView[idx + 1] ||
|
||||
glBlock.bufferView.getFloat32(offset + 8) !== glUniform.bufferView[idx + 2] ||
|
||||
glBlock.bufferView.getFloat32(offset + 12) !== glUniform.bufferView[idx + 3] ||
|
||||
glBlock.bufferView.getFloat32(offset + 16) !== glUniform.bufferView[idx + 4] ||
|
||||
glBlock.bufferView.getFloat32(offset + 20) !== glUniform.bufferView[idx + 5] ||
|
||||
glBlock.bufferView.getFloat32(offset + 24) !== glUniform.bufferView[idx + 6] ||
|
||||
glBlock.bufferView.getFloat32(offset + 28) !== glUniform.bufferView[idx + 7] ||
|
||||
glBlock.bufferView.getFloat32(offset + 32) !== glUniform.bufferView[idx + 8]) {
|
||||
gl.uniformMatrix3fv(glUniform.glLoc, false, <Float32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
@@ -1655,23 +1681,23 @@ export function WebGLCmdFuncExecuteCmds(device: WebGLGFXDevice, cmdPackage: WebG
|
||||
case WebGLRenderingContext.FLOAT_MAT4: {
|
||||
let offset = glUniform.offset;
|
||||
for (let m = 0; m < glUniform.count; ++m) {
|
||||
let idx = 16*m;
|
||||
let idx = 16 * m;
|
||||
if (glBlock.bufferView.getFloat32(offset) !== glUniform.bufferView[idx] ||
|
||||
glBlock.bufferView.getFloat32(offset+4) !== glUniform.bufferView[idx+1] ||
|
||||
glBlock.bufferView.getFloat32(offset+8) !== glUniform.bufferView[idx+2] ||
|
||||
glBlock.bufferView.getFloat32(offset+12) !== glUniform.bufferView[idx+3] ||
|
||||
glBlock.bufferView.getFloat32(offset+16) !== glUniform.bufferView[idx+4] ||
|
||||
glBlock.bufferView.getFloat32(offset+20) !== glUniform.bufferView[idx+5] ||
|
||||
glBlock.bufferView.getFloat32(offset+24) !== glUniform.bufferView[idx+6] ||
|
||||
glBlock.bufferView.getFloat32(offset+28) !== glUniform.bufferView[idx+7] ||
|
||||
glBlock.bufferView.getFloat32(offset+32) !== glUniform.bufferView[idx+8] ||
|
||||
glBlock.bufferView.getFloat32(offset+36) !== glUniform.bufferView[idx+9] ||
|
||||
glBlock.bufferView.getFloat32(offset+40) !== glUniform.bufferView[idx+10] ||
|
||||
glBlock.bufferView.getFloat32(offset+44) !== glUniform.bufferView[idx+11] ||
|
||||
glBlock.bufferView.getFloat32(offset+48) !== glUniform.bufferView[idx+12] ||
|
||||
glBlock.bufferView.getFloat32(offset+52) !== glUniform.bufferView[idx+13] ||
|
||||
glBlock.bufferView.getFloat32(offset+56) !== glUniform.bufferView[idx+14] ||
|
||||
glBlock.bufferView.getFloat32(offset+60) !== glUniform.bufferView[idx+15]) {
|
||||
glBlock.bufferView.getFloat32(offset + 4) !== glUniform.bufferView[idx + 1] ||
|
||||
glBlock.bufferView.getFloat32(offset + 8) !== glUniform.bufferView[idx + 2] ||
|
||||
glBlock.bufferView.getFloat32(offset + 12) !== glUniform.bufferView[idx + 3] ||
|
||||
glBlock.bufferView.getFloat32(offset + 16) !== glUniform.bufferView[idx + 4] ||
|
||||
glBlock.bufferView.getFloat32(offset + 20) !== glUniform.bufferView[idx + 5] ||
|
||||
glBlock.bufferView.getFloat32(offset + 24) !== glUniform.bufferView[idx + 6] ||
|
||||
glBlock.bufferView.getFloat32(offset + 28) !== glUniform.bufferView[idx + 7] ||
|
||||
glBlock.bufferView.getFloat32(offset + 32) !== glUniform.bufferView[idx + 8] ||
|
||||
glBlock.bufferView.getFloat32(offset + 36) !== glUniform.bufferView[idx + 9] ||
|
||||
glBlock.bufferView.getFloat32(offset + 40) !== glUniform.bufferView[idx + 10] ||
|
||||
glBlock.bufferView.getFloat32(offset + 44) !== glUniform.bufferView[idx + 11] ||
|
||||
glBlock.bufferView.getFloat32(offset + 48) !== glUniform.bufferView[idx + 12] ||
|
||||
glBlock.bufferView.getFloat32(offset + 52) !== glUniform.bufferView[idx + 13] ||
|
||||
glBlock.bufferView.getFloat32(offset + 56) !== glUniform.bufferView[idx + 14] ||
|
||||
glBlock.bufferView.getFloat32(offset + 60) !== glUniform.bufferView[idx + 15]) {
|
||||
gl.uniformMatrix4fv(glUniform.glLoc, false, <Float32Array>glUniform.bufferView);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
import { GFXDeviceInfo, GFXDevice } from '../device';
|
||||
import { GFXBuffer, GFXBufferInfo, GFXBufferUsageBit } from '../buffer';
|
||||
import { GFXBuffer, GFXBufferInfo } from '../buffer';
|
||||
import { WebGLGFXBuffer } from './webgl-buffer';
|
||||
import { WebGLGFXQueue } from './webgl-queue';
|
||||
import { WebGLStateCache } from './webgl-state-cache';
|
||||
import { WebGLGPUBuffer, WebGLGPUObjectType, WebGLGPUTexture, WebGLGPURenderPass, WebGLGPUFramebuffer, WebGLGPUTextureView, WebGLGPUShader, WebGLGPUShaderStage, WebGLGPUSampler, WebGLGPUInputAssembler, WebGLGPUPipelineState, WebGLGPUPipelineLayout, WebGLGPUBindingLayout as WebGLGPUBindingLayout, WebGLGPUBinding } from './webgl-gpu-objects';
|
||||
import { WebGLCmdFuncUpdateBuffer, WebGLCmdFuncDestroyBuffer, WebGLCmdFuncCreateBuffer, WebGLCmdFuncDestroyTexture, WebGLCmdFuncCreateTexture, WebGLCmdFuncCreateFramebuffer, WebGLCmdFuncDestroyFramebuffer, WebGLCmdFuncCreateShader, WebGLCmdFuncDestroyShader, WebGLCmdFuncCreateInputAssember } from './webgl-commands';
|
||||
import { GFXTextureInfo, GFXTextureType, GFXTextureFlagBit, GFXTexture } from '../texture';
|
||||
import { GFXTextureViewType, GFXTextureViewInfo, GFXTextureView } from '../texture-view';
|
||||
import { GFXTexture, GFXTextureInfo } from '../texture';
|
||||
import { GFXTextureViewInfo, GFXTextureView } from '../texture-view';
|
||||
import { GFXRenderPassInfo, GFXRenderPass } from '../render-pass';
|
||||
import { GFXFramebufferInfo, GFXFramebuffer } from '../framebuffer';
|
||||
import { WebGLGFXRenderPass } from './webgl-render-pass';
|
||||
import { WebGLGFXTextureView } from './webgl-texture-view';
|
||||
import { WebGLGFXTexture } from './webgl-texture';
|
||||
import { GFXShaderInfo, GFXShader } from '../shader';
|
||||
import { GFXSamplerInfo, GFXFilter, GFXSampler, GFXAddress } from '../sampler';
|
||||
import { GFXShader, GFXShaderInfo } from '../shader';
|
||||
import { GFXSamplerInfo, GFXSampler } from '../sampler';
|
||||
import { WebGLGFXCommandAllocator } from './webgl-command-allocator';
|
||||
import { GFXInputAssemblerInfo, GFXInputAssembler } from '../input-assembler';
|
||||
import { WebGLGFXShader } from './webgl-shader';
|
||||
import { GFXCommandAllocator, GFXCommandAllocatorInfo } from '../command-allocator';
|
||||
import { GFXPipelineStateInfo, GFXPipelineState } from '../pipeline-state';
|
||||
import { WebGLGFXPipelineLayout } from './webgl-pipeline-layout';
|
||||
import { GFXBindingLayoutInfo, GFXBindingUnit, GFXBindingType, GFXBindingLayout } from '../binding-layout';
|
||||
import { GFXBindingUnit, GFXBindingLayout, GFXBindingLayoutInfo } from '../binding-layout';
|
||||
import { WebGLGFXSampler } from './webgl-sampler';
|
||||
import { GFXCommandBufferInfo, GFXCommandBuffer } from '../command-buffer';
|
||||
import { GFXQueueInfo, GFXQueue } from '../queue';
|
||||
import { WebGLGFXCommandBuffer } from './webgl-command-buffer';
|
||||
import { WebGLGFXPipelineState } from './webgl-pipeline-state';
|
||||
import { GFXPipelineLayoutInfo, GFXPipelineLayout } from '../pipeline-layout';
|
||||
import { GFXPipelineLayout, GFXPipelineLayoutInfo } from '../pipeline-layout';
|
||||
import { WebGLGFXFramebuffer } from './webgl-framebuffer';
|
||||
import { WebGLGFXInputAssembler } from './webgl-input-assembler';
|
||||
import { GFXWindowInfo, GFXWindow } from '../window';
|
||||
import { GFXWindow, GFXWindowInfo } from '../window';
|
||||
import { WebGLGFXWindow } from './webgl-window';
|
||||
import { BufferView } from '../define';
|
||||
import { GFXBindingType, GFXFilter, GFXAddress, GFXTextureType, GFXTextureFlagBit, GFXTextureViewType, GFXBufferUsageBit } from '../gfx-define';
|
||||
import { WebGLGFXBindingLayout } from './webgl-binding-layout';
|
||||
|
||||
const WebGLPrimitives: GLenum[] = [
|
||||
@@ -61,12 +61,9 @@ const WebGLWraps: GLenum[] = [
|
||||
export class WebGLGFXDevice extends GFXDevice {
|
||||
|
||||
stateCache: WebGLStateCache = new WebGLStateCache;
|
||||
//webGLCmdAllocator: WebGLGFXCommandAllocator;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
//this.webGLCmdAllocator = new WebGLGFXCommandAllocator(this);
|
||||
}
|
||||
|
||||
public initialize(info: GFXDeviceInfo): boolean {
|
||||
@@ -157,6 +154,8 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
height: this._webGLRC.drawingBufferHeight,
|
||||
});
|
||||
|
||||
this._cmdAllocator = this.createCommandAllocator({});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -167,6 +166,11 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
this._mainWindow = null;
|
||||
}
|
||||
|
||||
if (this._cmdAllocator) {
|
||||
this._cmdAllocator.destroy();
|
||||
this._cmdAllocator = null;
|
||||
}
|
||||
|
||||
this._webGLRC = null;
|
||||
}
|
||||
|
||||
@@ -331,7 +335,7 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
return <WebGLGFXQueue>this._queue;
|
||||
}
|
||||
|
||||
public emitCmdCreateGPUBuffer(info: GFXBufferInfo, buffer: BufferView | null): WebGLGPUBuffer | null {
|
||||
public emitCmdCreateGPUBuffer(info: GFXBufferInfo, buffer: ArrayBuffer | null): WebGLGPUBuffer | null {
|
||||
|
||||
let gpuBuffer: WebGLGPUBuffer = {
|
||||
objType: WebGLGPUObjectType.BUFFER,
|
||||
@@ -346,8 +350,8 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
};
|
||||
|
||||
if (buffer) {
|
||||
gpuBuffer.buffer = buffer.buffer;
|
||||
gpuBuffer.bufferView = buffer;
|
||||
gpuBuffer.buffer = buffer;
|
||||
gpuBuffer.bufferView = new Uint8Array(gpuBuffer.buffer);
|
||||
}
|
||||
|
||||
//let isUBOSimulate = (gpuBuffer.usage & GFXBufferUsageBit.UNIFORM) !== GFXBufferUsageBit.NONE;
|
||||
@@ -365,7 +369,7 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
WebGLCmdFuncDestroyBuffer(<WebGLGFXDevice>this, gpuBuffer);
|
||||
}
|
||||
|
||||
public emitCmdUpdateGPUBuffer(gpuBuffer: WebGLGPUBuffer, offset: number, buffer: BufferView) {
|
||||
public emitCmdUpdateGPUBuffer(gpuBuffer: WebGLGPUBuffer, offset: number, buffer: ArrayBuffer) {
|
||||
// TODO: Async
|
||||
let isUBOSimulate = (gpuBuffer.usage & GFXBufferUsageBit.UNIFORM) !== GFXBufferUsageBit.NONE;
|
||||
let isStagingBuffer = (gpuBuffer.usage & GFXBufferUsageBit.TRANSFER_SRC) !== GFXBufferUsageBit.NONE;
|
||||
@@ -472,8 +476,8 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
public emitCmdCreateGPURenderPass(info: GFXRenderPassInfo): WebGLGPURenderPass {
|
||||
let gpuRenderPass: WebGLGPURenderPass = {
|
||||
objType: WebGLGPUObjectType.RENDER_PASS,
|
||||
colorAttachments: info.colorAttachment,
|
||||
depthStencilAttachment: info.depthStencilAttachment,
|
||||
colorAttachments: info.colorAttachment? info.colorAttachment : [],
|
||||
depthStencilAttachment: info.depthStencilAttachment? info.depthStencilAttachment : null,
|
||||
}
|
||||
|
||||
return gpuRenderPass;
|
||||
@@ -578,13 +582,12 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
|
||||
for (let i = 0; i < info.stages.length; ++i) {
|
||||
let stage = info.stages[i];
|
||||
let gpuStage = gpuStages[i];
|
||||
gpuStage.type = stage.type;
|
||||
gpuStage.source = stage.source;
|
||||
|
||||
if (stage.macros) {
|
||||
gpuStage.macros = stage.macros;
|
||||
}
|
||||
gpuStages[i] = {
|
||||
type: stage.type,
|
||||
source: stage.source,
|
||||
macros: stage.macros? stage.macros : [],
|
||||
glShader: 0,
|
||||
};
|
||||
}
|
||||
|
||||
let gpuShader: WebGLGPUShader = {
|
||||
@@ -704,12 +707,6 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
|
||||
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) {
|
||||
@@ -739,7 +736,6 @@ export class WebGLGFXDevice extends GFXDevice {
|
||||
let gpuInputAssembler: WebGLGPUInputAssembler = {
|
||||
objType: WebGLGPUObjectType.INPUT_ASSEMBLER,
|
||||
attributes: info.attributes,
|
||||
gpuShader: gpuShader,
|
||||
gpuVertexBuffers: gpuVertexBuffers,
|
||||
gpuIndexBuffer: gpuIndexBuffer,
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ export class WebGLGFXFramebuffer extends GFXFramebuffer {
|
||||
|
||||
public initialize(info : GFXFramebufferInfo) : boolean {
|
||||
|
||||
this._renderPass = info.renderPass;
|
||||
|
||||
if(info.colorViews) {
|
||||
this._colorViews = info.colorViews;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import { GFXBufferUsage, GFXBufferUsageBit, GFXMemoryUsage, GFXMemoryUsageBit } from "../buffer";
|
||||
import { GFXTextureType, GFXTextureUsage, GFXTextureUsageBit, GFXTextureFlags, GFXTextureFlagBit } from "../texture";
|
||||
import { GFXTextureViewType } from "../texture-view";
|
||||
import { GFXFormat, GFXType, BufferView } from "../define";
|
||||
import { GFXFormat, GFXType, GFXTextureType, GFXTextureUsage, GFXTextureUsageBit, GFXTextureFlags, GFXTextureFlagBit, GFXShaderType, GFXBindingType, GFXTextureViewType, GFXBufferUsageBit, GFXMemoryUsageBit, GFXMemoryUsage, GFXBufferUsage } from "../gfx-define";
|
||||
import { GFXColorAttachment, GFXDepthStencilAttachment } from "../render-pass";
|
||||
import { GFXShaderType, GFXShaderMacro, GFXUniformBlock, GFXUniformSampler } from "../shader";
|
||||
import { GFXBindingType } from "../binding-layout";
|
||||
import { GFXRasterizerState, GFXDepthStencilState, GFXBlendState } from "../pipeline-state";
|
||||
import { GFXInputAttribute } from "../input-assembler";
|
||||
import { GFXUniformBlock, GFXUniformSampler, GFXShaderMacro } from "../shader";
|
||||
|
||||
export enum WebGLGPUObjectType {
|
||||
UNKNOWN,
|
||||
@@ -40,7 +36,7 @@ export class WebGLGPUBuffer extends WebGLGPUObject {
|
||||
glTarget: GLenum = 0;
|
||||
glBuffer: WebGLBuffer = 0;
|
||||
buffer: ArrayBuffer | null = null;
|
||||
bufferView: BufferView | null = null;
|
||||
bufferView: Uint8Array | null = null;
|
||||
|
||||
constructor() {
|
||||
super(WebGLGPUObjectType.BUFFER);
|
||||
@@ -245,7 +241,6 @@ export class WebGLAttrib {
|
||||
|
||||
export class WebGLGPUInputAssembler extends WebGLGPUObject {
|
||||
attributes: GFXInputAttribute[] = [];
|
||||
gpuShader: WebGLGPUShader | null = null;
|
||||
gpuVertexBuffers: WebGLGPUBuffer[] = [];
|
||||
gpuIndexBuffer: WebGLGPUBuffer | null = null;
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { GFXDevice } from '../device';
|
||||
import { GFXPipelineLayout, GFXPipelineLayoutInfo } from '../pipeline-layout';
|
||||
import { WebGLGFXDevice } from './webgl-device';
|
||||
import { WebGLGPUPipelineLayout } from './webgl-gpu-objects';
|
||||
import { GFXPipelineLayout } from '../pipeline-layout';
|
||||
import { GFXPipelineLayoutInfo } from '../binding-layout';
|
||||
|
||||
export class WebGLGFXPipelineLayout extends GFXPipelineLayout {
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export class WebGLGFXQueue extends GFXQueue {
|
||||
|
||||
}
|
||||
|
||||
public submit(cmdBuffs: GFXCommandBuffer[], fence: null = null) {
|
||||
public submit(cmdBuffs: GFXCommandBuffer[], fence?) {
|
||||
|
||||
// TODO: Async
|
||||
if (!this._isAsync) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { GFXDevice } from '../device';
|
||||
import { WebGLGPUTexture, WebGLGPURenderPass } from './webgl-gpu-objects';
|
||||
import { WebGLGPURenderPass } from './webgl-gpu-objects';
|
||||
import { WebGLGFXDevice } from './webgl-device';
|
||||
import { GFXTexture, GFXTextureInfo, GFXTextureFlagBit } from '../texture';
|
||||
import { GFXFormatSurfaceSize } from '../define';
|
||||
import { GFXRenderPass, GFXRenderPassInfo } from '../render-pass';
|
||||
|
||||
export class WebGLGFXRenderPass extends GFXRenderPass {
|
||||
@@ -13,8 +11,13 @@ export class WebGLGFXRenderPass extends GFXRenderPass {
|
||||
|
||||
public initialize(info: GFXRenderPassInfo): boolean {
|
||||
|
||||
this._colorInfos = info.colorAttachment;
|
||||
this._depthStencilInfo = info.depthStencilAttachment;
|
||||
if (info.colorAttachment) {
|
||||
this._colorInfos = info.colorAttachment;
|
||||
}
|
||||
|
||||
if (info.depthStencilAttachment) {
|
||||
this._depthStencilInfo = info.depthStencilAttachment;
|
||||
}
|
||||
|
||||
this._gpuRenderPass = this.webGLDevice.emitCmdCreateGPURenderPass(info);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GFXDevice } from '../device';
|
||||
import { GFXSampler, GFXSamplerInfo } from '../sampler';
|
||||
import { GFXSampler, GFXSamplerInfo, GFXSamplerState } from '../sampler';
|
||||
import { WebGLGFXDevice } from './webgl-device';
|
||||
import { WebGLGPUSampler } from './webgl-gpu-objects';
|
||||
|
||||
@@ -7,11 +7,64 @@ export class WebGLGFXSampler extends GFXSampler {
|
||||
|
||||
constructor(device : GFXDevice) {
|
||||
super(device);
|
||||
|
||||
this._state = new GFXSamplerState;
|
||||
}
|
||||
|
||||
public initialize(info : GFXSamplerInfo) : boolean {
|
||||
|
||||
this._state = info;
|
||||
if(info.name) {
|
||||
this._state.name = info.name;
|
||||
}
|
||||
|
||||
if(info.minFilter) {
|
||||
this._state.minFilter = info.minFilter;
|
||||
}
|
||||
|
||||
if(info.magFilter) {
|
||||
this._state.magFilter = info.magFilter;
|
||||
}
|
||||
|
||||
if(info.mipFilter) {
|
||||
this._state.mipFilter = info.mipFilter;
|
||||
}
|
||||
|
||||
if(info.addressU) {
|
||||
this._state.addressU = info.addressU;
|
||||
}
|
||||
|
||||
if(info.addressV) {
|
||||
this._state.addressV = info.addressV;
|
||||
}
|
||||
|
||||
if(info.addressW) {
|
||||
this._state.addressW = info.addressW;
|
||||
}
|
||||
|
||||
if(info.maxAnisotropy) {
|
||||
this._state.maxAnisotropy = info.maxAnisotropy;
|
||||
}
|
||||
|
||||
if(info.cmpFunc) {
|
||||
this._state.cmpFunc = info.cmpFunc;
|
||||
}
|
||||
|
||||
if(info.borderColor) {
|
||||
this._state.borderColor = info.borderColor;
|
||||
}
|
||||
|
||||
if(info.minLOD) {
|
||||
this._state.minLOD = info.minLOD;
|
||||
}
|
||||
|
||||
if(info.maxLOD) {
|
||||
this._state.maxLOD = info.maxLOD;
|
||||
}
|
||||
|
||||
if(info.mipLODBias) {
|
||||
this._state.mipLODBias = info.mipLODBias;
|
||||
}
|
||||
|
||||
this._gpuSampler = this.webGLDevice.emitCmdCreateGPUSampler(info);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -11,10 +11,7 @@ export class WebGLGFXShader extends GFXShader {
|
||||
|
||||
public initialize(info: GFXShaderInfo): boolean {
|
||||
|
||||
if (info.name) {
|
||||
this._name = info.name;
|
||||
}
|
||||
|
||||
this._name = info.name;
|
||||
this._stages = info.stages;
|
||||
this._blocks = info.blocks;
|
||||
this._samplers = info.samplers;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GFX_MAX_TEXTURE_UNITS, GFX_MAX_VERTEX_ATTRIBUTES } from "../define";
|
||||
import { GFX_MAX_TEXTURE_UNITS, GFX_MAX_VERTEX_ATTRIBUTES, GFXViewport, GFXRect } from "../gfx-define";
|
||||
import { GFXRasterizerState, GFXDepthStencilState, GFXBlendState } from "../pipeline-state";
|
||||
|
||||
export interface WebGLTexUnit
|
||||
@@ -20,8 +20,8 @@ export class WebGLStateCache {
|
||||
glTex2DUnits : WebGLTexUnit[];
|
||||
glTexCubeUnits : WebGLTexUnit[];
|
||||
glFramebuffer : WebGLFramebuffer = 0;
|
||||
viewport : number[] = [0.0, 0.0, 0.0, 0.0];
|
||||
scissorRect : number[] = [0.0, 0.0, 0.0, 0.0];
|
||||
viewport : GFXViewport;
|
||||
scissorRect : GFXRect;
|
||||
rs : GFXRasterizerState;
|
||||
dss : GFXDepthStencilState;
|
||||
bs : GFXBlendState;
|
||||
@@ -32,6 +32,8 @@ export class WebGLStateCache {
|
||||
constructor() {
|
||||
this.glTex2DUnits = new Array<WebGLTexUnit>(GFX_MAX_TEXTURE_UNITS);
|
||||
this.glTexCubeUnits = new Array<WebGLTexUnit>(GFX_MAX_TEXTURE_UNITS);
|
||||
this.viewport = { left: 0.0, top: 0.0, width: 0.0, height: 0.0, minDepth: 0.0, maxDepth: 0.0};
|
||||
this.scissorRect = { left: 0.0, top: 0.0, width: 0.0, height: 0.0};
|
||||
this.rs = new GFXRasterizerState;
|
||||
this.dss = new GFXDepthStencilState;
|
||||
this.bs = new GFXBlendState;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { GFXDevice } from '../device';
|
||||
import { WebGLGPUTexture } from './webgl-gpu-objects';
|
||||
import { WebGLGFXDevice } from './webgl-device';
|
||||
import { GFXTexture, GFXTextureInfo, GFXTextureFlagBit } from '../texture';
|
||||
import { GFXFormatSurfaceSize } from '../define';
|
||||
import { GFXTexture, GFXTextureInfo } from '../texture';
|
||||
import { GFXFormatSurfaceSize, GFXTextureFlagBit } from '../gfx-define';
|
||||
|
||||
export class WebGLGFXTexture extends GFXTexture {
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { GFXDevice } from '../device';
|
||||
import { WebGLGFXDevice } from './webgl-device';
|
||||
import { GFXWindow, GFXWindowInfo } from '../window';
|
||||
import { GFXFramebufferInfo } from '../framebuffer';
|
||||
import { GFXRenderPassInfo, GFXColorAttachment, GFXLoadOp, GFXStoreOp, GFXTextureLayout, GFXPipelineBindPoint, GFXDepthStencilAttachment } from '../render-pass';
|
||||
import { GFXTextureType, GFXTextureUsageBit, GFXTextureFlagBit } from '../texture';
|
||||
import { GFXTextureViewType } from '../texture-view';
|
||||
import { GFXFormat } from '../define';
|
||||
import { GFXFormat, GFXTextureType, GFXTextureUsageBit, GFXTextureFlagBit, GFXTextureViewType, GFXTextureLayout, GFXLoadOp, GFXStoreOp } from '../gfx-define';
|
||||
|
||||
export class WebGLGFXWindow extends GFXWindow {
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import { GFXDevice } from './device';
|
||||
import { GFXFramebuffer } from './framebuffer';
|
||||
import { GFXTexture } from './texture';
|
||||
import { GFXTextureView } from './texture-view';
|
||||
import { GFXFormat } from './define';
|
||||
import { GFXFormat } from './gfx-define';
|
||||
import { GFXRenderPass } from './render-pass';
|
||||
|
||||
export interface GFXWindowInfo {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { RenderFlow, RenderFlowInfo } from "../render-flow";
|
||||
import { GFXRenderPass } from "../../gfx/gfx-render-pass";
|
||||
import { RenderPipeline } from "../render-pipeline";
|
||||
import { TestStage } from "./test-stage";
|
||||
|
||||
export enum ForwardStagePriority {
|
||||
FORWARD = 0,
|
||||
};
|
||||
|
||||
export class ForwardFlow extends RenderFlow {
|
||||
|
||||
@@ -9,27 +13,36 @@ export class ForwardFlow extends RenderFlow {
|
||||
}
|
||||
|
||||
public initialize(info: RenderFlowInfo): boolean {
|
||||
|
||||
if(info.name) {
|
||||
|
||||
if (info.name) {
|
||||
this._name = info.name;
|
||||
}
|
||||
|
||||
this._priority = info.priority;
|
||||
|
||||
let device = this._pipeline.root.device;
|
||||
if(!device) {
|
||||
let mainWindow = this._pipeline.root.mainWindow;
|
||||
if(!mainWindow || !mainWindow.framebuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//this._pipeline.root.mainWindow;
|
||||
//this._renderPass =
|
||||
|
||||
/*
|
||||
this.createStage<ForwardStage>(ForwardStage, {
|
||||
name: "ForwardStage",
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
});
|
||||
*/
|
||||
|
||||
this.createStage<TestStage>(TestStage, {
|
||||
name: "TestStage",
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
this.destroyStages();
|
||||
}
|
||||
|
||||
private _renderPass: GFXRenderPass | null = null;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { RenderPipeline } from "../render-pipeline";
|
||||
import { Root } from "../../../core/root";
|
||||
import { RenderPipeline, RenderPassStage } from "../render-pipeline";
|
||||
import { Root } from "../../core/root";
|
||||
import { ForwardFlow } from "./forward-flow";
|
||||
import { GFXRenderPass } from "../../gfx/render-pass";
|
||||
|
||||
export enum ForwardFlowPriority {
|
||||
FORWARD = 0,
|
||||
};
|
||||
|
||||
export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
@@ -9,10 +15,37 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
public initialize(): boolean {
|
||||
|
||||
if(!this.createQuadInputAssembler()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mainWindow = this._root.mainWindow;
|
||||
let windowPass: GFXRenderPass | null = null;
|
||||
|
||||
if(mainWindow) {
|
||||
windowPass = mainWindow.renderPass;
|
||||
}
|
||||
|
||||
if(!windowPass) {
|
||||
console.error("RenderPass of main window is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.addRenderPass(RenderPassStage.FORWARD, windowPass);
|
||||
|
||||
// create flows
|
||||
|
||||
this.createFlow<ForwardFlow>(ForwardFlow, {
|
||||
name: "ForwardFlow",
|
||||
priority: ForwardFlowPriority.FORWARD,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
this.destroyFlows();
|
||||
this.clearRenderPasses();
|
||||
this.destroyQuadInputAssembler();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,16 +1,53 @@
|
||||
import { RenderStage, RenderStageInfo } from "../render-stage";
|
||||
import { RenderFlow } from "../render-flow";
|
||||
import { GFXCommandBuffer } from "../../gfx/command-buffer";
|
||||
import { RenderView } from "../render-view";
|
||||
import { GFXFramebuffer } from "../../gfx/framebuffer";
|
||||
import { GFXCommandBufferType } from "../../gfx/gfx-define";
|
||||
import { GFXInputAssembler } from "../../gfx/input-assembler";
|
||||
|
||||
export class ForwardStage extends RenderStage {
|
||||
|
||||
constructor(flow: RenderFlow) {
|
||||
super(flow);
|
||||
}
|
||||
|
||||
public initialize(info: RenderStageInfo): boolean {
|
||||
|
||||
if(info.name) {
|
||||
this._name = info.name;
|
||||
}
|
||||
|
||||
this._priority = info.priority;
|
||||
this._framebuffer = info.framebuffer;
|
||||
|
||||
this._cmdBuff = this._device.createCommandBuffer({
|
||||
allocator: this._device.commandAllocator,
|
||||
type: GFXCommandBufferType.PRIMARY,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
||||
if (this._cmdBuff) {
|
||||
this._cmdBuff.destroy();
|
||||
this._cmdBuff = null;
|
||||
}
|
||||
}
|
||||
|
||||
public render() {
|
||||
public render(view: RenderView) {
|
||||
let cmdBuff = <GFXCommandBuffer>this._cmdBuff;
|
||||
this._renderArea.width = view.width;
|
||||
this._renderArea.height = view.height;
|
||||
|
||||
cmdBuff.begin();
|
||||
cmdBuff.beginRenderPass(<GFXFramebuffer>this._framebuffer, this._renderArea, this._clearColors, this._clearDepth, this._clearStencil);
|
||||
cmdBuff.draw(<GFXInputAssembler>this._pipeline.quadIA);
|
||||
cmdBuff.endRenderPass();
|
||||
cmdBuff.end();
|
||||
|
||||
this._device.queue.submit([cmdBuff]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import { RenderStage, RenderStageInfo } from "../render-stage";
|
||||
import { RenderFlow } from "../render-flow";
|
||||
import { GFXCommandBuffer } from "../../gfx/command-buffer";
|
||||
import { RenderView } from "../render-view";
|
||||
import { GFXFramebuffer } from "../../gfx/framebuffer";
|
||||
import { GFXCommandBufferType, GFXShaderType, GFXPrimitiveMode } from "../../gfx/gfx-define";
|
||||
import { GFXInputAssembler } from "../../gfx/input-assembler";
|
||||
import { GFXPipelineState, GFXInputState, GFXRasterizerState, GFXDepthStencilState, GFXBlendState } from "../../gfx/pipeline-state";
|
||||
import { GFXShader } from "../../gfx/shader";
|
||||
import { GFXRenderPass } from "../../gfx/render-pass";
|
||||
import { GFXPipelineLayout } from "../../gfx/pipeline-layout";
|
||||
import { GFXBindingLayout } from "../../gfx/binding-layout";
|
||||
|
||||
let _shader_vs =`
|
||||
attribute vec2 a_position;
|
||||
attribute vec2 a_texCoord;
|
||||
void main() {
|
||||
gl_Position = vec4(a_position, 0.0, 1.0);
|
||||
}
|
||||
`;
|
||||
|
||||
let _shader_fs =`
|
||||
void main() {
|
||||
gl_FragColor = vec4(0.3, 0.3, 0.8, 1.0);
|
||||
}\n
|
||||
`;
|
||||
|
||||
export class TestStage extends RenderStage {
|
||||
|
||||
constructor(flow: RenderFlow) {
|
||||
super(flow);
|
||||
}
|
||||
|
||||
public initialize(info: RenderStageInfo): boolean {
|
||||
|
||||
if (info.name) {
|
||||
this._name = info.name;
|
||||
}
|
||||
|
||||
this._priority = info.priority;
|
||||
this._framebuffer = info.framebuffer;
|
||||
if (!this._framebuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._cmdBuff = this._device.createCommandBuffer({
|
||||
allocator: this._device.commandAllocator,
|
||||
type: GFXCommandBufferType.PRIMARY,
|
||||
});
|
||||
|
||||
// create shader
|
||||
let vsStage = {
|
||||
type: GFXShaderType.VERTEX,
|
||||
source: _shader_vs,
|
||||
};
|
||||
|
||||
let fsStage = {
|
||||
type: GFXShaderType.FRAGMENT,
|
||||
source: _shader_fs,
|
||||
};
|
||||
|
||||
this._shader = this._device.createShader({
|
||||
name: "test",
|
||||
stages: [vsStage, fsStage],
|
||||
});
|
||||
if (!this._shader) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._bindingLayout = this._device.createBindingLayout({
|
||||
bindings: [],
|
||||
});
|
||||
if (!this._bindingLayout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._pipelineLayout = this._device.createPipelineLayout({
|
||||
layouts: [this._bindingLayout]
|
||||
});
|
||||
if (!this._pipelineLayout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this._pipeline.quadIA) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let is: GFXInputState = { attributes: this._pipeline.quadIA.attributes };
|
||||
|
||||
this._pipelineState = this._device.createPipelineState({
|
||||
primitive: GFXPrimitiveMode.TRIANGLE_LIST,
|
||||
shader: this._shader,
|
||||
is: is,
|
||||
rs: this._rs,
|
||||
dss: this._dss,
|
||||
bs: this._bs,
|
||||
layout: this._pipelineLayout,
|
||||
renderPass: <GFXRenderPass>this._framebuffer.renderPass,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
||||
if (this._shader) {
|
||||
this._shader.destroy();
|
||||
this._shader = null;
|
||||
}
|
||||
|
||||
if (this._bindingLayout) {
|
||||
this._bindingLayout.destroy();
|
||||
this._bindingLayout = null;
|
||||
}
|
||||
|
||||
if (this._pipelineLayout) {
|
||||
this._pipelineLayout.destroy();
|
||||
this._pipelineLayout = null;
|
||||
}
|
||||
|
||||
if (this._pipelineState) {
|
||||
this._pipelineState.destroy();
|
||||
this._pipelineState = null;
|
||||
}
|
||||
|
||||
if (this._cmdBuff) {
|
||||
this._cmdBuff.destroy();
|
||||
this._cmdBuff = null;
|
||||
}
|
||||
}
|
||||
|
||||
public render(view: RenderView) {
|
||||
let cmdBuff = <GFXCommandBuffer>this._cmdBuff;
|
||||
this._renderArea.width = view.width;
|
||||
this._renderArea.height = view.height;
|
||||
|
||||
cmdBuff.begin();
|
||||
cmdBuff.beginRenderPass(<GFXFramebuffer>this._framebuffer, this._renderArea, this._clearColors, this._clearDepth, this._clearStencil);
|
||||
cmdBuff.bindBindingLayout(<GFXBindingLayout>this._bindingLayout);
|
||||
cmdBuff.bindPipelineState(<GFXPipelineState>this._pipelineState);
|
||||
cmdBuff.bindInputAssembler(<GFXInputAssembler>this._pipeline.quadIA);
|
||||
cmdBuff.draw(<GFXInputAssembler>this._pipeline.quadIA);
|
||||
cmdBuff.endRenderPass();
|
||||
cmdBuff.end();
|
||||
|
||||
this._device.queue.submit([cmdBuff]);
|
||||
}
|
||||
|
||||
private _shader: GFXShader | null = null;
|
||||
private _bindingLayout: GFXBindingLayout | null = null;
|
||||
private _pipelineLayout: GFXPipelineLayout | null = null;
|
||||
private _pipelineState: GFXPipelineState | null = null;
|
||||
private _rs: GFXRasterizerState = new GFXRasterizerState;
|
||||
private _dss: GFXDepthStencilState = new GFXDepthStencilState;
|
||||
private _bs: GFXBlendState = new GFXBlendState;
|
||||
};
|
||||
@@ -1,6 +1,8 @@
|
||||
import { RenderStage, RenderStageInfo } from "./render-stage";
|
||||
import { RenderView } from "./render-view";
|
||||
import { RenderPipeline } from "./render-pipeline";
|
||||
import { GFXRenderPass } from "../gfx/render-pass";
|
||||
import { GFXDevice } from "../gfx/device";
|
||||
|
||||
export interface RenderFlowInfo {
|
||||
name?: string;
|
||||
@@ -10,6 +12,7 @@ export interface RenderFlowInfo {
|
||||
export abstract class RenderFlow {
|
||||
|
||||
constructor(pipeline: RenderPipeline) {
|
||||
this._device = pipeline.device;
|
||||
this._pipeline = pipeline;
|
||||
}
|
||||
|
||||
@@ -47,10 +50,19 @@ export abstract class RenderFlow {
|
||||
this._stages = [];
|
||||
}
|
||||
|
||||
public get device(): GFXDevice {
|
||||
return this._device;
|
||||
}
|
||||
|
||||
public get pipeline(): RenderPipeline {
|
||||
return this._pipeline;
|
||||
}
|
||||
|
||||
public get priority(): number {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
protected _device: GFXDevice;
|
||||
protected _pipeline: RenderPipeline;
|
||||
protected _name: string = "";
|
||||
protected _priority: number = 0;
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
import { RenderView } from "./render-view";
|
||||
import { RenderFlow, RenderFlowInfo } from "./render-flow";
|
||||
import { GFXDevice } from "../gfx/gfx-device";
|
||||
import { Root } from "../../core/root";
|
||||
import { Root } from "../core/root";
|
||||
import { GFXRenderPass, GFXRenderPassInfo } from "../gfx/render-pass";
|
||||
import { GFXDevice } from "../gfx/device";
|
||||
import { GFXBuffer } from "../gfx/buffer";
|
||||
import { GFXInputAssembler, GFXInputAttribute } from "../gfx/input-assembler";
|
||||
import { GFXBufferUsageBit, GFXMemoryUsageBit, GFXVertexSemantic, GFXFormat } from "../gfx/gfx-define";
|
||||
|
||||
export enum RenderPassStage {
|
||||
FORWARD = 0,
|
||||
CUSTOM = 100,
|
||||
};
|
||||
|
||||
export interface QuadVertex {
|
||||
position: number[];
|
||||
texCoord: number[];
|
||||
}
|
||||
|
||||
export abstract class RenderPipeline {
|
||||
|
||||
constructor(root: Root) {
|
||||
this._root = root;
|
||||
this._device = root.device;
|
||||
}
|
||||
|
||||
public abstract initialize(): boolean;
|
||||
@@ -19,7 +34,29 @@ export abstract class RenderPipeline {
|
||||
}
|
||||
|
||||
public resize(width, height) {
|
||||
}
|
||||
|
||||
public addRenderPass(stage: number, renderPass: GFXRenderPass) {
|
||||
if (renderPass) {
|
||||
this._renderPasses.set(stage, renderPass);
|
||||
}
|
||||
}
|
||||
|
||||
public getRenderPass(stage: number): GFXRenderPass | null {
|
||||
let renderPass = this._renderPasses.get(stage);
|
||||
if (renderPass) {
|
||||
return renderPass;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public removeRenderPass(stage: number) {
|
||||
this._renderPasses.delete(stage);
|
||||
}
|
||||
|
||||
public clearRenderPasses() {
|
||||
this._renderPasses.clear();
|
||||
}
|
||||
|
||||
public createFlow<T extends RenderFlow>(clazz: new (pipeline: RenderPipeline) => T, info: RenderFlowInfo): RenderFlow | null {
|
||||
@@ -47,10 +84,104 @@ export abstract class RenderPipeline {
|
||||
return this._root;
|
||||
}
|
||||
|
||||
public get device(): GFXDevice {
|
||||
return this._device;
|
||||
}
|
||||
|
||||
public get flows(): RenderFlow[] {
|
||||
return this._flows;
|
||||
}
|
||||
|
||||
public get quadIA(): GFXInputAssembler | null {
|
||||
return this._quadIA;
|
||||
}
|
||||
|
||||
protected createQuadInputAssembler(): boolean {
|
||||
|
||||
// create vertex buffer
|
||||
|
||||
let vbStride = Float32Array.BYTES_PER_ELEMENT * 4;
|
||||
let vbSize = vbStride * 4;
|
||||
|
||||
this._quadVB = this._device.createBuffer({
|
||||
usage: GFXBufferUsageBit.VERTEX,
|
||||
memUsage: GFXMemoryUsageBit.HOST | GFXMemoryUsageBit.DEVICE,
|
||||
size: vbSize,
|
||||
stride: vbStride,
|
||||
});
|
||||
|
||||
if(!this._quadVB) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let verts = new Float32Array(4 * 4);
|
||||
let n = 0;
|
||||
verts[n++] = -1.0; verts[n++] = -1.0; verts[n++] = 0.0; verts[n++] = 0.0;
|
||||
verts[n++] = 1.0; verts[n++] = -1.0; verts[n++] = 1.0; verts[n++] = 0.0;
|
||||
verts[n++] = -1.0; verts[n++] = 1.0; verts[n++] = 0.0; verts[n++] = 1.0;
|
||||
verts[n++] = 1.0; verts[n++] = 1.0; verts[n++] = 1.0; verts[n++] = 1.0;
|
||||
|
||||
this._quadVB.update(verts);
|
||||
|
||||
// create index buffer
|
||||
let ibStride = Uint8Array.BYTES_PER_ELEMENT;
|
||||
let ibSize = ibStride * 6;
|
||||
|
||||
this._quadIB = this._device.createBuffer({
|
||||
usage: GFXBufferUsageBit.INDEX,
|
||||
memUsage: GFXMemoryUsageBit.HOST | GFXMemoryUsageBit.DEVICE,
|
||||
size: ibSize,
|
||||
stride: ibStride,
|
||||
});
|
||||
|
||||
if(!this._quadIB) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let indices = new Uint8Array(6);
|
||||
indices[0] = 0; indices[1] = 1; indices[2] = 2;
|
||||
indices[3] = 1; indices[4] = 3; indices[5] = 2;
|
||||
|
||||
this._quadIB.update(indices);
|
||||
|
||||
// create input assembler
|
||||
|
||||
let attributes: GFXInputAttribute[] = [
|
||||
{name: "a_position", semantic: GFXVertexSemantic.POSITION, format: GFXFormat.RG32F},
|
||||
{name: "a_texCoord", semantic: GFXVertexSemantic.TEXCOORD, format: GFXFormat.RG32F},
|
||||
];
|
||||
|
||||
this._quadIA = this._device.createInputAssembler({
|
||||
attributes,
|
||||
vertexBuffers: [this._quadVB],
|
||||
indexBuffer: this._quadIB,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected destroyQuadInputAssembler() {
|
||||
if(this._quadVB) {
|
||||
this._quadVB.destroy();
|
||||
this._quadVB = null;
|
||||
}
|
||||
|
||||
if(this._quadIB) {
|
||||
this._quadIB.destroy();
|
||||
this._quadIB = null;
|
||||
}
|
||||
|
||||
if(this._quadIA) {
|
||||
this._quadIA.destroy();
|
||||
this._quadIA = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected _root: Root;
|
||||
protected _device: GFXDevice;
|
||||
protected _renderPasses: Map<number, GFXRenderPass> = new Map;
|
||||
protected _flows: RenderFlow[] = [];
|
||||
protected _quadVB: GFXBuffer | null = null;
|
||||
protected _quadIB: GFXBuffer | null = null;
|
||||
protected _quadIA: GFXInputAssembler | null = null;
|
||||
};
|
||||
|
||||
@@ -1,28 +1,90 @@
|
||||
import { RenderView } from "./render-view";
|
||||
import { GFXRenderPass } from "../../gfx/render-pass";
|
||||
import { GFXFramebuffer } from "../../gfx/framebuffer";
|
||||
import { GFXRenderPass } from "../gfx/render-pass";
|
||||
import { GFXFramebuffer } from "../gfx/framebuffer";
|
||||
import { GFXCommandBuffer } from "../gfx/command-buffer";
|
||||
import { RenderFlow } from "./render-flow";
|
||||
import { GFXDevice } from "../gfx/device";
|
||||
import { RenderPipeline } from "./render-pipeline";
|
||||
import { GFXColor, GFX_MAX_ATTACHMENTS, GFXRect } from "../gfx/gfx-define";
|
||||
|
||||
export interface RenderStageInfo {
|
||||
name?: string;
|
||||
priority: number;
|
||||
renderPass: GFXRenderPass;
|
||||
framebuffer: GFXFramebuffer;
|
||||
};
|
||||
|
||||
export abstract class RenderStage {
|
||||
|
||||
constructor(flow: RenderFlow) {
|
||||
this._flow = flow;
|
||||
this._pipeline = flow.pipeline;
|
||||
this._device = flow.device;
|
||||
|
||||
if (!this._flow.pipeline.root.device) {
|
||||
throw new Error("");
|
||||
}
|
||||
|
||||
this._device = this._flow.pipeline.root.device;
|
||||
|
||||
this._clearColors = new Array<GFXColor>(GFX_MAX_ATTACHMENTS);
|
||||
for (let i = 0; i < GFX_MAX_ATTACHMENTS; ++i) {
|
||||
this._clearColors[i] = { r: 0.0, g: 0.0, b: 0.0, a: 1.0 };
|
||||
}
|
||||
|
||||
this._renderArea = {left: 0, top: 0, width: 0, height: 0};
|
||||
}
|
||||
|
||||
public abstract initialize(info: RenderStageInfo): boolean;
|
||||
public abstract destroy();
|
||||
public abstract render(view: RenderView);
|
||||
|
||||
public resize(width, height) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public setClearColor(idx: number, color: GFXColor) {
|
||||
console.assert(idx < GFX_MAX_ATTACHMENTS);
|
||||
this._clearColors[idx] = color;
|
||||
}
|
||||
|
||||
public setClearDepth(depth: number) {
|
||||
this._clearDepth = depth;
|
||||
}
|
||||
|
||||
public setClearStencil(stencil: number) {
|
||||
this._clearStencil = stencil;
|
||||
}
|
||||
|
||||
public setRenderArea(width: number, height: number) {
|
||||
this._renderArea.width = width;
|
||||
this._renderArea.height = height;
|
||||
}
|
||||
|
||||
public get flow(): RenderFlow {
|
||||
return this._flow;
|
||||
}
|
||||
|
||||
public get pipeline(): RenderPipeline {
|
||||
return this._pipeline;
|
||||
}
|
||||
|
||||
public get priority(): number {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
public get framebuffer(): GFXFramebuffer | null {
|
||||
return this._framebuffer;
|
||||
}
|
||||
|
||||
protected _flow: RenderFlow;
|
||||
protected _pipeline: RenderPipeline;
|
||||
protected _device: GFXDevice;
|
||||
protected _name: string = "";
|
||||
protected _priority: number = 0;
|
||||
protected _framebuffer: GFXFramebuffer | null = null;
|
||||
protected _cmdBuff: GFXCommandBuffer | null = null;
|
||||
protected _clearColors: GFXColor[];
|
||||
protected _clearDepth: number = 1.0;
|
||||
protected _clearStencil: number = 0;
|
||||
protected _renderArea: GFXRect;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Scene } from "../scene/scene";
|
||||
import { Camera } from "../scene/camera";
|
||||
import { GFXWindow } from "../gfx/gfx-window";
|
||||
import { Scene } from "../renderer/scene/scene";
|
||||
import { Camera } from "../renderer/scene/camera";
|
||||
import { GFXWindow } from "../gfx/window";
|
||||
|
||||
export interface RenderViewInfo {
|
||||
window: GFXWindow;
|
||||
|
||||
@@ -5,8 +5,9 @@ import { GFXBuffer } from '../../gfx/buffer';
|
||||
import { GFXSampler } from '../../gfx/sampler';
|
||||
import { GFXDevice } from '../../gfx/device';
|
||||
import { GFXDepthStencilAttachment, GFXColorAttachment } from '../../gfx/render-pass';
|
||||
import { GFXPipelineState, GFXPrimitiveMode, GFXRasterizerState, GFXDepthStencilState, GFXBlendState, GFXInputState } from '../../gfx/pipeline-state';
|
||||
import { GFXPipelineState, GFXRasterizerState, GFXDepthStencilState, GFXBlendState, GFXInputState } from '../../gfx/pipeline-state';
|
||||
import { GFXBindingLayoutInfo } from '../../gfx/binding-layout';
|
||||
import { GFXPrimitiveMode } from '../../gfx/gfx-define';
|
||||
|
||||
interface PassInfo {
|
||||
programName?: string;
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import { RenderPipeline } from "../../../pipeline/render-pipeline";
|
||||
import { RenderFlow, RenderFlowInfo } from "../../../pipeline/render-flow";
|
||||
import { GFXRenderPass } from "../../../gfx/render-pass";
|
||||
|
||||
export class ForwardFlow extends RenderFlow {
|
||||
|
||||
constructor(pipeline: RenderPipeline) {
|
||||
super(pipeline);
|
||||
}
|
||||
|
||||
public initialize(info: RenderFlowInfo): boolean {
|
||||
|
||||
if(info.name) {
|
||||
this._name = info.name;
|
||||
}
|
||||
|
||||
this._priority = info.priority;
|
||||
|
||||
let device = this._pipeline.root.device;
|
||||
if(!device) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//this._pipeline.root.mainWindow;
|
||||
//this._renderPass =
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
this.destroyStages();
|
||||
}
|
||||
|
||||
private _renderPass: GFXRenderPass | null = null;
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Root } from "../../../core/root";
|
||||
import { RenderPipeline } from "../../../pipeline/render-pipeline";
|
||||
|
||||
export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
constructor(root: Root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
public initialize(): boolean {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy(): void {
|
||||
this.destroyFlows();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user