/// <summary> /// ピクセル配列からテクスチャを生成する。 /// </summary> /// <param name="device">Direct3D10デバイス。</param> /// <param name="width">横幅。</param> /// <param name="height">横幅。</param> /// <param name="format">フォーマット。</param> /// <param name="pixels">ピクセル配列。</param> /// <param name="bytesPerPixel">1ピクセルあたりのバイトサイズ。</param> /// <returns>生成されたテクスチャ。</returns> public static Texture2D MakeTexture( Device device, int width, int height, DXGI.Format format, Array pixels, int bytesPerPixel) { // テクスチャ情報作成 var desc = new Texture2DDescription { ArraySize = 1, Format = format, Width = width, Height = height, MipLevels = 1, SampleDescription = new DXGI.SampleDescription(1, 0), }; // テクスチャ生成 using (var s = new DataStream(pixels, true, false)) { var data = new DataRectangle(bytesPerPixel * width, s); return(new Texture2D(device, desc, data)); } }
protected override void OnUpdate(DX11RenderContext context) { //Grab a temp target if enabled TexInfo ti = this.rtm.GetRenderTarget(context); if (ti.w != this.width || ti.h != this.height || !this.targets.ContainsKey(context) || this.invalidate || ti.format != this.format) { this.invalidate = false; this.width = ti.w; this.height = ti.h; this.format = ti.format; this.depthmanager.NeedReset = true; if (targets.ContainsKey(context)) { context.ResourcePool.Unlock(targets[context]); } if (targetresolve.ContainsKey(context)) { context.ResourcePool.Unlock(targetresolve[context]); } int aacount = Convert.ToInt32(this.FInAASamplesPerPixel[0].Name); int aaquality = 0; if (aacount > 1) { List <SampleDescription> sds = context.GetMultisampleFormatInfo(ti.format); int maxlevels = sds[sds.Count - 1].Count; if (aacount > maxlevels) { FHost.Log(TLogType.Warning, "Multisample count too high for this format, reverted to: " + maxlevels); aacount = maxlevels; } DX11RenderTarget2D temptarget = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(aacount, aaquality), this.FInDoMipMaps[0], this.FInMipLevel[0]).Element; DX11RenderTarget2D temptargetresolve = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(1, 0), this.FInDoMipMaps[0], this.FInMipLevel[0]).Element; targets[context] = temptarget; targetresolve[context] = temptargetresolve; this.FOutBuffers[0][context] = temptargetresolve; this.FOutAABuffers[0][context] = temptarget; } else { //Bind both texture as same output DX11RenderTarget2D temptarget = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(aacount, aaquality), this.FInDoMipMaps[0], this.FInMipLevel[0]).Element; targets[context] = temptarget; this.FOutBuffers[0][context] = temptarget; this.FOutAABuffers[0][context] = temptarget; } } }
TColorFormat ToOpenCVFormat(SlimDX.DXGI.Format format) { switch (format) { case Format.B8G8R8A8_UNorm: case Format.B8G8R8X8_UNorm: case Format.B8G8R8A8_UNorm_SRGB: case Format.B8G8R8X8_UNorm_SRGB: case Format.B8G8R8A8_Typeless: case Format.R8G8B8A8_Typeless: case Format.R8G8B8A8_UInt: case Format.R8G8B8A8_UNorm: case Format.R8G8B8A8_UNorm_SRGB: return(TColorFormat.RGBA8); case Format.R16_UInt: case Format.R16_UNorm: case Format.R16_Typeless: return(TColorFormat.L16); case Format.R32G32B32A32_Float: return(TColorFormat.RGBA32F); case Format.R32_Float: return(TColorFormat.L32F); case Format.R32_SInt: return(TColorFormat.L32S); default: return(TColorFormat.UnInitialised); } }
private bool CheckSurfaceFormat(SurfaceFormat surfaceFormat, int sampleCount) { DXGI.Format format = D3D10Helper.ToD3DSurfaceFormat(surfaceFormat); D3D.FormatSupport support = _graphicsDevice.CheckFormatSupport(format); if (sampleCount > 0) { bool correctSamples = CheckMultiSampleQuality(format, sampleCount); return(correctSamples && ((support & D3D.FormatSupport.RenderTarget) == D3D.FormatSupport.RenderTarget) && ((support & D3D.FormatSupport.FormatMultisampleRenderTargetSupport) == D3D.FormatSupport.FormatMultisampleRenderTargetSupport)); } return((support & D3D.FormatSupport.RenderTarget) == D3D.FormatSupport.RenderTarget); }
internal static SurfaceFormat FromD3DSurfaceFormat(DXGI.Format f) { switch (f) { case DXGI.Format.R8G8B8A8_UNorm: return(SurfaceFormat.Color); case DXGI.Format.B5G5R5A1_UNorm: return(SurfaceFormat.BGRA5551); case DXGI.Format.B5G6R5_UNorm: return(SurfaceFormat.BGR565); case DXGI.Format.R32_Float: return(SurfaceFormat.Single); case DXGI.Format.R32G32_Float: return(SurfaceFormat.Vector2); case DXGI.Format.R32G32B32_Float: return(SurfaceFormat.Vector3); case DXGI.Format.R32G32B32A32_Float: return(SurfaceFormat.Vector4); case DXGI.Format.A8_UNorm: return(SurfaceFormat.Alpha8); case DXGI.Format.R16G16_UNorm: return(SurfaceFormat.RG32); case DXGI.Format.R10G10B10A2_UNorm: return(SurfaceFormat.RGBA1010102); case DXGI.Format.R16G16B16A16_UNorm: return(SurfaceFormat.RGBA64); case DXGI.Format.BC1_UNorm: return(SurfaceFormat.DXT1); case DXGI.Format.BC2_UNorm: return(SurfaceFormat.DXT3); case DXGI.Format.BC3_UNorm: return(SurfaceFormat.DXT5); default: throw new ArgumentException("Invalid DXGI format, cannot convert to engine Tesla SurfaceFormat"); } }
public static Format ToDirect3D9(DXGI.Format format) { switch (format) { case SlimDX.DXGI.Format.R8G8B8A8_UNorm: return(Format.A8R8G8B8); case SlimDX.DXGI.Format.B5G6R5_UNorm: return(Format.R5G6B5); case SlimDX.DXGI.Format.B5G5R5A1_UNorm: return(Format.A1R5G5B5); case SlimDX.DXGI.Format.A8_UNorm: return(Format.A8); case SlimDX.DXGI.Format.R10G10B10A2_UNorm: return(Format.A2B10G10R10); case SlimDX.DXGI.Format.B8G8R8A8_UNorm: return(Format.A8B8G8R8); case SlimDX.DXGI.Format.R16G16_UNorm: return(Format.G16R16); case SlimDX.DXGI.Format.R16G16B16A16_UNorm: return(Format.A16B16G16R16); case SlimDX.DXGI.Format.R16_Float: return(Format.R16F); case SlimDX.DXGI.Format.R16G16_Float: return(Format.G16R16F); case SlimDX.DXGI.Format.R16G16B16A16_Float: return(Format.A16B16G16R16F); case SlimDX.DXGI.Format.R32_Float: return(Format.R32F); case SlimDX.DXGI.Format.R32G32_Float: return(Format.G32R32F); case SlimDX.DXGI.Format.R32G32B32A32_Float: return(Format.A32B32G32R32F); } return(Format.Unknown); }
private bool CheckDepthFormat(DepthFormat depthFormat, int sampleCount) { if (depthFormat == DepthFormat.None) { return(true); } DXGI.Format format = D3D10Helper.ToD3DDepthFormat(depthFormat); D3D.FormatSupport support = _graphicsDevice.CheckFormatSupport(format); if (sampleCount > 0) { bool correctSamples = CheckMultiSampleQuality(format, sampleCount); return(correctSamples && ((support & D3D.FormatSupport.DepthStencil) == D3D.FormatSupport.DepthStencil) && ((support & D3D.FormatSupport.FormatMultisampleRenderTargetSupport) == D3D.FormatSupport.FormatMultisampleRenderTargetSupport)); } return((support & D3D.FormatSupport.DepthStencil) == D3D.FormatSupport.DepthStencil); }
public static int GetColorBits(DXGI.Format format) { switch (format) { case SlimDX.DXGI.Format.R32G32B32A32_Float: case SlimDX.DXGI.Format.R32G32B32A32_SInt: case SlimDX.DXGI.Format.R32G32B32A32_Typeless: case SlimDX.DXGI.Format.R32G32B32A32_UInt: case SlimDX.DXGI.Format.R32G32B32_Float: case SlimDX.DXGI.Format.R32G32B32_SInt: case SlimDX.DXGI.Format.R32G32B32_Typeless: case SlimDX.DXGI.Format.R32G32B32_UInt: return(32); case SlimDX.DXGI.Format.R16G16B16A16_Float: case SlimDX.DXGI.Format.R16G16B16A16_SInt: case SlimDX.DXGI.Format.R16G16B16A16_SNorm: case SlimDX.DXGI.Format.R16G16B16A16_Typeless: case SlimDX.DXGI.Format.R16G16B16A16_UInt: case SlimDX.DXGI.Format.R16G16B16A16_UNorm: return(16); case SlimDX.DXGI.Format.R10G10B10A2_Typeless: case SlimDX.DXGI.Format.R10G10B10A2_UInt: case SlimDX.DXGI.Format.R10G10B10A2_UNorm: return(10); case SlimDX.DXGI.Format.R8G8B8A8_SInt: case SlimDX.DXGI.Format.R8G8B8A8_SNorm: case SlimDX.DXGI.Format.R8G8B8A8_Typeless: case SlimDX.DXGI.Format.R8G8B8A8_UInt: case SlimDX.DXGI.Format.R8G8B8A8_UNorm: case SlimDX.DXGI.Format.R8G8B8A8_UNorm_SRGB: return(8); case SlimDX.DXGI.Format.B5G5R5A1_UNorm: case SlimDX.DXGI.Format.B5G6R5_UNorm: return(5); default: return(0); } }
/// <summary> /// Queries if the specified surface format is valid for texture resources. /// </summary> /// <param name="surfaceFormat">Surface format</param> /// <param name="texType">The texture type</param> /// <returns>True if valid, false otherwise</returns> public bool QueryTextureFormat(SurfaceFormat surfaceFormat, TextureDimensions texType) { DXGI.Format format = D3D10Helper.ToD3DSurfaceFormat(surfaceFormat); D3D.FormatSupport support = _graphicsDevice.CheckFormatSupport(format); switch (texType) { case TextureDimensions.One: return((support & D3D.FormatSupport.Texture1D) == D3D.FormatSupport.Texture1D); case TextureDimensions.Two: return((support & D3D.FormatSupport.Texture2D) == D3D.FormatSupport.Texture2D); case TextureDimensions.Three: return((support & D3D.FormatSupport.Texture3D) == D3D.FormatSupport.Texture3D); case TextureDimensions.Cube: return((support & D3D.FormatSupport.TextureCube) == D3D.FormatSupport.TextureCube); } return(false); }
internal static DepthFormat FromD3DDepthFormat(DXGI.Format f) { switch (f) { case DXGI.Format.D32_Float: return(DepthFormat.Depth32); case DXGI.Format.D32_Float_S8X24_UInt: return(DepthFormat.Depth24); case DXGI.Format.D24_UNorm_S8_UInt: return(DepthFormat.Depth24Stencil8); case DXGI.Format.D16_UNorm: return(DepthFormat.Depth16); default: throw new ArgumentException("Invalid DXGI depth format, cannot convert to Tesla DepthFormat"); } }
public int GetSize(SlimDX.DXGI.Format format) { return(this.formatsize[format]); }
public static DX11Texture2D CreateImmutable(DX11RenderContext context, int width, int height, SlimDX.DXGI.Format format, int pitch, SlimDX.DataStream initialData) { Texture2DDescription desc = new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = height, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Immutable, Width = width }; SlimDX.DataRectangle dataRectangle = new SlimDX.DataRectangle(pitch, initialData); Texture2D texture = new Texture2D(context.Device, desc, dataRectangle); try { ShaderResourceView shaderView = new ShaderResourceView(context.Device, texture); return(TakeOwnership(context, texture, shaderView)); } catch { texture.Dispose(); //Avoid partial leak in case of failure, that should be really rare but could happen throw; } }
public static DX11Texture2D CreateImmutable(DX11RenderContext context, int width, int height, SlimDX.DXGI.Format format, int pitch, IntPtr initialData) { var dataStream = new SlimDX.DataStream(initialData, pitch * height, true, false); return(CreateImmutable(context, width, height, format, pitch, dataStream)); }
public static int GetPixelSizeInBytes(SlimDX.DXGI.Format format) { SharpDX.DXGI.Format sf = (SharpDX.DXGI.Format)format; return(SharpDX.DXGI.FormatHelper.SizeOfInBytes(sf)); }
private bool CheckMultiSampleQuality(DXGI.Format format, int sampleCount) { return(_graphicsDevice.CheckMultisampleQualityLevels(format, sampleCount) > 0); }
private void CreateSwapChain(IntPtr windowHandle, PresentationParameters presentParams) { DXGI.Format surfaceFormat = D3D10Helper.ToD3DSurfaceFormat(presentParams.BackBufferFormat); switch (presentParams.PresentInterval) { case PresentInterval.Immediate: _interval = 0; break; case PresentInterval.One: _interval = 1; break; case PresentInterval.Two: _interval = 2; break; } DXGI.SampleDescription sampleDesc = new DXGI.SampleDescription(1, 0); bool msEnabled = false; if (presentParams.MultiSampleCount > 1) { sampleDesc.Count = presentParams.MultiSampleCount; int q = _graphicsDevice.CheckMultisampleQualityLevels(surfaceFormat, presentParams.MultiSampleCount); if (presentParams.MultiSampleQuality < q) { sampleDesc.Quality = presentParams.MultiSampleQuality; } else { sampleDesc.Quality = q - 1; } msEnabled = true; } DXGI.SwapEffect swap; if (presentParams.RenderTargetUsage == RenderTargetUsage.PlatformDefault) { if (msEnabled) { swap = DXGI.SwapEffect.Discard; } else { swap = DXGI.SwapEffect.Sequential; } } else if (presentParams.RenderTargetUsage == RenderTargetUsage.DiscardContents) { swap = DXGI.SwapEffect.Discard; } else { swap = DXGI.SwapEffect.Sequential; } DXGI.ModeDescription modeDesc = new DXGI.ModeDescription(presentParams.BackBufferWidth, presentParams.BackBufferHeight, new SDX.Rational(60, 1), surfaceFormat); modeDesc.Scaling = DXGI.DisplayModeScaling.Stretched; _swapChain = new DXGI.SwapChain(_factory, _graphicsDevice, new DXGI.SwapChainDescription { BufferCount = 1, Flags = DXGI.SwapChainFlags.AllowModeSwitch, IsWindowed = true, ModeDescription = modeDesc, OutputHandle = windowHandle, SampleDescription = sampleDesc, SwapEffect = swap, Usage = DXGI.Usage.RenderTargetOutput }); //Add to tracker _renderer.Resources.AddTrackedObject(_swapChain.ComPointer, this); _factory.SetWindowAssociation(windowHandle, DXGI.WindowAssociationFlags.IgnoreAll | DXGI.WindowAssociationFlags.IgnoreAltEnter); }
protected override void OnUpdate(DX11RenderContext context) { bool resetta = true; try { var ptadesc = FOutTexArray[0][context].Description; resetta = FTADepth[0] != ptadesc.ArraySize || (int)FTASize[0].x != ptadesc.Width || (int)FTASize[0].y != ptadesc.Height || FTAFormat[0] != ptadesc.Format; } catch (Exception e) { } if (resetta) { try { FOutTexArray[0].Dispose(context); } catch (Exception e) { } var tadesc = new Texture2DDescription { ArraySize = FTADepth[0], Width = (int)FTASize[0].x, Height = (int)FTASize[0].y, Format = FTAFormat[0], BindFlags = BindFlags.UnorderedAccess | BindFlags.ShaderResource, //CpuAccessFlags = CpuAccessFlags.None, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), //Usage = ResourceUsage.Default }; FOutTexArray[0][context] = new DX11RWTextureArray2D(context, new Texture2D(context.Device, tadesc)); foreach (var semantic in CustomSemantics) { semantic.Dispose(); } CustomSemantics.Clear(); CustomSemantics.Add(new RWTexture2dArrayRenderSemantic("TEXTUREARRAY", false) { Data = FOutTexArray[0][context] }); CustomSemantics.Add(new Texture2dArrayRenderSemantic("TEXTUREARRAY_SRV", false) { Data = FOutTexArray[0][context] }); } TexInfo ti = this.rtm.GetRenderTarget(context); if (ti.w != this.width || ti.h != this.height || !this.targets.ContainsKey(context) || this.invalidate || ti.format != this.format) { this.invalidate = false; this.width = ti.w; this.height = ti.h; this.format = ti.format; this.depthmanager.NeedReset = true; if (targets.ContainsKey(context)) { context.ResourcePool.Unlock(targets[context]); } if (targetresolve.ContainsKey(context)) { context.ResourcePool.Unlock(targetresolve[context]); } int aacount = Convert.ToInt32(this.FInAASamplesPerPixel[0].Name); int aaquality = 0; if (aacount > 1) { List <SampleDescription> sds = context.GetMultisampleFormatInfo(ti.format); int maxlevels = sds[sds.Count - 1].Count; if (aacount > maxlevels) { FHost.Log(TLogType.Warning, "Multisample count too high for this format, reverted to: " + maxlevels); aacount = maxlevels; } DX11RenderTarget2D temptarget = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(aacount, aaquality), this.FInDoMipMaps[0], this.FInMipLevel[0], this.FInSharedTex[0]).Element; DX11RenderTarget2D temptargetresolve = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(1, 0), this.FInDoMipMaps[0], this.FInMipLevel[0], this.FInSharedTex[0]).Element; targets[context] = temptarget; targetresolve[context] = temptargetresolve; this.FOutBuffers[0][context] = temptargetresolve; this.FOutAABuffers[0][context] = temptarget; } else { //Bind both texture as same output DX11RenderTarget2D temptarget = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(aacount, aaquality), this.FInDoMipMaps[0], this.FInMipLevel[0], this.FInSharedTex[0]).Element; targets[context] = temptarget; this.FOutBuffers[0][context] = temptarget; this.FOutAABuffers[0][context] = temptarget; } } }
protected override void OnUpdate(DX11RenderContext context) { //Grab a temp target if enabled TexInfo ti = this.rtm.GetRenderTarget(context); if (ti.w != this.width || ti.h != this.height || !this.targets.ContainsKey(context) || this.FInAASamplesPerPixel.IsChanged || ti.format !=this.format) { this.width = ti.w; this.height = ti.h; this.format = ti.format; this.depthmanager.NeedReset = true; if (targets.ContainsKey(context)) { context.ResourcePool.Unlock(targets[context]); } if (targetresolve.ContainsKey(context)) { context.ResourcePool.Unlock(targetresolve[context]); } int aacount = Convert.ToInt32(this.FInAASamplesPerPixel[0].Name); int aaquality = 0; if (aacount > 1) { List<SampleDescription> sds = context.GetMultisampleFormatInfo(ti.format); int maxlevels = sds[sds.Count - 1].Count; if (aacount > maxlevels) { FHost.Log(TLogType.Warning, "Multisample count too high for this format, reverted to: " + maxlevels); aacount = maxlevels; } DX11RenderTarget2D temptarget = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(aacount,aaquality), this.FInDoMipMaps[0], this.FInMipLevel[0]).Element; DX11RenderTarget2D temptargetresolve = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(1, 0), this.FInDoMipMaps[0], this.FInMipLevel[0]).Element; targets[context] = temptarget; targetresolve[context] = temptargetresolve; this.FOutBuffers[0][context] = temptargetresolve; this.FOutAABuffers[0][context] = temptarget; } else { //Bind both texture as same output DX11RenderTarget2D temptarget = context.ResourcePool.LockRenderTarget(this.width, this.height, ti.format, new SampleDescription(aacount, aaquality), this.FInDoMipMaps[0], this.FInMipLevel[0]).Element; targets[context] = temptarget; this.FOutBuffers[0][context] = temptarget; this.FOutAABuffers[0][context] = temptarget; } } }
public static int GetFormatStrideInBytes(SlimDX.DXGI.Format format, int width) { SharpDX.DXGI.Format sf = (SharpDX.DXGI.Format)format; return(SharpDX.DXGI.FormatHelper.SizeOfInBytes(sf) * width); }