add some gfx features

This commit is contained in:
jerrywwl
2019-02-25 14:28:47 +08:00
parent 47c5fd0891
commit 8fd9921276
5 changed files with 83 additions and 4 deletions
+2
View File
@@ -24,6 +24,8 @@ export enum GFXAPI {
export enum GFXFeature {
TEXTURE_FLOAT,
TEXTURE_HALF_FLOAT,
FORMAT_R11G11B10F,
FORMAT_D24S8,
COUNT,
}
+4
View File
@@ -305,6 +305,10 @@ export class WebGLGFXDevice extends GFXDevice {
this._features[GFXFeature.TEXTURE_HALF_FLOAT] = true;
}
if (this._WEBGL_depth_texture) {
this._features[GFXFeature.FORMAT_D24S8] = true;
}
// init states
this.initStates(gl);
+2
View File
@@ -225,6 +225,8 @@ export class WebGL2GFXDevice extends GFXDevice {
this._features.fill(false);
this._features[GFXFeature.TEXTURE_FLOAT] = true;
this._features[GFXFeature.TEXTURE_HALF_FLOAT] = true;
this._features[GFXFeature.FORMAT_R11G11B10F] = true;
this._features[GFXFeature.FORMAT_D24S8] = true;
// init states
this.initStates(gl);
@@ -61,6 +61,10 @@ export class ForwardPipeline extends RenderPipeline {
public initialize (): boolean {
if (!this.createShadingTarget()) {
return false;
}
if (!this.createQuadInputAssembler()) {
return false;
}
+71 -4
View File
@@ -3,8 +3,8 @@ import { Root } from '../core/root';
import { Mat4 } from '../core/value-types';
import { mat4, vec3 } from '../core/vmath';
import { GFXBuffer } from '../gfx/buffer';
import { GFXBufferUsageBit, GFXFormat, GFXMemoryUsageBit, GFXType } from '../gfx/define';
import { GFXDevice } from '../gfx/device';
import { GFXBufferUsageBit, GFXFormat, GFXMemoryUsageBit, GFXType, GFXLoadOp, GFXStoreOp, GFXTextureLayout, GFXFormatInfos } from '../gfx/define';
import { GFXDevice, GFXFeature, GFXAPI } from '../gfx/device';
import { GFXInputAssembler, IGFXInputAttribute } from '../gfx/input-assembler';
import { GFXRenderPass } from '../gfx/render-pass';
import { GFXUniformBlock } from '../gfx/shader';
@@ -13,6 +13,7 @@ import { GFXTextureView } from '../gfx/texture-view';
import { IRenderFlowInfo, RenderFlow } from './render-flow';
import { RenderQueue } from './render-queue';
import { RenderView } from './render-view';
import { GFXFramebuffer } from '../gfx/framebuffer';
export class UBOGlobal {
public static TIME_OFFSET: number = 0;
@@ -50,8 +51,8 @@ export class UBOGlobal {
export class UBOLocal {
public static MAT_WORLD_OFFSET: number = 0;
public static MAT_WORLD_IT_OFFSET: number = UBOLocal.MAT_WORLD_OFFSET + 16;
public static COUNT: number = UBOLocal.MAT_WORLD_IT_OFFSET + 16;
public static MAT_WORLD_IT_OFFSET: number = 16;
public static COUNT: number = 32;
public static SIZE: number = UBOLocal.COUNT * 4;
public static BLOCK: GFXUniformBlock = {
@@ -86,6 +87,14 @@ export abstract class RenderPipeline {
return this._flows;
}
public get shadingTex (): GFXTexture {
return this._shadingTex!;
}
public get shadingTexView (): GFXTextureView {
return this._shadingTexView!;
}
public get quadIA (): GFXInputAssembler {
return this._quadIA!;
}
@@ -107,6 +116,11 @@ export abstract class RenderPipeline {
protected _queue: RenderQueue = new RenderQueue();
protected _renderPasses: Map<number, GFXRenderPass> = new Map();
protected _flows: RenderFlow[] = [];
protected _isHDR: boolean = false;
protected _shadingPass: GFXRenderPass | null = null;
protected _shadingTex: GFXTexture | null = null;
protected _shadingTexView: GFXTextureView | null = null;
protected _shadingFBO: GFXFramebuffer | null = null;
protected _quadVB: GFXBuffer | null = null;
protected _quadIB: GFXBuffer | null = null;
protected _quadIA: GFXInputAssembler | null = null;
@@ -189,6 +203,59 @@ export abstract class RenderPipeline {
this._flows = [];
}
protected createShadingTarget (): boolean {
let colorFmt: GFXFormat;
let depthFmt: GFXFormat;
// Try to use HDR format
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F)) {
colorFmt = GFXFormat.R11G11B10F;
this._isHDR = true;
} else if (this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT)) {
colorFmt = GFXFormat.RGB16F;
this._isHDR = true;
} else if (this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
colorFmt = GFXFormat.RGB32F;
this._isHDR = true;
} else { // Fallback to LDR
colorFmt = GFXFormat.RGBA8;
this._isHDR = false;
}
if (this._device.hasFeature(GFXFeature.FORMAT_D24S8)) {
depthFmt = GFXFormat.D24S8;
} else {
depthFmt = GFXFormat.D16;
}
console.info('Shading Color Format: ' + GFXFormatInfos[colorFmt].name);
console.info('Shading Depth Format: ' + GFXFormatInfos[depthFmt].name);
this._shadingPass = this._device.createRenderPass({
colorAttachments: [{
format: colorFmt,
loadOp: GFXLoadOp.CLEAR,
storeOp: GFXStoreOp.STORE,
sampleCount: 1,
beginLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL,
endLayout: GFXTextureLayout.COLOR_ATTACHMENT_OPTIMAL,
}],
depthStencilAttachment: {
format : depthFmt,
depthLoadOp : GFXLoadOp.CLEAR,
depthStoreOp : GFXStoreOp.STORE,
stencilLoadOp : GFXLoadOp.CLEAR,
stencilStoreOp : GFXStoreOp.STORE,
sampleCount : 1,
beginLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
endLayout : GFXTextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
},
});
return true;
}
protected createQuadInputAssembler (): boolean {
// create vertex buffer