void CreateFontsTexture() { var io = ImGui.GetIO(); byte *pixels; int width, height; io.Fonts.GetTexDataAsRGBA32(out pixels, out width, out height); var texDesc = new Texture2DDescription { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = Format.R8G8B8A8_UNorm, SampleDescription = new SampleDescription { Count = 1 }, Usage = Vortice.Direct3D11.Usage.Default, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None }; var subResource = new SubresourceData { DataPointer = (IntPtr)pixels, Pitch = texDesc.Width * 4, SlicePitch = 0 }; var texture = device.CreateTexture2D(texDesc, new[] { subResource }); var resViewDesc = new ShaderResourceViewDescription { Format = Format.R8G8B8A8_UNorm, ViewDimension = ShaderResourceViewDimension.Texture2D, Texture2D = new Texture2DShaderResourceView { MipLevels = texDesc.MipLevels, MostDetailedMip = 0 } }; fontTextureView = device.CreateShaderResourceView(texture, resViewDesc); texture.Release(); io.Fonts.TexID = RegisterTexture(fontTextureView); var samplerDesc = new SamplerDescription { Filter = Filter.MinMagMipLinear, AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, MipLODBias = 0f, ComparisonFunction = ComparisonFunction.Always, MinLOD = 0f, MaxLOD = 0f }; fontSampler = device.CreateSamplerState(samplerDesc); }
private void StartDesktopDuplicator(int adapterId, int outputId) { var adapter = factory.GetAdapter1(adapterId); D3D11.D3D11CreateDevice(adapter, DriverType.Unknown, DeviceCreationFlags.None, s_featureLevels, out device); var output = adapter.GetOutput(outputId); var output1 = output.QueryInterface <IDXGIOutput1>(); var bounds = output1.Description.DesktopCoordinates; var width = bounds.Right - bounds.Left; var height = bounds.Bottom - bounds.Top; var textureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width / 2, Height = height / 2, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = Usage.Staging }; stagingTexture = device.CreateTexture2D(textureDesc); var smallerTextureDesc = new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.None, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.GenerateMips, MipLevels = 4, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = Usage.Default }; smallerTexture = device.CreateTexture2D(smallerTextureDesc); smallerTextureView = device.CreateShaderResourceView(smallerTexture); duplication = output1.DuplicateOutput(device); }
public static IComObject <ID3D11ShaderResourceView> CreateShaderResourceView(this ID3D11Device device, ID3D11Resource resource, D3D11_SHADER_RESOURCE_VIEW_DESC?desc = null) { if (device == null) { throw new ArgumentNullException(nameof(device)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } using (var mem = new ComMemory(desc)) { device.CreateShaderResourceView(resource, mem.Pointer, out var view).ThrowOnError(); return(new ComObject <ID3D11ShaderResourceView>(view)); } }
public D3D11TextureView(D3D11GraphicsDevice gd, ref TextureViewDescription description) : base(ref description) { ID3D11Device device = gd.Device; D3D11Texture d3dTex = Util.AssertSubtype <Texture, D3D11Texture>(description.Target); ShaderResourceViewDescription srvDesc = D3D11Util.GetSrvDesc( d3dTex, description.BaseMipLevel, description.MipLevels, description.BaseArrayLayer, description.ArrayLayers, Format); ShaderResourceView = device.CreateShaderResourceView(d3dTex.DeviceTexture, srvDesc); if ((d3dTex.Usage & TextureUsage.Storage) == TextureUsage.Storage) { UnorderedAccessViewDescription uavDesc = new UnorderedAccessViewDescription(); uavDesc.Format = D3D11Formats.GetViewFormat(d3dTex.DxgiFormat); if ((d3dTex.Usage & TextureUsage.Cubemap) == TextureUsage.Cubemap) { throw new NotSupportedException(); } else if (d3dTex.Depth == 1) { if (d3dTex.ArrayLayers == 1) { if (d3dTex.Type == TextureType.Texture1D) { uavDesc.ViewDimension = UnorderedAccessViewDimension.Texture1D; uavDesc.Texture1D.MipSlice = (int)description.BaseMipLevel; } else { uavDesc.ViewDimension = UnorderedAccessViewDimension.Texture2D; uavDesc.Texture2D.MipSlice = (int)description.BaseMipLevel; } } else { if (d3dTex.Type == TextureType.Texture1D) { uavDesc.ViewDimension = UnorderedAccessViewDimension.Texture1DArray; uavDesc.Texture1DArray.MipSlice = (int)description.BaseMipLevel; uavDesc.Texture1DArray.FirstArraySlice = (int)description.BaseArrayLayer; uavDesc.Texture1DArray.ArraySize = (int)description.ArrayLayers; } else { uavDesc.ViewDimension = UnorderedAccessViewDimension.Texture2DArray; uavDesc.Texture2DArray.MipSlice = (int)description.BaseMipLevel; uavDesc.Texture2DArray.FirstArraySlice = (int)description.BaseArrayLayer; uavDesc.Texture2DArray.ArraySize = (int)description.ArrayLayers; } } } else { uavDesc.ViewDimension = UnorderedAccessViewDimension.Texture3D; uavDesc.Texture3D.MipSlice = (int)description.BaseMipLevel; // Map the entire range of the 3D texture. uavDesc.Texture3D.FirstWSlice = 0; uavDesc.Texture3D.WSize = (int)d3dTex.Depth; } UnorderedAccessView = device.CreateUnorderedAccessView(d3dTex.DeviceTexture, uavDesc); } }