public static void release(TObject obj) { if (obj == null) { return; } if (AllocDebugger.enableDebugging) { if (!obj.activated_flag) { Debug.Assert(false, "an item has been recycled more than once !"); } obj.activated_flag = false; AllocDebugger.onRelease(debugKey, debugName, allocatedCount); } obj.clear(); if (pool.Count > POOL_MAX_SIZE) { allocatedCount--; //there are enough items in the pool //just release the obj to GC return; } pool.Push(obj); }
public static TObject alloc() { if (pool.Count == 0) { for (int i = 0; i < POOL_BATCH_SIZE; i++) { var obj = new TObject(); pool.Push(obj); } allocatedCount += POOL_BATCH_SIZE; } var ret = pool.Pop(); ret.setup(); if (AllocDebugger.enableDebugging) { AllocDebugger.onAlloc(debugKey, debugName, allocatedCount); ret.activated_flag = true; } return(ret); }
public void flush(uiPicture picture) { if (!CanvasShader.isReady()) { return; } this._reset(); this._resetRenderTextureId(); this._resetComputeBuffer(); this._drawUIPicture(picture, false); D.assert(this._layers.Count == 1); D.assert(this._layers[0].states.Count == 1); var layer = this._currentLayer; using (var cmdBuf = new CommandBuffer()) { cmdBuf.name = "CommandBufferCanvas"; this._lastRtID = -1; this._drawLayer(layer, cmdBuf); // this is necessary for webgl2. not sure why... just to be safe to disable the scissor. cmdBuf.DisableScissorRect(); this._bindComputeBuffer(); Graphics.ExecuteCommandBuffer(cmdBuf); } D.assert(this._layers.Count == 0 || (this._layers.Count == 1 && this._layers[0] == this._currentLayer)); if (this._currentLayer != null) { this._clearLayer(this._currentLayer); ObjectPool <RenderLayer> .release(this._currentLayer); this._currentLayer = null; this._lastScissor = null; this._layers.Clear(); } AllocDebugger.onFrameEnd(); }