fix command pool bug

This commit is contained in:
jerrywwl
2019-01-21 21:26:40 +08:00
parent 0d60055707
commit 87df5e9be7
4 changed files with 48 additions and 26 deletions
-1
View File
@@ -174,7 +174,6 @@ export class ModelComponent extends RenderableComponent {
}
onDisable() {
this._getRenderScene().destroyModel(this._model);
}
onDestroy() {
+1 -1
View File
@@ -35,7 +35,7 @@ export class CachedArray<T> {
for (let i = 0; i < this._capacity; ++i) {
this.array[i] = temp[i];
}
this._capacity = length;
this._capacity = this.length;
}
this.array[this.length++] = item;
+34 -24
View File
@@ -11,41 +11,51 @@ import {
export class WebGLGFXCommandPool<T> {
private _frees: Array<T|null>;
private _freeIdx: number = 0;
private _count = 0;
private _data: T[];
private _objIdx: Map<T, number>;
constructor (clazz: new() => T, count: number) {
this._frees = new Array(count);
this._data = new Array(count);
this._objIdx = new Map<T, number>();
for (let i = 0; i < count; ++i) {
this._frees[i] = new clazz();
this._data[i] = new clazz();
this._objIdx.set(this._data[i], i);
}
this._freeIdx = count - 1;
}
public alloc (clazz: new() => T): T | null {
if (this._freeIdx < 0) {
const size = this._frees.length * 2;
const temp = this._frees;
this._frees = new Array<T>(size);
const increase = size - temp.length;
for (let i = 0; i < increase; ++i) {
this._frees[i] = new clazz();
public alloc (clazz: new() => T): T {
if (this._count >= this._data.length) {
if (this._data.length * 2 > this._data.length) {
for (let i = this._data.length; i < this._data.length * 2; ++i) {
this._data[i] = new clazz();
}
}
this._freeIdx += increase;
}
const item = this._frees[this._freeIdx];
this._frees[this._freeIdx--] = null;
return item;
return this._data[this._count++];
}
public free (cmd: T) {
this._frees[++this._freeIdx] = cmd;
public freeAt (idx: number) {
if (idx >= this._count) {
return;
}
const last = this._count - 1;
const tmp = this._data[idx];
this._data[idx] = this._data[last];
this._data[last] = tmp;
this._objIdx.set(this._data[idx], idx);
this._objIdx.set(this._data[last], last);
this._count -= 1;
}
public free (obj: T) {
const idx = this._objIdx.get(obj);
if (idx !== undefined) {
this.freeAt(idx);
}
}
}
+13
View File
@@ -264,6 +264,19 @@ export class UI {
}
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!;