/// <summary>
        /// Explicit operator to convert this view into its attached index buffer.
        /// </summary>
        /// <param name="view">View to convert.</param>
        /// <returns>The attached buffer.</returns>
        /// <exception cref="System.InvalidCastException">Thrown when the buffer is not a index buffer.</exception>
        public static GorgonIndexBuffer ToIndexBuffer(GorgonBufferUnorderedAccessView view)
        {
            if (view._indexBuffer == null)
            {
                throw new InvalidCastException(string.Format(Resources.GORGFX_VIEW_RESOURCE_NOT_BUFFER, "index"));
            }

            return(view._indexBuffer);
        }
示例#2
0
        /// <summary>
        /// Function to create/retrieve an unordered access view in the cache.
        /// </summary>
        /// <param name="format">Format of the unordered access view.</param>
        /// <param name="mipSliceElementStart">Mip slice for a texture, element start for a buffer.</param>
        /// <param name="arrayIndexElementCount">Array index for a texture, element count for a buffer.</param>
        /// <param name="arrayCount">Array count for a texture.</param>
        /// <param name="viewType">View type for structured buffers.</param>
        /// <param name="isRaw">TRUE for raw views, FALSE for normal.</param>
        /// <returns>The cached unordered access view.</returns>
        public GorgonUnorderedAccessView GetUnorderedAccessView(BufferFormat format,
                                                                int mipSliceElementStart,
                                                                int arrayIndexElementCount,
                                                                int arrayCount,
                                                                UnorderedAccessViewType viewType,
                                                                bool isRaw)
        {
            var key = new ViewKey(format, mipSliceElementStart, arrayIndexElementCount, arrayCount, ((int)viewType) + (isRaw ? 10 : 0));

            lock (_syncLock)
            {
                GorgonUnorderedAccessView result;

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

                switch (_resource.ResourceType)
                {
                case ResourceType.Buffer:
                    if (_resource is GorgonStructuredBuffer)
                    {
                        result = new GorgonStructuredBufferUnorderedAccessView(_resource,
                                                                               mipSliceElementStart,
                                                                               arrayIndexElementCount,
                                                                               viewType);
                    }
                    else
                    {
                        result = new GorgonBufferUnorderedAccessView(_resource, format, mipSliceElementStart, arrayIndexElementCount, isRaw);
                    }
                    break;

                case ResourceType.Texture1D:
                case ResourceType.Texture2D:
                case ResourceType.Texture3D:
                    result = new GorgonTextureUnorderedAccessView(_resource, format, mipSliceElementStart, arrayIndexElementCount, arrayCount);
                    break;
                }

                // This should never happen.
                if (result == null)
                {
                    throw new GorgonException(GorgonResult.CannotCreate,
                                              string.Format(Resources.GORGFX_IMAGE_TYPE_INVALID, _resource.ResourceType));
                }

                result.Initialize();
                _unorderedViews.Add(key, result);

                return(result);
            }
        }