public ITexture CreateTexture(int width, int height, Format format, bool createMipMaps = true) { const TextureViewType type = TextureViewType.ShaderResource; var resource = (Texture2D)Create2DTexture(width, height, format, type, createMipMaps); return(new D3D11Texture(_graphicsDevice, resource, width, height, 0, false, resource.Description.MipLevels, type)); }
public ITexture CreateRenderTarget(int width, int height, Format format) { const TextureViewType type = TextureViewType.RenderTarget | TextureViewType.ShaderResource; var resource = Create2DTexture(width, height, format, type); return(new D3D11Texture(_graphicsDevice, resource, width, height, 0, false, 1, type)); }
/// <summary>To initialize this structure with default value, use this constructor. The argument value is ignored.</summary> /// <remarks>This is only here because C# doesn’t support parameterless constructors for structures.</remarks> public TextureViewDesc(bool unused) { baseStruct = new DeviceObjectAttribs(true); ViewType = TextureViewType.Undefined; TextureDim = ResourceDimension.Undefined; Format = TextureFormat.Unknown; MostDetailedMip = 0; NumMipLevels = 0; FirstArraySlice = 0; FirstDepthSlice = default(int); AccessFlags = UavAccessFlag.Unspecified; Flags = TextureViewFlags.None; }
private static BindFlags TextureViewTypeToBindFlags(TextureViewType type) { var bindFlags = BindFlags.None; if ((type & TextureViewType.DepthStencil) > 0) { bindFlags |= BindFlags.DepthStencil; } if ((type & TextureViewType.RenderTarget) > 0) { bindFlags |= BindFlags.RenderTarget; } if ((type & TextureViewType.ShaderResource) > 0) { bindFlags |= BindFlags.ShaderResource; } return(bindFlags); }
public D3D11Texture(D3D11GraphicsDevice graphicsDevice, Resource nativeResource, int width, int height, int depth, bool isCube, int mipLevels, TextureViewType type) { _graphicsDevice = graphicsDevice; _nativeResource = nativeResource; View = new D3D11TextureView(graphicsDevice, _nativeResource, width, height, depth, isCube, mipLevels, type); }
public D3D11TextureView(D3D11GraphicsDevice graphicsDevice, D3D11Resource resource, int width, int height, int depth, bool isCube, int mipLevels, TextureViewType type) { if (type.HasFlag(TextureViewType.RenderTarget)) { _nativeRenderTargetView = new RenderTargetView(graphicsDevice, resource); } if (type.HasFlag(TextureViewType.ShaderResource)) { var srvDescription = new ShaderResourceViewDescription(); if (depth > 0 && height > 0 && width > 0) { srvDescription.Format = ((Texture3D)resource).Description.Format; srvDescription.Texture1D.MipLevels = mipLevels; srvDescription.Dimension = ShaderResourceViewDimension.Texture3D; } else if (depth == 0 && height > 0 && width > 0) { srvDescription.Format = ((Texture2D)resource).Description.Format; srvDescription.Texture2D.MipLevels = mipLevels; srvDescription.Dimension = ShaderResourceViewDimension.Texture2D; if (isCube) { srvDescription.Dimension = ShaderResourceViewDimension.TextureCube; } } else if (depth == 0 && height == 0 && width > 0) { srvDescription.Format = ((Texture1D)resource).Description.Format; srvDescription.Texture3D.MipLevels = mipLevels; srvDescription.Dimension = ShaderResourceViewDimension.Texture1D; } _nativeShaderResourceView = new ShaderResourceView(graphicsDevice, resource, srvDescription); } if (type.HasFlag(TextureViewType.DepthStencil)) { _nativeDepthStencilView = new DepthStencilView(graphicsDevice, resource); } }