Ejemplo n.º 1
0
        public override void DrawImage(ITexture image, Rect rectangle, Point uvMin, Point uvMax)
        {
            if (image == null)
            {
                return;
            }
            EnsureContent();

            unsafe
            {
                if (!this.content.ReadRecord(out DrawImageCommand record))
                {//different record type: append new record
                    record.ImageSourceIndex = this.content.AddDependentResource(image);
                    record.rectangle        = rectangle;
                    record.UVMin            = uvMin;
                    record.UVMax            = uvMax;
                    this.content.WriteRecord(RecordType.DrawImage, (byte *)&record, sizeof(DrawImageCommand));
                    return;
                }

                //same type: update record if different
                bool recordNeedOverwrite = false;
                if (this.content.ReadDependentResource(record.ImageSourceIndex, out ITexture oldImage))
                {
                    if (!image.Equals(oldImage))
                    {
                        record.ImageSourceIndex = this.content.AddDependentResource(image);
                        recordNeedOverwrite     = true;
                    }
                }
                else
                {
                    record.ImageSourceIndex = this.content.AddDependentResource(image);
                    recordNeedOverwrite     = true;
                }

                if (!Point.AlmostEqual(record.UVMin, uvMin))
                {
                    record.UVMin        = uvMin;
                    recordNeedOverwrite = true;
                }
                if (!Point.AlmostEqual(record.UVMax, uvMax))
                {
                    record.UVMax        = uvMax;
                    recordNeedOverwrite = true;
                }


                if (recordNeedOverwrite)
                {
                    content.WriteRecord(RecordType.DrawImage, (byte *)&record, sizeof(DrawImageCommand));
                }
            }
        }