Example #1
0
        protected bool FinishDisplayListEntry(ref DisplayListEntry de, ref DisplayListCamera dlc,
                                              ref LocalToWorld tx, ref PrivateTransformData ptd, bool doNotClip)
        {
            de.inSortingGroup = ptd.inSortingGroup;
#if UNITY_USE_TINYMATH
            de.finalMatrix = tinymath.mul(dlc.inverseWorld, tx.Value);
#else
            de.finalMatrix = math.mul(dlc.inverseWorld, tx.Value);
#endif
            if (doNotClip)
            {
                return(true);
            }
            // z-clip
            float z = de.finalMatrix[2][3];
            if (z < dlc.clipZNear || z > dlc.clipZFar)
            {
                return(false);
            }
            // bounds clip
#if DEBUG
            if (!(de.inBounds.width > 0.0f) || !(de.inBounds.height > 0.0f))
            {
                Debug.LogFormat("Entity {0} has zero or negative size ({1},{2})! This is checked in DEVELOPMENT builds only!", de.e, de.inBounds.width, de.inBounds.height);
                return(false);
            }
#endif
            return(true);
        }
Example #2
0
        // Callback to create entry
        // DisplayListEntry de is input/output
        //    e = input, the entity being added
        //    finalMatrix = undefined at this point, do not change
        //    inBounds = output, object space bounding rectangle
        //    type = output, type to be used by rendering
        //    inSortingGroup = undefined at this point, do not change
        // return false to discard the entry
        public bool MakeEntry(EntityManager m, ref DisplayListEntry de)
        {
            var spriteRenderer = cachedGetSprite2DRenderer[de.e];

            if (spriteRenderer.color.a <= 0.0f)
            {
                return(false);
            }
            var spritePrivate = cachedGetSprite2DPrivate[spriteRenderer.sprite];

            if (!spritePrivate.valid)
            {
                return(false);
            }

            if (cachedGetSprite2DRendererOptions.Exists(de.e))
            {
                // slow path: with options
                var    sprite    = cachedGetSprite2D[spriteRenderer.sprite];
                var    tiling    = cachedGetSprite2DRendererOptions[de.e];
                float2 size      = tiling.size;
                Entity esprite   = spriteRenderer.sprite;
                bool   hasBorder = false;
                // check for border
                if (cachedGetSprite2DBorder.Exists(esprite))
                {
                    var border = cachedGetSprite2DBorder[esprite];
                    hasBorder = border.bottomLeft.x > 0.0f || border.bottomLeft.y > 0.0f || border.topRight.x < 1.0f ||
                                border.topRight.y < 1.0f;
                    //Assert(border->bottomLeft.x < border->topRight.x);
                    //Assert(border->bottomLeft.y < border->topRight.y);
                    //Assert(border->bottomLeft.x >= 0.0f && border->topRight.x <= 1.0f);
                    //Assert(border->bottomLeft.y >= 0.0f && border->topRight.y <= 1.0f);
                }
                if (tiling.drawMode == DrawMode.Stretch && !hasBorder)
                {
                    de.type = DisplayListEntryType.Sprite;
                }
                else
                {
                    de.type = hasBorder ? DisplayListEntryType.SlicedSprite : DisplayListEntryType.TiledSprite;
                }
                // compute bounds
                de.inBounds = new Rect {
                    x = size.x * -sprite.pivot.x, y = size.y * -sprite.pivot.y, width = size.x, height = size.y
                };
            }
            else
            {
                de.inBounds = spritePrivate.rect;
                de.type     = DisplayListEntryType.Sprite;
            }
            return(true);
        }
Example #3
0
        protected void AddItemsToListByType(IExternalDisplayListEntryMaker dlm, DisplayListCamera dlc, Camera2D c2d,
                                            DynamicBuffer <DisplayListEntry> dest, DynamicBuffer <SortedEntity> destSorted)
        {
            var mgr = EntityManager;

            dlm.Update(this);
            var  cachedGetLayerSorting = GetComponentDataFromEntity <LayerSorting>(true);
            bool doNotClip             = dlm.DoNotClip();
            var  query = Entities;

            // build the query: Add base filter and dlm, then add per - camera filter
            dlm.Filter(ref query);
            // add camera 'layer' filter
            AddLayerFilter(ref query, c2d);

            // run query
            query.ForEach((Entity e, ref PrivateTransformData ptd, ref LocalToWorld tx) =>
            {
                DisplayListEntry de = default;
                de.e = e;
                if (!dlm.MakeEntry(mgr, ref de))
                {
                    return;
                }
                if (!FinishDisplayListEntry(ref de, ref dlc, ref tx, ref ptd, doNotClip))
                {
                    return;
                }
                float z         = math.dot(de.finalMatrix[3], dlc.sortingDot); // = Dot(de.finalMatrix.GetColumn(3), dlc.camSortingDot); TODO CHECK
                SortedEntity se = new SortedEntity {
                    e   = de.e,
                    idx = dest.Length
                };
                if (cachedGetLayerSorting.Exists(de.e))
                {
                    var sortEx = cachedGetLayerSorting[de.e];
                    se.CombineKey(z, sortEx.layer, sortEx.order);
                }
                else
                {
                    se.CombineKey(z);
                }
                se.e   = de.e;
                se.idx = dest.Length;
                dest.Add(de);
                destSorted.Add(se);
            });
        }
Example #4
0
        public bool MakeEntry(EntityManager mgr, ref DisplayListEntry de)
        {
            var shapeRenderer = mgr.GetComponentData <Shape2DRenderer>(de.e);

            if (shapeRenderer.color.a <= 0)
            {
                return(false);
            }
            if (shapeRenderer.shape == Entity.Null) // fix up invalid ref to point to self
            {
                shapeRenderer.shape = de.e;
            }
#if DEVELOPMENT
            if (!man.hasBuffer <Shape2DVertex>(shapeRenderer->shape))
            {
                logWarning("Shape renderer entity %s has no valid Shape2DVertex buffer!", man.formatEntity(det.e).c_str());
                return(false);
            }
#endif
            var shape = mgr.GetBuffer <Shape2DVertex>(shapeRenderer.shape);
            if (shape.Length < 3)
            {
                return(false);
            }
#if DEVELOPMENT
            if (shape.size() < 3)
            {
                logWarning("Shape entity %s has less than three (%i) vertices!", man.formatEntity(det.e).c_str(),
                           (int)shape.size());
                return(false);
            }
#endif
            float2 bbMin = shape[0].position;
            float2 bbMax = bbMin;
            for (int i = 1; i < (int)shape.Length; i++)
            {
                bbMin = math.min(bbMin, shape[i].position);
                bbMax = math.max(bbMax, shape[i].position);
            }
            de.inBounds.x      = bbMin.x;
            de.inBounds.y      = bbMin.y;
            de.inBounds.width  = bbMax.x - bbMin.x;
            de.inBounds.height = bbMax.y - bbMin.y;
            de.type            = DisplayListEntryType.Shape;
            return(true);
        }
Example #5
0
 public bool MakeEntry(EntityManager mgr, ref DisplayListEntry de)
 {
     de.inBounds = new Rect();
     de.type     = DisplayListEntryType.GroupOnly;
     return(true);
 }