Structure holding details of a license to use a temporary shared buffer.
Esempio n. 1
0
        /// <summary>
        ///		Internal method that forces the release of copies of a given buffer.
        /// </summary>
        /// <remarks>
        ///		This usually means that the buffer which the copies are based on has
        ///		been changed in some fundamental way, and the owner of the original
        ///		wishes to make that known so that new copies will reflect the changes.
        /// </remarks>
        /// <param name="sourceBuffer">Buffer to release temp copies of.</param>
        internal void ForceReleaseBufferCopies(HardwareVertexBuffer sourceBuffer)
        {
            // erase the copies which are licensed out
            for (int i = tempVertexBufferLicenses.Count - 1; i >= 0; i--)
            {
                VertexBufferLicense vbl =
                    (VertexBufferLicense)tempVertexBufferLicenses[i];

                if (vbl.originalBuffer == sourceBuffer)
                {
                    // Just tell the owner that this is being released
                    vbl.licensee.LicenseExpired(vbl.buffer);
                    tempVertexBufferLicenses.RemoveAt(i);
                }
            }

            // TODO: Verify this works
            foreach (DictionaryEntry entry in freeTempVertexBufferMap)
            {
                if (entry.Key == sourceBuffer)
                {
                    ArrayList list = (ArrayList)entry.Value;
                    list.Clear();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Internal method for releasing all temporary buffers which have been
        ///     allocated using <see cref="BufferLicenseRelease.Automatic"/> is called by Axiom.
        /// </summary>
        public virtual void ReleaseBufferCopies(bool forceFreeUnused)
        {
            int numUnused = freeTempVertexBufferMap.Count;
            int numUsed   = tempVertexBufferLicenses.Count;

            for (int i = tempVertexBufferLicenses.Count - 1; i >= 0; i--)
            {
                VertexBufferLicense vbl =
                    (VertexBufferLicense)tempVertexBufferLicenses[i];

                // only release licenses set to auto release
                if (vbl.licenseType == BufferLicenseRelease.Automatic &&
                    (forceFreeUnused || --vbl.expiredDelay <= 0))
                {
                    vbl.licensee.LicenseExpired(vbl.buffer);
                    IList list = (IList)freeTempVertexBufferMap[vbl.originalBuffer];

                    Debug.Assert(list != null, "There is no license recorded for this buffer.");

                    // push the buffer back into the free list
                    list.Add(vbl.buffer);

                    // remove the license for this buffer
                    tempVertexBufferLicenses.RemoveAt(i);
                }
            }
            // Check whether or not free unused temporary vertex buffers.
            if (forceFreeUnused)
            {
                FreeUnusedBufferCopies();
                underUsedFrameCount = 0;
            }
            else
            {
                if (numUsed < numUnused)
                {
                    // Free temporary vertex buffers if too many unused for a long time.
                    // Do overall temporary vertex buffers instead of per source buffer
                    // to avoid overhead.
                    ++underUsedFrameCount;
                    if (underUsedFrameCount >= UnderUsedFrameThreshold)
                    {
                        FreeUnusedBufferCopies();
                        underUsedFrameCount = 0;
                    }
                }
                else
                {
                    underUsedFrameCount = 0;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     Tell engine that the vertex buffer copy intent to reuse.
        /// </summary>
        /// <remarks>
        ///     Ogre internal keep an expired delay counter of BLT_AUTOMATIC_RELEASE
        ///     buffers, when the counter count down to zero, it'll release for other
        ///     purposes later. But you can use this function to reset the counter to
        ///     the internal configured value, keep the buffer not get released for
        ///     some frames.
        /// </remarks>
        /// <param name="bufferCopy" The buffer copy. The caller is expected to keep this
        ///     buffer copy for use.</param>
        public void TouchVertexBufferCopy(HardwareVertexBuffer bufferCopy)
        {
            for (int i = 0; i < tempVertexBufferLicenses.Count; i++)
            {
                VertexBufferLicense vbl = (VertexBufferLicense)tempVertexBufferLicenses[i];
                if (vbl.buffer != bufferCopy)
                {
                    continue;
                }
                Debug.Assert(vbl.licenseType == BufferLicenseRelease.Automatic);

                vbl.expiredDelay = expiredDelayFrameThreshold;
            }
        }
Esempio n. 4
0
 /// <summary>
 ///     Manually release a vertex buffer copy for others to subsequently use.
 /// </summary>
 /// <remarks>
 ///     Only required if the original call to <see cref="AllocateVertexBufferCopy"/>
 ///     included a licenseType of <see cref="BufferLicenseRelease.Manual"/>.
 /// </remarks>
 /// <param name="bufferCopy">
 ///     The buffer copy. The caller is expected to no longer use this reference,
 ///     since another user may well begin to modify the contents of the buffer.
 /// </param>
 public virtual void ReleaseVertexBufferCopy(HardwareVertexBuffer bufferCopy)
 {
     for (int i = 0; i < tempVertexBufferLicenses.Count; i++)
     {
         VertexBufferLicense vbl = (VertexBufferLicense)tempVertexBufferLicenses[i];
         if (vbl.buffer != bufferCopy)
         {
             continue;
         }
         vbl.licensee.LicenseExpired(bufferCopy);
         tempVertexBufferLicenses.RemoveAt(i);
         return;
     }
 }