/// <summary> /// Unsubscribes the given object from the given render pass. /// </summary> internal void UnsubscribeForPass(RenderPassSubscription subscription) { if (!_isSubscribeUnsubscribeAllowed) { throw new SeeingSharpException("Subscription is not allowed currently!"); } if (subscription.IsSubscribed) { // Set unsubscribed flag _anythingUnsubscribed = true; // Register unsubscription call var subscriptionInfo = _objectsPerPassDict[subscription.RenderPass]; subscriptionInfo.UnsubscribeCallCount++; // Update subscription info and reinsert it on the pass collection subscription.IsSubscribed = false; subscriptionInfo.Subscriptions[subscription.SubscriptionIndex] = subscription; // Post changes to the scene object holding this info too subscription.SceneObject.UpdateSubscription(subscription, this); } }
/// <summary> /// Subscribes the given object to the given render pass. /// </summary> internal RenderPassSubscription SubscribeForPass( RenderPassInfo passInfo, SceneObject sceneObject, Action <RenderState> renderMethod, int zOrder) { if (!_isSubscribeUnsubscribeAllowed) { throw new SeeingSharpException("Subscription is not allowed currently!"); } var subscriptionProperties = _objectsPerPassDict[passInfo]; // Append new subscription to subscription list var subscriptions = subscriptionProperties.Subscriptions; var subscriptionsCount = subscriptions.Count; var 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 var newIndex = SeeingSharpUtil.BinaryInsert(subscriptions, newSubscription, SubscriptionZOrderComparer.Instance); // Increment all subscription indices after the inserted position subscriptionsCount++; for (var loop = newIndex; loop < subscriptionsCount; loop++) { var actSubscription = subscriptions[loop]; if (actSubscription.SubscriptionIndex != loop) { actSubscription.SubscriptionIndex = loop; subscriptions[loop] = actSubscription; actSubscription.SceneObject.UpdateSubscription(actSubscription, this); } } newSubscription = subscriptions[newIndex]; } return(newSubscription); }