/// <summary>
        /// Unsubscribes from the given render pass.
        /// </summary>
        protected internal void UnsubscribeFromPass(RenderPassInfo passInfo, UpdateState updateState, ViewRelatedSceneLayerSubset layerViewSubset)
        {
            // Get the subscription list
            // (may be null if object was removed from the layer)
            List <RenderPassSubscription> subscriptionList = m_viewRelatedSubscriptions[layerViewSubset.ViewIndex];

            if (subscriptionList == null)
            {
                return;
            }

            // Perform unsubscribe
            int entryCount = 0;

            for (int loop = 0; loop < subscriptionList.Count; loop++)
            {
                if (subscriptionList[loop].RenderPass == passInfo)
                {
                    subscriptionList[loop].Unsubscribe();
                    subscriptionList.RemoveAt(loop);
                    entryCount++;
                    loop--;
                }
            }
            if (entryCount > 1)
            {
                throw new SeeingSharpGraphicsException("Inconsistency: Too much subscriptions for SceneObject detected!");
            }
            if (entryCount == 0)
            {
                throw new SeeingSharpGraphicsException("Inconsistency: No subscription found on SceneObject!");
            }
        }
        /// <summary>
        /// Subscribes on the given render pass with the given action.
        /// </summary>
        /// <param name="renderPass">The render pass to which to subscribe.</param>
        /// <param name="renderAction">The action which performs rendering.</param>
        /// <param name="layerViewSubset">The ViewRelatedSceneLayerSubset to which to subscribe.</param>
        /// <param name="zOrder">The z order if sorting is enabled for this pass (default = 0).</param>
        protected internal void SubscribeToPass(
            RenderPassInfo renderPass,
            ViewRelatedSceneLayerSubset layerViewSubset, Action <RenderState> renderAction,
            int zOrder = 0)
        {
            List <RenderPassSubscription> subscriptionList = m_viewRelatedSubscriptions[layerViewSubset.ViewIndex];

            subscriptionList.Add(layerViewSubset.SubscribeForPass(renderPass, this, renderAction, zOrder));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RenderPassSubscription" /> struct.
 /// </summary>
 /// <param name="layerViewSubset">The ViewRelatedSceneLayerSubset object this subscription belongs to.</param>
 /// <param name="renderPass">The render pass on which to register.</param>
 /// <param name="sceneObject">The scene object which should be registered.</param>
 /// <param name="renderMethod">The render method which is to be registered.</param>
 /// <param name="zOrder">The z-order for sorting if the subsciptions of this pass get sorted by it.</param>
 internal RenderPassSubscription(
     ViewRelatedSceneLayerSubset layerViewSubset, RenderPassInfo renderPass,
     SceneObject sceneObject, Action <RenderState> renderMethod,
     int zOrder)
 {
     LayerViewSubset   = layerViewSubset;
     RenderPass        = renderPass;
     SceneObject       = sceneObject;
     RenderMethod      = renderMethod;
     IsSubscribed      = true;
     SubscriptionIndex = 0;
     ZOrder            = zOrder;
 }
Пример #4
0
        /// <summary>
        /// Subscribes the given object to the given render pass.
        /// </summary>
        internal RenderPassSubscription SubscribeForPass(
            RenderPassInfo passInfo,
            SceneObject sceneObject, Action <RenderState> renderMethod,
            int zOrder)
        {
            if (!m_isSubscribeUnsubscribeAllowed)
            {
                throw new SeeingSharpException("Subscription is not allowed currently!");
            }

            var subscriptionProperties = m_objectsPerPassDict[passInfo];

            // Append new subscription to subscription list
            List <RenderPassSubscription> subscriptions = subscriptionProperties.Subscriptions;
            int subscriptionsCount = subscriptions.Count;
            RenderPassSubscription newSubscription = new RenderPassSubscription(this, passInfo, sceneObject, renderMethod, zOrder);

            if (!passInfo.IsSorted)
            {
                // No sort, so put the new subscription to the end of the collection
                newSubscription.SubscriptionIndex = subscriptionsCount;
                subscriptions.Add(newSubscription);
            }
            else
            {
                // Perform BinaryInsert to the correct position
                int newIndex = CommonTools.BinaryInsert(subscriptions, newSubscription, SubscriptionZOrderComparer.Instance);

                // Increment all subscription indices after the inserted position
                subscriptionsCount++;
                RenderPassSubscription actSubscription;
                for (int loop = newIndex; loop < subscriptionsCount; loop++)
                {
                    actSubscription = subscriptions[loop];
                    if (actSubscription.SubscriptionIndex != loop)
                    {
                        actSubscription.SubscriptionIndex = loop;
                        subscriptions[loop] = actSubscription;

                        actSubscription.SceneObject.UpdateSubscription(actSubscription, this);
                    }
                }
                newSubscription = subscriptions[newIndex];
            }

            return(newSubscription);
        }