Example #1
0
		public SpriteBatchItem ()
		{
			vertexTL = new VertexPosition2ColorTexture();
			vertexTR = new VertexPosition2ColorTexture();
			vertexBL = new VertexPosition2ColorTexture();
			vertexBR = new VertexPosition2ColorTexture();
		}
Example #2
0
 public SpriteBatchItem()
 {
     vertexTL = new VertexPosition2ColorTexture();
     vertexTR = new VertexPosition2ColorTexture();
     vertexBL = new VertexPosition2ColorTexture();
     vertexBR = new VertexPosition2ColorTexture();
 }
        public void Draw(Texture2D texture, Vector2 position, Color color)
        {
            _texture = texture; //Hack sorta

            _vertexArray[_index++] = new VertexPosition2ColorTexture(position, color, Vector2.Zero);
            _vertexArray[_index++] = new VertexPosition2ColorTexture(position + new Vector2(texture.Width, 0), color, Vector2.UnitX);
            _vertexArray[_index++] = new VertexPosition2ColorTexture(position + new Vector2(0, texture.Height), color, Vector2.UnitY);
            _vertexArray[_index++] = new VertexPosition2ColorTexture(position + new Vector2(texture.Width, texture.Height), color, Vector2.One);
        }
Example #4
0
        public void DrawBatch20(SpriteSortMode sortMode)
        {
            // nothing to do
            if (_batchItemList.Count == 0)
            {
                return;
            }

            // sort the batch items
            switch (sortMode)
            {
            case SpriteSortMode.Texture:
                _batchItemList.Sort(CompareTexture);
                break;

            case SpriteSortMode.FrontToBack:
                _batchItemList.Sort(CompareDepth);
                break;

            case SpriteSortMode.BackToFront:
                _batchItemList.Sort(CompareReverseDepth);
                break;
            }

            // make sure an old draw isn't still going on.
            // cross fingers, commenting this out!!
            //GL20.Flush();
            GL20.EnableVertexAttribArray(attributePosition);
            GL20.EnableVertexAttribArray(attributeTexCoord);

            int size = VertexPosition2ColorTexture.GetSize();

            GL20.VertexAttribPointer(attributePosition, 2, All20.Float, false, size, _vertexHandle.AddrOfPinnedObject());
            GL20.VertexAttribPointer(attributeTexCoord, 2, All20.Float, false, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint))));
//			GL11.VertexPointer(2,All11.Float,size,_vertexHandle.AddrOfPinnedObject() );
//			GL11.ColorPointer(4, All11.UnsignedByte,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2)));
//			GL11.TexCoordPointer(2, All11.Float,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2+sizeof(uint))) );

            // setup the vertexArray array
            int   startIndex = 0;
            int   index      = 0;
            int   texID      = -1;
            Color lastTint   = new Color(0.0f, 0.0f, 0.0f, 0.0f);

            // make sure the vertexArray has enough space
            if (_batchItemList.Count * 4 > _vertexArray.Length)
            {
                ExpandVertexArray(_batchItemList.Count);
            }

            foreach (SpriteBatchItem item in _batchItemList)
            {
                //Tint Color
                Vector4 vtint = item.Tint.ToVector4();
                vtint /= 255;
//				GL20.VertexAttrib4(attributeTint,vtint.X, vtint.Y, vtint.Z, vtint.W);

                // if the texture changed, we need to flush and bind the new texture
                if (item.TextureID != texID || item.Tint != lastTint)
                {
                    FlushVertexArray20(startIndex, index);
                    startIndex = index;
                    texID      = item.TextureID;
                    lastTint   = item.Tint;
                    GL20.ActiveTexture(All20.Texture0);
                    GL20.BindTexture(All20.Texture2D, texID);
                    GL20.Uniform1(texID, 0);
                    GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W);
                }
                // store the SpriteBatchItem data in our vertexArray
                _vertexArray[index++] = item.vertexTL;
                _vertexArray[index++] = item.vertexTR;
                _vertexArray[index++] = item.vertexBL;
                _vertexArray[index++] = item.vertexBR;

                _freeBatchItemQueue.Enqueue(item);
            }
            // flush the remaining vertexArray data
            FlushVertexArray20(startIndex, index);

            _batchItemList.Clear();
        }
Example #5
0
        public void DrawBatch11(SpriteSortMode sortMode)
        {
            // nothing to do
            if (_batchItemList.Count == 0)
            {
                return;
            }

            // sort the batch items
            switch (sortMode)
            {
            case SpriteSortMode.Texture:
                _batchItemList.Sort(CompareTexture);
                break;

            case SpriteSortMode.FrontToBack:
                _batchItemList.Sort(CompareDepth);
                break;

            case SpriteSortMode.BackToFront:
                _batchItemList.Sort(CompareReverseDepth);
                break;
            }

            // make sure an old draw isn't still going on.
            // cross fingers, commenting this out!!
            //GL.Flush();
            int size = VertexPosition2ColorTexture.GetSize();

            GL11.VertexPointer(2, All11.Float, size, _vertexHandle.AddrOfPinnedObject());
            GL11.ColorPointer(4, All11.UnsignedByte, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2)));
            GL11.TexCoordPointer(2, All11.Float, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint))));

            // setup the vertexArray array
            int startIndex = 0;
            int index      = 0;
            int texID      = -1;

            // make sure the vertexArray has enough space
            if (_batchItemList.Count * 4 > _vertexArray.Length)
            {
                ExpandVertexArray(_batchItemList.Count);
            }

            foreach (SpriteBatchItem item in _batchItemList)
            {
                // if the texture changed, we need to flush and bind the new texture
                if (item.TextureID != texID)
                {
                    FlushVertexArray11(startIndex, index);
                    startIndex = index;
                    texID      = item.TextureID;
                    GL11.BindTexture(All11.Texture2D, texID);
                }
                // store the SpriteBatchItem data in our vertexArray
                _vertexArray[index++] = item.vertexTL;
                _vertexArray[index++] = item.vertexTR;
                _vertexArray[index++] = item.vertexBL;
                _vertexArray[index++] = item.vertexBR;

                _freeBatchItemQueue.Enqueue(item);
            }
            // flush the remaining vertexArray data
            FlushVertexArray11(startIndex, index);

            _batchItemList.Clear();
        }
Example #6
0
        public void DrawBatchGL20(SpriteSortMode sortMode)
        {
            // nothing to do
            if (_batchItemList.Count == 0)
            {
                return;
            }

            // sort the batch items
            switch (sortMode)
            {
            case SpriteSortMode.Texture:
                //_batchItemList.Sort( CompareTexture );
                throw new NotSupportedException();

            case SpriteSortMode.FrontToBack:
                //_batchItemList.Sort ( CompareDepth );
                throw new NotSupportedException();

            case SpriteSortMode.BackToFront:
                //_batchItemList.Sort ( CompareReverseDepth );
                throw new NotSupportedException();
            }

            GL20.EnableVertexAttribArray(attributePosition);
            GL20.EnableVertexAttribArray(attributeTexCoord);

            // make sure the vertexArray has enough space
            if (_batchItemList.Count * 4 > _index.Length)
            {
                ExpandIndexArray(_batchItemList.Count);
            }

            LinkVertexArray();


            int size = VertexPosition2ColorTexture.GetSize();

            GL20.VertexAttribPointer(attributePosition, 2, ALL20.Float, false, size, _vertexHandle.AddrOfPinnedObject());
            GL20.VertexAttribPointer(attributeTexCoord, 2, ALL20.Float, false, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint))));

            // setup the vertexArray array
            int   startIndex = 0;
            int   index      = 0;
            int   texID      = -1;
            Color lastTint   = new Color(0.0f, 0.0f, 0.0f, 0.0f);



            foreach (SpriteBatchItem item in _batchItemList)
            {
                //Tint Color
                Vector4 vtint = item.Tint.ToVector4();
                //vtint /= 255;
                //GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W);

                // if the texture changed, we need to flush and bind the new texture
                if (item.TextureID != texID || item.Tint != lastTint)
                {
                    FlushVertexArrayGL20(startIndex, index);
                    startIndex = index;
                    texID      = item.TextureID;
                    lastTint   = item.Tint;
                    GL20.ActiveTexture(ALL20.Texture0);
                    GL20.BindTexture(ALL20.Texture2D, texID);
                    GL20.Uniform1(texID, 0);
                    GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W);
                }
                index += 4;
            }
            // flush the remaining vertexArray data
            FlushVertexArrayGL20(startIndex, index);

            _batchItemList.Clear();
            _vertexArray.Clear();
        }