void FreeBatch() { if (isBatch) { if (batch != null) { batch.Dispose(); batch = null; isBatch = false; } } }
public static LTextureBatch DisposeBatchCache(int texId) { lock (batchPools) { LTextureBatch pBatch = (LTextureBatch)CollectionUtils.Remove(batchPools, texId); if (pBatch != null) { lock (pBatch) { pBatch.Dispose(); } } return(pBatch); } }
public static LTextureBatch BindBatchCache( int index, int texId, LTexture texture) { if (batchPools.Count > 128) { ClearBatchCaches(); } int key = LSystem.Unite(index, texId); LTextureBatch pBatch = (LTextureBatch)CollectionUtils.Get(batchPools, key); if (pBatch == null) { lock (batchPools) { pBatch = new LTextureBatch(texture); CollectionUtils.Put(batchPools,key, pBatch); } } return pBatch; }
public GLCache(LTextureBatch batch, bool Reset) { if (Reset) { batch.InsertVertices(); } this.m_type = batch.batchType; this.m_cache = new VertexPositionColorTexture[batch.glbase.GetVerticesSize()]; Array.Copy(batch.glbase.Vertices, m_cache, batch.glbase.GetVerticesSize()); this.m_quadIndices = new short[batch.glbase.GetQuadIndicesSize()]; Array.Copy(batch.glbase.QuadIndices, m_quadIndices, batch.glbase.GetQuadIndicesSize()); this.batchCount = batch.batchCount; this.isColor = batch.isColor; this.x = batch.moveX; this.y = batch.moveY; }
public static LTextureBatch BindBatchCache(int index, int texId, LTexture texture) { if (batchPools.Count > 128) { ClearBatchCaches(); } int key = LSystem.Unite(index, texId); LTextureBatch pBatch = (LTextureBatch)CollectionUtils.Get(batchPools, key); if (pBatch == null) { lock (batchPools) { pBatch = new LTextureBatch(texture); CollectionUtils.Put(batchPools, key, pBatch); } } return(pBatch); }
public GLCache(LTextureBatch batch) : this(batch, true) { }
private void DrawString(float x, float y, float sx, float sy, float ax, float ay, float rotation, string chars, LColor c, int startIndex, int endIndex) { if (displays.Count > LSystem.DEFAULT_MAX_CACHE_SIZE) { lock (displays) { foreach (Loon.Core.Graphics.Opengl.LTextureBatch.GLCache cache in displays.Values) { if (cache != null) { cache.Dispose(); } } } displays.Clear(); } this.intObject = null; this.charCurrent = 0; this.totalWidth = 0; if (rotation != 0 && (ax == 0 && ay == 0)) { ax = font.StringWidth(chars) / 2; ay = font.GetHeight(); } if (useCache) { display = (Loon.Core.Graphics.Opengl.LTextureBatch.GLCache)CollectionUtils.Get(displays, chars); if (display == null) { fontBatch.GLBegin(); char[] charList = chars.ToCharArray(); for (int i = 0; i < charList.Length; i++) { charCurrent = charList[i]; if (charCurrent < totalCharSet) { intObject = charArray[charCurrent]; } else { intObject = (IntObject)CollectionUtils.Get(customChars, (char)charCurrent); } if (intObject != null) { if ((i >= startIndex) || (i <= endIndex)) { if (antiAlias) { fontBatch.DrawQuad(totalWidth * fontScale, 0, (totalWidth + intObject.width) * fontScale, (intObject.height * fontScale), intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } else { fontBatch.DrawQuad(totalWidth, 0, (totalWidth + intObject.width), intObject.height, intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } } totalWidth += intObject.width; } } fontBatch.CommitQuad(c, x, y, sx, sy, ax, ay, rotation); CollectionUtils.Put(displays, chars, display = fontBatch.NewGLCache()); } else if (display != null && fontBatch != null && fontBatch.GetTexture() != null) { LTextureBatch.CommitQuad(fontBatch.GetTexture(), display, c, x, y, sx, sy, ax, ay, rotation); } } else { fontBatch.GLBegin(); char[] charList = chars.ToCharArray(); for (int i = 0; i < charList.Length; i++) { charCurrent = charList[i]; if (charCurrent < totalCharSet) { intObject = charArray[charCurrent]; } else { intObject = (IntObject)CollectionUtils.Get(customChars, (char)charCurrent); } if (intObject != null) { if ((i >= startIndex) || (i <= endIndex)) { if (antiAlias) { fontBatch.DrawQuad(totalWidth * fontScale, 0, (totalWidth + intObject.width) * fontScale, (intObject.height * fontScale), intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } else { fontBatch.DrawQuad(totalWidth, 0, (totalWidth + intObject.width), intObject.height, intObject.storedX, intObject.storedY, intObject.storedX + intObject.width, intObject.storedY + intObject.height); } } totalWidth += intObject.width; } } fontBatch.CommitQuad(c, x, y, sx, sy, ax, ay, rotation); } }
private void Make(LFont font, char[] customCharsArray) { if (charArray == null) { charArray = new IntObject[totalCharSet]; } if (customCharsArray != null && customCharsArray.Length > totalCharSet) { textureWidth *= 2; } try { LImage imgTemp = LImage.CreateImage(textureWidth, textureHeight, true); LGraphics g = imgTemp.GetLGraphics(); g.SetFont(font); int rowHeight = 0; int positionX = 0; int positionY = 0; int customCharsLength = (customCharsArray != null) ? customCharsArray.Length : 0; this.totalCharSet = customCharsLength == 0 ? totalCharSet : 0; StringBuilder sbr = new StringBuilder(totalCharSet); for (int i = 0; i < totalCharSet + customCharsLength; i++) { char ch = (i < totalCharSet) ? (char)i : customCharsArray[i - totalCharSet]; int charwidth = font.CharWidth(ch); if (charwidth <= 0) { charwidth = 1; } int charheight = font.GetHeight(); if (charheight <= 0) { charheight = font.GetSize(); } IntObject newIntObject = new IntObject(); newIntObject.width = charwidth; newIntObject.height = charheight; if (positionX + newIntObject.width >= textureWidth) { g.DrawString(sbr.ToString(), 0, positionY); sbr.Clear(); positionX = 0; positionY += rowHeight; rowHeight = 0; } newIntObject.storedX = positionX; newIntObject.storedY = positionY; if (newIntObject.height > fontHeight) { fontHeight = newIntObject.height; } if (newIntObject.height > rowHeight) { rowHeight = newIntObject.height; } sbr.Append(ch); positionX += newIntObject.width; if (i < totalCharSet) { charArray[i] = newIntObject; } else { CollectionUtils.Put(customChars, ch, newIntObject); } } if (sbr.Length > 0) { g.DrawString(sbr.ToString(), 0, positionY); sbr = null; } g.Dispose(); g = null; fontBatch = new LTextureBatch(imgTemp.GetTexture()); } catch (Exception ex) { Loon.Utils.Debugging.Log.Exception(ex); } }
private void Make(LFont font, char[] customCharsArray) { if (charArray == null) { charArray = new IntObject[totalCharSet]; } if (customCharsArray != null && customCharsArray.Length > totalCharSet) { textureWidth *= 2; } try { LImage imgTemp = LImage.CreateImage(textureWidth, textureHeight, true); LGraphics g = imgTemp.GetLGraphics(); g.SetFont(font); int rowHeight = 0; int positionX = 0; int positionY = 0; int customCharsLength = (customCharsArray != null) ? customCharsArray.Length : 0; this.totalCharSet = customCharsLength == 0 ? totalCharSet : 0; StringBuilder sbr = new StringBuilder(totalCharSet); for (int i = 0; i < totalCharSet + customCharsLength; i++) { char ch = (i < totalCharSet) ? (char)i : customCharsArray[i - totalCharSet]; int charwidth = font.CharWidth(ch); if (charwidth <= 0) { charwidth = 1; } int charheight = font.GetHeight(); if (charheight <= 0) { charheight = font.GetSize(); } IntObject newIntObject = new IntObject(); newIntObject.width = charwidth; newIntObject.height = charheight; if (positionX + newIntObject.width >= textureWidth) { g.DrawString(sbr.ToString(), 0, positionY); sbr.Clear(); positionX = 0; positionY += rowHeight; rowHeight = 0; } newIntObject.storedX = positionX; newIntObject.storedY = positionY; if (newIntObject.height > fontHeight) { fontHeight = newIntObject.height; } if (newIntObject.height > rowHeight) { rowHeight = newIntObject.height; } sbr.Append(ch); positionX += newIntObject.width; if (i < totalCharSet) { charArray[i] = newIntObject; } else { CollectionUtils.Put(customChars, ch, newIntObject); } } if (sbr.Length > 0) { g.DrawString(sbr.ToString(), 0, positionY); sbr = null; } g.Dispose(); g = null; fontBatch = new LTextureBatch(imgTemp.GetTexture()); } catch (Exception ex) { Loon.Utils.Debug.Log.Exception(ex); } }
public GLEx(GL gl) { GLEx._gl = gl; this.glBatch = new GLBatch(512); this.texBatch = new LTextureBatch(glBatch); this.texBatch.ClearBatch = false; this.xnaClip = new RectBox(_trueScreenMax); WhitePixel = new Texture2D(GL.device, 1, 1, true, SurfaceFormat.Color); Color[] pixels = { Color.White }; WhitePixel.SetData(pixels); GLEx.self = this; }
public GLCache(LTextureBatch batch) : this(batch, true) { }
public GLCache(LTextureBatch batch, bool Reset) { if (Reset) { batch.InsertVertices(); } this.m_type = batch.batchType; this.m_cache = new VertexPositionColorTexture[batch.glbase.GetVerticesSize()]; Array.Copy(batch.glbase.Vertices, m_cache, batch.glbase.GetVerticesSize()); this.m_quadIndices = new short[batch.glbase.GetQuadIndicesSize()]; Array.Copy(batch.glbase.QuadIndices, m_quadIndices, batch.glbase.GetQuadIndicesSize()); this.batchCount = batch.batchCount; this.isColor = batch.isColor; this.x = batch.moveX; this.y = batch.moveY; }
public static void Destory() { LTextureBatch.ClearBatchCaches(); }
void FreeBatch() { if (isBatch) { if (batch != null) { batch.Dispose(); batch = null; isBatch = false; } } }
void MakeBatch() { if (!isBatch) { batch = new LTextureBatch(this, MaxBatchSize); isBatch = true; } }