Exemple #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);
            }
        }
Exemple #2
0
        /// <summary>
        /// Function to convert this view into its attached 3D texture.
        /// </summary>
        /// <param name="view">View to convert.</param>
        /// <returns>The texture attached to the view.</returns>
        /// <exception cref="System.InvalidCastException">Thrown when the view is not attached to a 3D texture.</exception>
        public static GorgonTexture3D ToTexture3D(GorgonTextureShaderView view)
        {
            if (view._texture3D == null)
            {
                throw new InvalidCastException(string.Format(Resources.GORGFX_VIEW_RESOURCE_NOT_TEXTURE, "3D"));
            }

            return(view._texture3D);
        }