Пример #1
0
        /// <summary>
        /// Function to retrieve a texture view.
        /// </summary>
        /// <param name="format">Format of the view.</param>
        /// <param name="firstMip">First mip level for the view.</param>
        /// <param name="mipCount">Number of mip levels to view.</param>
        /// <param name="arrayIndex">First array index for the view.</param>
        /// <param name="arrayCount">Number of array indices to view.</param>
        /// <returns>The cached texture shader view.</returns>
        public GorgonTextureShaderView GetTextureView(BufferFormat format,
                                                      int firstMip,
                                                      int mipCount,
                                                      int arrayIndex,
                                                      int arrayCount)
        {
            var buffer = (GorgonTexture)_resource;
            var key    = new ViewKey(format,
                                     firstMip,
                                     mipCount,
                                     buffer.ResourceType != ResourceType.Texture3D ? arrayIndex : -1,
                                     buffer.ResourceType != ResourceType.Texture3D ? arrayCount : -1,
                                     buffer.Settings.IsTextureCube);

            lock (_syncLock)
            {
                GorgonTextureShaderView result;

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

                result = new GorgonTextureShaderView(buffer,
                                                     format,
                                                     firstMip,
                                                     mipCount,
                                                     buffer.ResourceType != ResourceType.Texture3D ? arrayIndex : -1,
                                                     buffer.ResourceType != ResourceType.Texture3D ? arrayCount : -1);
                result.Initialize();
                _textureViews.Add(key, result);

                return(result);
            }
        }