add floating texture to GFXFeature

This commit is contained in:
jerrywwl
2019-01-22 18:55:11 +08:00
committed by Yun Hsiao Wu
parent 905b5f7081
commit a074b2c217
8 changed files with 171 additions and 122 deletions
+1 -2
View File
@@ -35,7 +35,6 @@ export class MeshBuffer {
private _initIDataCount: number = 0;
private _dirty: boolean = false;
constructor (/*device: GFXDevice*/) {
// const device = cc.game._renderContext;
@@ -157,7 +156,7 @@ export class MeshBuffer {
// }
// }
if (this.vData && this.vData.byteLength === this._initVDataCount){
if (this.vData && this.vData.byteLength === this._initVDataCount) {
return;
}
+6 -2
View File
@@ -552,8 +552,12 @@ class View extends EventTarget {
var canvas = game.canvas;
var container = game.container;
canvas.width = width * this._devicePixelRatio;
canvas.height = height * this._devicePixelRatio;
//canvas.width = width * this._devicePixelRatio;
//canvas.height = height * this._devicePixelRatio;
const w = width * this._devicePixelRatio;
const h = height * this._devicePixelRatio;
cc.director.root.resize(w, h);
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
+1
View File
@@ -1,6 +1,7 @@
import { GFXObject, GFXObjectType } from './define';
import { GFXDevice } from './device';
// tslint:disable-next-line:no-empty-interface
export interface IGFXCommandAllocatorInfo {
}
+8
View File
@@ -16,6 +16,9 @@ import { GFXTextureView, IGFXTextureViewInfo } from './texture-view';
import { GFXWindow, IGFXWindowInfo } from './window';
export enum GFXFeature {
TEXTURE_FLOAT,
TEXTURE_HALF_FLOAT,
COUNT,
}
export interface IGFXDeviceInfo {
@@ -105,6 +108,7 @@ export abstract class GFXDevice {
protected _renderer: string = '';
protected _vendor: string = '';
protected _version: string = '';
protected _features: boolean[] = new Array<boolean>(GFXFeature.COUNT);
protected _queue: GFXQueue | null = null;
protected _width: number = 0;
protected _height: number = 0;
@@ -145,6 +149,10 @@ export abstract class GFXDevice {
public abstract copyImageSourceToTexture (source: CanvasImageSource, texture: GFXTexture, regions: GFXBufferTextureCopy[]);
public abstract copyFramebufferToBuffer (srcFramebuffer: GFXFramebuffer, dstBuffer: ArrayBuffer, regions: GFXBufferTextureCopy[]);
public hasFeature (feature: GFXFeature): boolean {
return this._features[feature];
}
public genShaderId (): number {
return this._shaderIdGen++;
}
+3 -2
View File
@@ -27,12 +27,11 @@ export class WebGLGFXCommandPool<T extends WebGLCmdObject> {
this._freeIdx = count - 1;
}
/*
public alloc (clazz: new() => T): T {
return new clazz();
}
*/
/*
public alloc (clazz: new() => T): T {
if (this._freeIdx < 0) {
const size = this._frees.length * 2;
@@ -56,6 +55,7 @@ export class WebGLGFXCommandPool<T extends WebGLCmdObject> {
++cmd.refCount;
return cmd;
}
*/
public free (cmd: T) {
if (--cmd.refCount === 0) {
@@ -64,6 +64,7 @@ export class WebGLGFXCommandPool<T extends WebGLCmdObject> {
}
public freeCmds (cmds: CachedArray<T>) {
return ;
for (let i = 0; i < cmds.length; ++i) {
if (--cmds.array[i].refCount === 0) {
this._freeCmds.push(cmds.array[i]);
+10 -1
View File
@@ -15,7 +15,7 @@ import {
GFXTextureType,
GFXTextureViewType,
} from '../define';
import { GFXDevice, IGFXDeviceInfo } from '../device';
import { GFXDevice, GFXFeature, IGFXDeviceInfo } from '../device';
import { GFXFramebuffer, IGFXFramebufferInfo } from '../framebuffer';
import { GFXInputAssembler, IGFXInputAssemblerInfo } from '../input-assembler';
import { GFXPipelineLayout, IGFXPipelineLayoutInfo } from '../pipeline-layout';
@@ -351,6 +351,15 @@ export class WebGLGFXDevice extends GFXDevice {
this._OES_element_index_uint = gl.getExtension('OES_element_index_uint');
this._ANGLE_instanced_arrays = gl.getExtension('ANGLE_instanced_arrays');
this._features.fill(false);
if (this._OES_texture_float) {
this._features[GFXFeature.TEXTURE_FLOAT] = true;
}
if (this._OES_texture_half_float) {
this._features[GFXFeature.TEXTURE_HALF_FLOAT] = true;
}
// init states
this.initStates(gl);
+51
View File
@@ -0,0 +1,51 @@
import { Material } from '../../3d/assets/material';
import { GFXBindingLayout } from '../../gfx/binding-layout';
import { GFXPipelineState } from '../../gfx/pipeline-state';
import { Pass } from '../core/pass';
export interface IUIMaterialInfo {
material: Material;
}
export class UIMaterial {
public get material (): Material {
return this._material!;
}
public get pass (): Pass {
return this._pass!;
}
public get pipelineState (): GFXPipelineState {
return this._pipelineState!;
}
public get bindingLayout (): GFXBindingLayout {
return this._bindingLayout!;
}
protected _material: Material | null = null;
protected _pass: Pass | null = null;
protected _pipelineState: GFXPipelineState | null = null;
protected _bindingLayout: GFXBindingLayout | null = null;
constructor () {
}
public initialize (info: IUIMaterialInfo): boolean {
this._material = info.material;
this._pass = this._material.passes[0];
this._pipelineState = this._pass.createPipelineState();
this._bindingLayout = this._pipelineState!.pipelineLayout.layouts[0];
return true;
}
public destroy () {
this._bindingLayout = null;
this._pipelineState = null;
this._material = null;
}
}
+91 -115
View File
@@ -25,26 +25,18 @@ import { BaseNode } from '../../scene-graph/base-node';
import { Pass } from '../core/pass';
import { Camera } from '../scene/camera';
import { RenderScene } from '../scene/render-scene';
import { IUIMaterialInfo, UIMaterial } from './ui-material';
export interface IUIBufferBatch {
vb: GFXBuffer;
ib: GFXBuffer;
}
export interface IUIMaterial {
material: Material;
bindingLayout: GFXBindingLayout;
pipelineLayout: GFXPipelineLayout;
pipelineState: GFXPipelineState;
ia: GFXInputAssembler;
}
export interface IUIRenderItem {
camera: Camera;
pass: Pass;
bindingLayout: GFXBindingLayout;
pipelineLayout: GFXPipelineLayout;
pipelineState: GFXPipelineState;
inputAssembler: GFXInputAssembler;
bufferBatch: IUIBufferBatch;
uiMaterial: UIMaterial;
}
export interface IUIRenderData {
@@ -68,8 +60,9 @@ export class UI {
private _scene: RenderScene;
private _attributes: IGFXInputAttribute[] = [];
private _bufferBatches: IUIBufferBatch[] = [];
private _uiMaterials: IUIMaterial[] = [];
private _items: CachedArray<IUIRenderItem>;
private _uiMaterial: UIMaterial | null = null;
private _uiMaterials: UIMaterial[] = [];
private _items: CachedArray<IUIRenderData>;
private _bufferInitData: IMeshBufferInitData | null = null;
private _commitUIRenderDatas: IUIRenderData[] = [];
@@ -90,9 +83,9 @@ export class UI {
public initialize () {
this._attributes = [
{ name: 'a_color', format: GFXFormat.RGBA32F, binding: 0, },
{ name: 'a_position', format: GFXFormat.RGB32F, binding: 1, },
{ name: 'a_texCoord', format: GFXFormat.RG32F, binding: 2, },
{ name: 'a_color', format: GFXFormat.RGBA32F, binding: 0 },
{ name: 'a_position', format: GFXFormat.RGB32F, binding: 1 },
{ name: 'a_texCoord', format: GFXFormat.RG32F, binding: 2 },
];
this.createBufferBatch();
@@ -102,17 +95,22 @@ export class UI {
type: GFXCommandBufferType.PRIMARY,
});
// create ui material
/*
const material = new Material();
material.effectName = 'sprite-material';
// material.setProperty('mainTexture', texture);
material.update();
this._uiMaterial = this.createUIMaterial( { material });
*/
return true;
}
public destroy () {
for (const uiMaterial of this._uiMaterials) {
uiMaterial.bindingLayout.destroy();
uiMaterial.pipelineLayout.destroy();
uiMaterial.pipelineState.destroy();
}
this._uiMaterials = [];
this.destroyUIMaterials();
for (const buffBatch of this._bufferBatches) {
buffBatch.vb.destroy();
@@ -126,46 +124,32 @@ export class UI {
}
}
/*
public registerMaterial (material: Material): IUIMaterial {
const pass = material.passes[0];
for (const mtrl of this._uiMaterials) {
if (mtrl.pass === pass) {
return mtrl;
public createUIMaterial (info: IUIMaterialInfo): UIMaterial | null {
const uiMtrl = new UIMaterial();
if (uiMtrl.initialize(info)) {
this._uiMaterials.push(uiMtrl);
return uiMtrl;
} else {
return null;
}
}
public destroyUIMaterial (uiMaterial: UIMaterial) {
for (let i = 0; i < this._uiMaterials.length; ++i) {
if (this._uiMaterials[i] === uiMaterial) {
uiMaterial.destroy();
this._uiMaterials.splice(i);
return;
}
}
const bindingLayout = this._device.createBindingLayout({
bindings: pass.bindings,
});
const pipelineLayout = this._device.createPipelineLayout({
layouts: [bindingLayout],
});
const pipelineState = this._device.createPipelineState({
primitive: pass.primitive,
shader: pass.shader,
is: { attributes: this._attributes },
rs: pass.rasterizerState,
dss: pass.depthStencilState,
bs: pass.blendState,
layout: pipelineLayout,
renderPass: pass.renderPass,
});
const uiMaterial = {
pass,
bindingLayout,
pipelineLayout,
pipelineState,
};
this._uiMaterials.push(uiMaterial);
return uiMaterial;
}
*/
public destroyUIMaterials () {
for (const uiMaterial of this._uiMaterials) {
uiMaterial.destroy();
}
this._uiMaterials = [];
}
public addScreen (comp) {
this._screens.push(comp);
@@ -198,26 +182,62 @@ export class UI {
return buffer;
}
public createUIRenderData(){
public createUIRenderData () {
return this._commitUIRenderDataPool.add();
}
public addToQueue(uiRenderData: IUIRenderData){
public addToQueue (uiRenderData: IUIRenderData) {
this._commitUIRenderDatas.push(uiRenderData);
}
public flush(){
this.render();
}
public update (dt: number) {
this._items.clear();
// TODO: Merge batch here.
this._renderScreens();
// this.render();
this.flush();
// TODO: Merge batch here.
let curCamera: Camera | null = null;
for (const uiRenderData of this._commitUIRenderDatas) {
if (curCamera !== uiRenderData.camera) {
curCamera = uiRenderData.camera;
}
// uiRenderData.meshBuffer.iData.length;
}
}
public render () {
const material = this._uiMaterial!;
if (this._items.length) {
const framebuffer = this._root.curWindow!.framebuffer;
const cmdBuff = this._cmdBuff!;
cmdBuff.begin();
for (let i = 0; i < this._items.length; ++i) {
const item = this._items.array[i];
const camera = item.camera;
this._renderArea.width = camera.width;
this._renderArea.height = camera.height;
cmdBuff.beginRenderPass(framebuffer, this._renderArea, [], camera.clearDepth, camera.clearStencil);
cmdBuff.bindPipelineState(material.pipelineState);
cmdBuff.bindBindingLayout(material.bindingLayout);
// cmdBuff.bindInputAssembler(item.meshBuffer.indiceOffset);
// cmdBuff.draw(item.inputAssembler);
cmdBuff.endRenderPass();
}
cmdBuff.end();
this._device.queue.submit([cmdBuff]);
}
}
private _walk (node, fn1, fn2, level = 0) {
@@ -273,50 +293,6 @@ export class UI {
comp.postUpdateAssembler();
}
private render () {
/*
const framebuffer = this._root.curWindow!.framebuffer;
const cmdBuff = this._cmdBuff!;
cmdBuff.begin();
cmdBuff.beginRenderPass(framebuffer, this._renderArea,
[{r: 1, g: 1, b: 1, a: 1}], 1.0, 0);
cmdBuff.end();
this._device.queue.submit([cmdBuff]);
*/
if (this._items.length) {
const framebuffer = this._root.curWindow!.framebuffer;
const cmdBuff = this._cmdBuff!;
cmdBuff.begin();
for (let i = 0; i < this._items.length; ++i) {
const item = this._items.array[i];
const camera = item.camera;
this._renderArea.width = camera.width;
this._renderArea.height = camera.height;
cmdBuff.beginRenderPass(framebuffer, this._renderArea,
[camera.clearColor], camera.clearDepth, camera.clearStencil);
cmdBuff.bindPipelineState(item.pipelineState);
cmdBuff.bindBindingLayout(item.bindingLayout);
cmdBuff.bindInputAssembler(item.inputAssembler);
cmdBuff.draw(item.inputAssembler);
cmdBuff.endRenderPass();
}
cmdBuff.end();
this._device.queue.submit([cmdBuff]);
}
}
private createBufferBatch (): IUIBufferBatch {
const vbStride = Float32Array.BYTES_PER_ELEMENT * 6;
@@ -343,7 +319,7 @@ export class UI {
indexBuffer: ib,
});
const batch: IUIBufferBatch = { vb, ib };
const batch: IUIBufferBatch = { vb, ib, ia };
this._bufferBatches.push(batch);
return batch;
}