Ejemplo n.º 1
0
        void ReallyCreateAtlas()
        {
            m_Atlas = new UIRAtlasManager(
                m_VertexTexturingEnabled ? RenderTextureFormat.ARGBFloat : RenderTextureFormat.ARGB32, // If no vertex texturing, only store opacity in ARGB32
                FilterMode.Point,                                                                      // Filtering is never needed for this texture
                Math.Max(pageWidth, pageHeight * 3),                                                   // Each transform row is stored vertically
                64);                                                                                   // Because we want predictable placement of first pages, 64 will fit all three default allocs

            // The order of allocation from the atlas below is important. See the comment at the beginning of Construct().
            RectInt rcTransform, rcClipRect, rcOpacity;

            m_Atlas.AllocateRect(pageWidth * m_TransformAllocator.entryWidth, pageHeight * m_TransformAllocator.entryHeight, out rcTransform);
            m_Atlas.AllocateRect(pageWidth * m_ClipRectAllocator.entryWidth, pageHeight * m_ClipRectAllocator.entryHeight, out rcClipRect);
            m_Atlas.AllocateRect(pageWidth * m_OpacityAllocator.entryWidth, pageHeight * m_OpacityAllocator.entryHeight, out rcOpacity);

            if (!AtlasRectMatchesPage(ref m_TransformAllocator, identityTransform, rcTransform))
            {
                throw new Exception("Atlas identity transform allocation failed unexpectedly");
            }

            if (!AtlasRectMatchesPage(ref m_ClipRectAllocator, infiniteClipRect, rcClipRect))
            {
                throw new Exception("Atlas infinite clip rect allocation failed unexpectedly");
            }

            if (!AtlasRectMatchesPage(ref m_OpacityAllocator, fullOpacity, rcOpacity))
            {
                throw new Exception("Atlas full opacity allocation failed unexpectedly");
            }

            var whiteTexel = UIRenderDevice.whiteTexel;

            if (m_VertexTexturingEnabled)
            {
                var allocXY = AllocToTexelCoord(ref m_TransformAllocator, identityTransform);
                m_Atlas.EnqueueBlit(whiteTexel, allocXY.x, allocXY.y + 0, false, identityTransformRow0Value);
                m_Atlas.EnqueueBlit(whiteTexel, allocXY.x, allocXY.y + 1, false, identityTransformRow1Value);
                m_Atlas.EnqueueBlit(whiteTexel, allocXY.x, allocXY.y + 2, false, identityTransformRow2Value);

                allocXY = AllocToTexelCoord(ref m_ClipRectAllocator, infiniteClipRect);
                m_Atlas.EnqueueBlit(whiteTexel, allocXY.x, allocXY.y, false, infiniteClipRectValue);
            }
            {
                var allocXY = AllocToTexelCoord(ref m_OpacityAllocator, fullOpacity);
                m_Atlas.EnqueueBlit(whiteTexel, allocXY.x, allocXY.y, false, fullOpacityValue);
            }

            m_AtlasReallyCreated = true;
        }
Ejemplo n.º 2
0
        public BMPAlloc Allocate(UIRAtlasManager atlasManager)
        {
            int pageCount = m_Pages.Count;

            for (int pageIndex = 0; pageIndex < pageCount; pageIndex++)
            {
                var pageInfo = m_Pages[pageIndex];
                if (pageInfo.freeSlots == 0)
                {
                    continue;
                }

                int line    = pageIndex * m_PageHeight;
                int endLine = line + m_PageHeight;
                for (; line < endLine; line++)
                {
                    var allocBits = m_AllocMap[line];
                    if (allocBits == 0)
                    {
                        continue;
                    }
                    byte allocIndex = CountTrailingZeroes(allocBits);
                    m_AllocMap[line] = allocBits & (~(1U << allocIndex));
                    pageInfo.freeSlots--;
                    m_Pages[pageIndex] = pageInfo;
                    return(new BMPAlloc()
                    {
                        page = pageIndex, pageLine = (ushort)(line - pageIndex * m_PageHeight), bitIndex = allocIndex, owned = 1
                    });
                } // For each line
            }     // For each page

            RectInt uvRect;

            if ((atlasManager == null) || !atlasManager.AllocateRect(kPageWidth * m_EntryWidth, m_PageHeight * m_EntryHeight, out uvRect))
            {
                return(BMPAlloc.Invalid);
            }

            m_AllocMap.Capacity += m_PageHeight;
            m_AllocMap.Add(0xFFFFFFFE); // Reserve first slot
            for (int i = 1; i < m_PageHeight; i++)
            {
                m_AllocMap.Add(0xFFFFFFFF);
            }

            m_Pages.Add(new Page()
            {
                x = (UInt16)uvRect.xMin, y = (UInt16)uvRect.yMin, freeSlots = kPageWidth * m_PageHeight - 1
            });
            return(new BMPAlloc()
            {
                page = m_Pages.Count - 1, owned = 1
            });
        }
Ejemplo n.º 3
0
        public BMPAlloc Allocate(UIRAtlasManager atlasManager)
        {
            int      count = this.m_Pages.Count;
            BMPAlloc result;

            for (int i = 0; i < count; i++)
            {
                BitmapAllocator32.Page page = this.m_Pages[i];
                bool flag = page.freeSlots == 0;
                if (!flag)
                {
                    int j   = i * this.m_PageHeight;
                    int num = j + this.m_PageHeight;
                    while (j < num)
                    {
                        uint num2  = this.m_AllocMap[j];
                        bool flag2 = num2 == 0u;
                        if (!flag2)
                        {
                            byte b = BitmapAllocator32.CountTrailingZeroes(num2);
                            this.m_AllocMap[j] = (num2 & ~(1u << (int)b));
                            page.freeSlots--;
                            this.m_Pages[i] = page;
                            result          = new BMPAlloc
                            {
                                page       = i,
                                pageLine   = (ushort)(j - i * this.m_PageHeight),
                                bitIndex   = b,
                                ownedState = OwnedState.Owned
                            };
                            return(result);
                        }
                        j++;
                    }
                }
            }
            RectInt rectInt;
            bool    flag3 = atlasManager == null || !atlasManager.AllocateRect(32 * this.m_EntryWidth, this.m_PageHeight * this.m_EntryHeight, out rectInt);

            if (flag3)
            {
                result = BMPAlloc.Invalid;
                return(result);
            }
            this.m_AllocMap.Capacity += this.m_PageHeight;
            this.m_AllocMap.Add(4294967294u);
            for (int k = 1; k < this.m_PageHeight; k++)
            {
                this.m_AllocMap.Add(4294967295u);
            }
            this.m_Pages.Add(new BitmapAllocator32.Page
            {
                x         = (ushort)rectInt.xMin,
                y         = (ushort)rectInt.yMin,
                freeSlots = 32 * this.m_PageHeight - 1
            });
            result = new BMPAlloc
            {
                page       = this.m_Pages.Count - 1,
                ownedState = OwnedState.Owned
            };
            return(result);
        }