/// <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(GorgonTextureUnorderedAccessView view) { if (view._texture3D == null) { throw new InvalidCastException(string.Format(Resources.GORGFX_VIEW_RESOURCE_NOT_TEXTURE, "3D")); } return(view._texture3D); }
/// <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); } }