예제 #1
0
        /// <summary>
        /// Function to perform an unlock.
        /// </summary>
        /// <param name="lockData">Lock data to remove.</param>
        public void Unlock(GorgonTextureLockData lockData)
        {
            lock (_syncLock)
            {
                var key = new LockCacheKey(lockData.Graphics, lockData.MipLevel, lockData.ArrayIndex);
                GorgonTextureLockData result;

                if (!_locks.TryGetValue(key, out result))
                {
                    return;
                }

                lockData.Graphics.Context.UnmapSubresource(_texture.D3DResource,
                                                           D3D.Resource.CalculateSubResourceIndex(lockData.MipLevel,
                                                                                                  lockData.ArrayIndex,
                                                                                                  _texture.Settings.MipCount));

                _locks.Remove(key);
            }
        }
예제 #2
0
        /// <summary>
        /// Function to lock a sub resource.
        /// </summary>
        /// <param name="lockFlags">Flags used to lock the data.</param>
        /// <param name="mipLevel">Mip map level to lock.</param>
        /// <param name="arrayIndex">Array index to lock (1D/2D textures only).</param>
        /// <param name="context">Graphics context to use for the lock.</param>
        /// <returns>The locking data.</returns>
        public GorgonTextureLockData Lock(BufferLockFlags lockFlags, int mipLevel, int arrayIndex, GorgonGraphics context)
        {
            lock (_syncLock)
            {
                var key = new LockCacheKey(context, mipLevel, arrayIndex);
                GorgonTextureLockData result;

                if (_locks.TryGetValue(key, out result))
                {
                    return(result);
                }

                switch (_texture.ResourceType)
                {
                case ResourceType.Texture1D:
                case ResourceType.Texture2D:
                case ResourceType.Texture3D:
                    DX.DataStream lockStream;

                    DX.DataBox box = context.Context.MapSubresource(_texture.D3DResource,
                                                                    D3D.Resource.CalculateSubResourceIndex(mipLevel, arrayIndex, _texture.Settings.MipCount),
                                                                    GetMapMode(lockFlags),
                                                                    D3D.MapFlags.None,
                                                                    out lockStream);

                    result = new GorgonTextureLockData(context, _texture, this, box, mipLevel, arrayIndex);

                    _locks.Add(key, result);
                    break;

                default:
                    throw new GorgonException(GorgonResult.CannotCreate,
                                              string.Format(Resources.GORGFX_RESOURCE_INVALID, _texture.ResourceType));
                }

                return(result);
            }
        }