Esempio n. 1
0
        void ReallyCreateStorage()
        {
            // Because we want predictable placement of first pages, 64 will fit all default allocs
            if (m_VertexTexturingEnabled)
            {
                m_Storage = new ShaderInfoStorageRGBAFloat(64);
            }
            else
            {
                m_Storage = new ShaderInfoStorageRGBA32(64); // If no vertex texturing, only store opacity in RGBA32
            }
            // The order of allocation from the atlas below is important. See the comment at the beginning of Construct().
            RectInt rcTransform, rcClipRect, rcOpacity, rcColor, rcTextCoreSettings;

            m_Storage.AllocateRect(pageWidth * m_TransformAllocator.entryWidth, pageHeight * m_TransformAllocator.entryHeight, out rcTransform);
            m_Storage.AllocateRect(pageWidth * m_ClipRectAllocator.entryWidth, pageHeight * m_ClipRectAllocator.entryHeight, out rcClipRect);
            m_Storage.AllocateRect(pageWidth * m_OpacityAllocator.entryWidth, pageHeight * m_OpacityAllocator.entryHeight, out rcOpacity);
            m_Storage.AllocateRect(pageWidth * m_ColorAllocator.entryWidth, pageHeight * m_ColorAllocator.entryHeight, out rcColor);
            m_Storage.AllocateRect(pageWidth * m_TextSettingsAllocator.entryWidth, pageHeight * m_TextSettingsAllocator.entryHeight, out rcTextCoreSettings);

            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");
            }

            if (!AtlasRectMatchesPage(ref m_ColorAllocator, clearColor, rcColor))
            {
                throw new Exception("Atlas clear color allocation failed unexpectedly");
            }

            if (!AtlasRectMatchesPage(ref m_TextSettingsAllocator, defaultTextCoreSettings, rcTextCoreSettings))
            {
                throw new Exception("Atlas text setting allocation failed unexpectedly");
            }

            if (m_VertexTexturingEnabled)
            {
                SetTransformValue(identityTransform, identityTransformValue);
                SetClipRectValue(infiniteClipRect, infiniteClipRectValue);
            }
            {
                SetOpacityValue(fullOpacity, fullOpacityValue.w);
                SetColorValue(clearColor, clearColorValue);
                SetTextCoreSettingValue(defaultTextCoreSettings, defaultTextCoreSettingsValue);
            }

            m_StorageReallyCreated = true;
        }
Esempio n. 2
0
        public BMPAlloc Allocate(BaseShaderInfoStorage storage)
        {
            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, ownedState = OwnedState.Owned
                    });
                } // For each line
            }     // For each page

            RectInt uvRect;

            if ((storage == null) || !storage.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, ownedState = OwnedState.Owned
            });
        }