Пример #1
0
 void FreeBatch()
 {
     if (isBatch)
     {
         if (batch != null)
         {
             batch.Dispose();
             batch   = null;
             isBatch = false;
         }
     }
 }
Пример #2
0
 public static LTextureBatch DisposeBatchCache(int texId)
 {
     lock (batchPools) {
         LTextureBatch pBatch = (LTextureBatch)CollectionUtils.Remove(batchPools, texId);
         if (pBatch != null)
         {
             lock (pBatch) {
                 pBatch.Dispose();
             }
         }
         return(pBatch);
     }
 }
Пример #3
0
	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;
	}
Пример #4
0
 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;
 }
Пример #5
0
        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);
        }
Пример #6
0
 public GLCache(LTextureBatch batch)
     : this(batch, true)
 {
 }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        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;
        }
Пример #11
0
            public GLCache(LTextureBatch batch)
                : this(batch, true)
            {

            }
Пример #12
0
 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;
 }
Пример #13
0
 public static void Destory()
 {
     LTextureBatch.ClearBatchCaches();
 }
Пример #14
0
 void FreeBatch()
 {
     if (isBatch)
     {
         if (batch != null)
         {
             batch.Dispose();
             batch = null;
             isBatch = false;
         }
     }
 }
Пример #15
0
 void MakeBatch()
 {
     if (!isBatch)
     {
         batch = new LTextureBatch(this, MaxBatchSize);
         isBatch = true;
     }
 }