fix ui batch errors

This commit is contained in:
jerrywwl
2019-01-30 11:41:58 +08:00
parent 0e8e8fd1f7
commit 005282b6f5
5 changed files with 43 additions and 50 deletions
+6 -12
View File
@@ -151,26 +151,20 @@ export class WebGLGFXCommandBuffer extends GFXCommandBuffer {
public bindPipelineState (pipelineState: GFXPipelineState) {
const gpuPipelineState = (pipelineState as WebGLGFXPipelineState).gpuPipelineState;
if (this._curGPUPipelineState !== gpuPipelineState) {
this._curGPUPipelineState = gpuPipelineState;
this._isStateInvalied = true;
}
this._curGPUPipelineState = gpuPipelineState;
this._isStateInvalied = true;
}
public bindBindingLayout (bindingLayout: GFXBindingLayout) {
const gpuBindingLayout = (bindingLayout as WebGLGFXBindingLayout).gpuBindingLayout;
if (this._curGPUBindingLayout !== gpuBindingLayout) {
this._curGPUBindingLayout = gpuBindingLayout;
this._isStateInvalied = true;
}
this._curGPUBindingLayout = gpuBindingLayout;
this._isStateInvalied = true;
}
public bindInputAssembler (inputAssembler: GFXInputAssembler) {
const gpuInputAssembler = (inputAssembler as WebGLGFXInputAssembler).gpuInputAssembler;
if (this._curGPUInputAssembler !== gpuInputAssembler) {
this._curGPUInputAssembler = gpuInputAssembler;
this._isStateInvalied = true;
}
this._curGPUInputAssembler = gpuInputAssembler;
this._isStateInvalied = true;
}
public setViewport (viewport: IGFXViewport) {
+4
View File
@@ -697,6 +697,10 @@ export class WebGLGFXDevice extends GFXDevice {
glType: 0,
glUsage: 0,
glTexture: 0,
glWrapS: 0,
glWrapT: 0,
glMinFilter: 0,
glMagFilter: 0,
};
// TODO: Async
-14
View File
@@ -35,23 +35,9 @@ export class WebGLStateCache {
for (let i = 0; i < GFX_MAX_TEXTURE_UNITS; ++i) {
this.glTex2DUnits[i] = {
glTexture: 0,
minFilter: WebGLRenderingContext.NONE,
magFilter: WebGLRenderingContext.NONE,
wrapS: WebGLRenderingContext.NONE,
wrapT: WebGLRenderingContext.NONE,
wrapR: WebGLRenderingContext.NONE,
baseLevel: 0,
maxLevel: 1000,
};
this.glTexCubeUnits[i] = {
glTexture: 0,
minFilter: WebGLRenderingContext.NONE,
magFilter: WebGLRenderingContext.NONE,
wrapS: WebGLRenderingContext.NONE,
wrapT: WebGLRenderingContext.NONE,
wrapR: WebGLRenderingContext.NONE,
baseLevel: 0,
maxLevel: 1000,
};
}
-14
View File
@@ -17,18 +17,8 @@ export class UIMaterial {
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 () {
}
@@ -42,15 +32,11 @@ export class UIMaterial {
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;
}
}
+33 -10
View File
@@ -31,6 +31,7 @@ import { RenderScene } from '../scene/render-scene';
import { IUIMaterialInfo, UIMaterial } from './ui-material';
import { Node } from '../../scene-graph/node';
import { Rect } from '../../core/value-types';
import { GFXPipelineState } from '../../gfx/pipeline-state';
export class UBOUI {
public static MAT_VIEW_PROJ_OFFSET: number = 0;
@@ -63,14 +64,28 @@ export class UIBufferBatch {
export class UIDrawBatch {
public camera: Camera | null = null;
public bufferBatch: UIBufferBatch | null = null;
public uiMaterial: UIMaterial | null = null;
public material: Material | null = null;
public texView: GFXTextureView | null = null;
public idxCount: number = 0;
public pipelineState: GFXPipelineState | null = null;
public bindingLayout: GFXBindingLayout | null = null;
destroy() {
if (this.pipelineState) {
this.pipelineState.destroy();
this.pipelineState = null;
}
if (this.bindingLayout) {
this.bindingLayout.destroy();
this.bindingLayout = null;
}
}
clear() {
this.camera = null;
this.bufferBatch = null;
this.uiMaterial = null;
this.material = null;
this.texView = null;
this.idxCount = 0;
}
@@ -196,6 +211,10 @@ export class UI {
this._uiUBO = null;
}
for (const batch of this._batches.array) {
batch.destroy();
}
for (const buffBatch of this._bufferBatches) {
buffBatch.vb!.destroy();
buffBatch.ib!.destroy();
@@ -351,15 +370,16 @@ export class UI {
cmdBuff.beginRenderPass(framebuffer, this._renderArea, [], camera.clearDepth, camera.clearStencil);
}
material.bindingLayout.bindBuffer(0, this._uiUBO!);
material.bindingLayout.bindTextureView(1, batch.texView!);
material.bindingLayout.update();
const bindingLayout = batch.bindingLayout!;
bindingLayout.bindBuffer(0, this._uiUBO!);
bindingLayout.bindTextureView(1, batch.texView!);
bindingLayout.update();
let ia = batch.bufferBatch!.ia!
ia.indexCount = batch.idxCount;
cmdBuff.bindPipelineState(material.pipelineState);
cmdBuff.bindBindingLayout(material.bindingLayout);
cmdBuff.bindPipelineState(batch.pipelineState!);
cmdBuff.bindBindingLayout(bindingLayout);
cmdBuff.bindInputAssembler(batch.bufferBatch!.ia!);
cmdBuff.draw(batch.bufferBatch!.ia!);
}
@@ -541,8 +561,6 @@ export class UI {
curBufferBatch.vui16![idxCount + n] = vui16[n] + vertCount;
}
//curBufferBatch.vui16!.set(vui16, idxCount);
vertCount += vCount;
idxCount += vui16.length;
@@ -555,10 +573,15 @@ export class UI {
curDrawBatch = this._drawBatchPool.add();
curDrawBatch.camera = curCamera;
curDrawBatch.bufferBatch = curBufferBatch;
curDrawBatch.uiMaterial = this._uiMaterial!;
curDrawBatch.material = uiRenderData.material;
curDrawBatch.texView = curTexView!;
curDrawBatch.idxCount = idxCount;
if (!curDrawBatch.pipelineState) {
curDrawBatch.pipelineState = this._uiMaterial!.pass.createPipelineState();
curDrawBatch.bindingLayout = curDrawBatch.pipelineState!.pipelineLayout.layouts[0];
}
this._batches.push(curDrawBatch);
isNewBatch = false;
} else {