Ejemplo n.º 1
0
        internal void ReleaseSlot(int slotIndex)
        {
            RenderModelEffectSlot selectedSlot = null;

            foreach (var slot in effectNameToSlot)
            {
                if (slot.Value.Slot == slotIndex)
                {
                    selectedSlot = slot.Value;
                    break;
                }
            }

            if (selectedSlot == null)
            {
                throw new ArgumentOutOfRangeException("slotIndex", "Invalid slot");
            }

            if (--selectedSlot.ReferenceCount == 0)
            {
                // Release the slot if no other reference points to it (add it in free list)
                if (!effectNameToSlot.Remove(selectedSlot.EffectName))
                {
                    throw new InvalidOperationException("Model slot not found while trying to remove it.");
                }
                availableSlots.Enqueue(selectedSlot);
            }
        }
        /// <summary>
        /// Gets or creates a slot for the specified effect name.
        /// </summary>
        /// <param name="effectName">Name of the effect.</param>
        /// <returns>RenderModelEffectSlot.</returns>
        internal int AllocateSlot(string effectName)
        {
            RenderModelEffectSlot renderModelEffectSlot;
            if (!effectNameToSlot.TryGetValue(effectName, out renderModelEffectSlot))
            {
                // First, check free list, otherwise create a new slot
                if (availableSlots.Count > 0)
                {
                    renderModelEffectSlot = availableSlots.Dequeue();
                    renderModelEffectSlot.EffectName = effectName;
                    effectNameToSlot[effectName] = renderModelEffectSlot;
                }
                else
                    effectNameToSlot[effectName] = renderModelEffectSlot = new RenderModelEffectSlot(effectName, effectNameToSlot.Count);
            }

            renderModelEffectSlot.ReferenceCount++;
            return renderModelEffectSlot.Slot;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets or creates a slot for the specified effect name.
        /// </summary>
        /// <param name="effectName">Name of the effect.</param>
        /// <returns>RenderModelEffectSlot.</returns>
        internal int AllocateSlot(string effectName)
        {
            RenderModelEffectSlot renderModelEffectSlot;

            if (!effectNameToSlot.TryGetValue(effectName, out renderModelEffectSlot))
            {
                // First, check free list, otherwise create a new slot
                if (availableSlots.Count > 0)
                {
                    renderModelEffectSlot            = availableSlots.Dequeue();
                    renderModelEffectSlot.EffectName = effectName;
                    effectNameToSlot[effectName]     = renderModelEffectSlot;
                }
                else
                {
                    effectNameToSlot[effectName] = renderModelEffectSlot = new RenderModelEffectSlot(effectName, effectNameToSlot.Count);
                }
            }

            renderModelEffectSlot.ReferenceCount++;
            return(renderModelEffectSlot.Slot);
        }