Esempio n. 1
0
        /// <summary>
        /// Perform a copy from the provided handle to this one, or perform a deferred copy if none is provided.
        /// </summary>
        /// <param name="fromHandle">The handle to copy from. If not provided, this method will copy from and clear the deferred copy instead</param>
        /// <returns>True if the copy was performed, false otherwise</returns>
        public bool Copy(TextureGroupHandle fromHandle = null)
        {
            bool result = false;

            if (fromHandle == null)
            {
                fromHandle = DeferredCopy;

                if (fromHandle != null && fromHandle._bindCount == 0)
                {
                    // Repeat the copy in future if the bind count is greater than 0.
                    DeferredCopy = null;
                }
            }

            if (fromHandle != null)
            {
                // If the copy texture is dirty, do not copy. Its data no longer matters, and this handle should also be dirty.
                if (!fromHandle.CheckDirty())
                {
                    Texture from = fromHandle._group.Storage;
                    Texture to   = _group.Storage;

                    if (from.ScaleFactor != to.ScaleFactor)
                    {
                        to.PropagateScale(from);
                    }

                    from.HostTexture.CopyTo(
                        to.HostTexture,
                        fromHandle._firstLayer,
                        _firstLayer,
                        fromHandle._firstLevel,
                        _firstLevel);

                    Modified = true;

                    _group.RegisterAction(this);

                    result = true;
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Perform a copy from the provided handle to this one, or perform a deferred copy if none is provided.
        /// </summary>
        /// <param name="context">GPU context to register sync for modified handles</param>
        /// <param name="fromHandle">The handle to copy from. If not provided, this method will copy from and clear the deferred copy instead</param>
        /// <returns>True if the copy was performed, false otherwise</returns>
        public bool Copy(GpuContext context, TextureGroupHandle fromHandle = null)
        {
            bool result     = false;
            bool shouldCopy = false;

            if (fromHandle == null)
            {
                fromHandle = DeferredCopy;

                if (fromHandle != null)
                {
                    // Only copy if the copy texture is still modified.
                    // It will be set as unmodified if new data is written from CPU, as the data previously in the texture will flush.
                    // It will also set as unmodified if a copy is deferred to it.

                    shouldCopy = fromHandle.Modified;

                    if (fromHandle._bindCount == 0)
                    {
                        // Repeat the copy in future if the bind count is greater than 0.
                        DeferredCopy = null;
                    }
                }
            }
            else
            {
                // Copies happen directly when initializing a copy dependency.
                // If dirty, do not copy. Its data no longer matters, and this handle should also be dirty.
                // Also, only direct copy if the data in this handle is not already modified (can be set by copies from modified handles).
                shouldCopy = !fromHandle.CheckDirty() && (fromHandle.Modified || !Modified);
            }

            if (shouldCopy)
            {
                Texture from = fromHandle._group.Storage;
                Texture to   = _group.Storage;

                if (from.ScaleFactor != to.ScaleFactor)
                {
                    to.PropagateScale(from);
                }

                from.HostTexture.CopyTo(
                    to.HostTexture,
                    fromHandle._firstLayer,
                    _firstLayer,
                    fromHandle._firstLevel,
                    _firstLevel);

                if (fromHandle.Modified)
                {
                    Modified = true;

                    RegisterSync(context);
                }

                result = true;
            }

            return(result);
        }