本文整理汇总了C#中SwapChainDescription类的典型用法代码示例。如果您正苦于以下问题:C# SwapChainDescription类的具体用法?C# SwapChainDescription怎么用?C# SwapChainDescription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SwapChainDescription类属于命名空间,在下文中一共展示了SwapChainDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderContainer
public RenderContainer(SwapChainDescription swapChainDescription, RenderControl control)
{
try
{
_swapChainDescription = swapChainDescription;
using (Factory1 factory = new Factory1())
using (Adapter adapter = factory.GetAdapter(0))
{
Device11 = new Dx11ChainedDevice(adapter, _swapChainDescription);
Device10 = new Dx10Device(adapter);
}
GraphicsDevice = new GenericGraphicsDevice(Device11.Device);
SpriteBatch = new SpriteBatch(GraphicsDevice);
Reset(control.Width, control.Height);
control.Resize += OnRenderControlResize;
}
catch
{
Dispose();
throw;
}
}
示例2: RenderControl
/// <summary>
/// Initializes a new instance of the <see cref="RenderControl" /> class.
/// </summary>
public RenderControl()
{
SwapChainDescription swapCHainDesc = new SwapChainDescription
{
BufferCount = 2,
Usage = Usage.RenderTargetOutput,
OutputHandle = Handle,
IsWindowed = true,
ModeDescription =
new ModeDescription(
Width,
Height,
new Rational(60, 1),
Format.R8G8B8A8_UNorm),
SampleDescription = new SampleDescription(1, 0),
Flags = SwapChainFlags.AllowModeSwitch,
SwapEffect = SwapEffect.Discard
};
Device.CreateWithSwapChain(
DriverType.Hardware,
DeviceCreationFlags.BgraSupport,
swapCHainDesc,
out _device,
out _swapChain);
Debug.Assert(_swapChain != null, "_swapChain != null");
// ReSharper disable once AssignNullToNotNullAttribute
_backBuffer = Surface.FromSwapChain(_swapChain, 0);
Debug.Assert(_backBuffer != null, "_backBuffer != null");
Size2F dpi = DirectXResourceManager.FactoryD2D.DesktopDpi;
RenderTarget renderTarget = new RenderTarget(
DirectXResourceManager.FactoryD2D,
_backBuffer,
new RenderTargetProperties
{
DpiX = dpi.Width,
DpiY = dpi.Height,
MinLevel = SharpDX.Direct2D1.FeatureLevel.Level_DEFAULT,
PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Ignore),
Type = RenderTargetType.Default,
Usage = RenderTargetUsage.None
});
_renderTargetContainer = RenderTargetContainer.CreateContainer(renderTarget, out _renderTargetRef);
using (FactoryDXGI factory = _swapChain.GetParent<FactoryDXGI>())
{
Debug.Assert(factory != null, "factory != null");
factory.MakeWindowAssociation(Handle, WindowAssociationFlags.IgnoreAltEnter);
}
_renderThread = new Thread(RenderLoop)
{
Name = "Render Thread",
IsBackground = true
};
}
示例3: InitializeD3D
public void InitializeD3D()
{
var description = new SwapChainDescription()
{
BufferCount = 2,
Usage = Usage.RenderTargetOutput,
OutputHandle = form.Handle,
IsWindowed = true,
ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm),
SampleDescription = new SampleDescription(1, 0),
Flags = SwapChainFlags.AllowModeSwitch,
SwapEffect = SwapEffect.Discard
};
//Create swap chain
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, description, out this.device, out swapChain);
// create a view of our render target, which is the backbuffer of the swap chain we just created
// setting a viewport is required if you want to actually see anything
var resource = Resource.FromSwapChain<Texture2D>(swapChain, 0);
renderTarget = new RenderTargetView(device, resource);
var context = device.ImmediateContext;
var viewport = new Viewport(0.0f, 0.0f, form.ClientSize.Width, form.ClientSize.Height);
context.OutputMerger.SetTargets(renderTarget);
context.Rasterizer.SetViewports(viewport);
}
示例4: InitializeDeviceResources
private void InitializeDeviceResources()
{
ModeDescription backBufferDesc = new ModeDescription(Width, Height, new Rational(60, 1), Format.R8G8B8A8_UNorm);
// Descriptor for the swap chain
SwapChainDescription swapChainDesc = new SwapChainDescription()
{
ModeDescription = backBufferDesc,
SampleDescription = new SampleDescription(1, 0),
Usage = Usage.RenderTargetOutput,
BufferCount = 1,
OutputHandle = renderForm.Handle,
IsWindowed = true
};
// Create device and swap chain
D3D11.Device.CreateWithSwapChain(DriverType.Hardware, D3D11.DeviceCreationFlags.None, swapChainDesc, out d3dDevice, out swapChain);
d3dDeviceContext = d3dDevice.ImmediateContext;
// Create render target view for back buffer
using(D3D11.Texture2D backBuffer = swapChain.GetBackBuffer<D3D11.Texture2D>(0))
{
renderTargetView = new D3D11.RenderTargetView(d3dDevice, backBuffer);
}
// Set back buffer as current render target view
d3dDeviceContext.OutputMerger.SetRenderTargets(renderTargetView);
}
示例5: CreateImpl
protected override void CreateImpl()
{
var swapChainDesc = new SwapChainDescription()
{
BufferCount = (int)Desc.BufferCount,
ModeDescription = new ModeDescription((int) Desc.Width, (int)Desc.Height, new Rational(0,0), Memory.Enums.ToDXGIFormat[(int)Desc.Format]),
Usage = Usage.RenderTargetOutput,
SwapEffect = SwapEffect.FlipDiscard,
OutputHandle = Desc.WindowHandle,
SampleDescription = new SampleDescription
{
Count = (int) Desc.SampleCount,
Quality = (int) Desc.SampleQuality
},
IsWindowed = !Desc.Fullscreen
};
using (var factory = new Factory4())
{
var tempSwapChain = new SharpDX.DXGI.SwapChain(factory, ((CommandQueue)Desc.AssociatedGraphicsQueue).CommandQueueD3D12, swapChainDesc);
SwapChainDXGI = tempSwapChain.QueryInterface<SwapChain3>();
tempSwapChain.Dispose();
CurrentBackBufferIndex = (uint)SwapChainDXGI.CurrentBackBufferIndex;
}
SwapChainDXGI.DebugName = Label;
Log.Info("Created SwapChain");
}
示例6: CreateDeviceSwapChainAndRenderTarget
public static void CreateDeviceSwapChainAndRenderTarget(Form form,
out Device device, out SwapChain swapChain, out RenderTargetView renderTarget)
{
try
{
// the debug mode requires the sdk to be installed otherwise an exception is thrown
device = new Device(DeviceCreationFlags.Debug);
}
catch (Direct3D10Exception)
{
device = new Device(DeviceCreationFlags.None);
}
var swapChainDescription = new SwapChainDescription();
var modeDescription = new ModeDescription();
var sampleDescription = new SampleDescription();
modeDescription.Format = Format.R8G8B8A8_UNorm;
modeDescription.RefreshRate = new Rational(60, 1);
modeDescription.Scaling = DisplayModeScaling.Unspecified;
modeDescription.ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified;
modeDescription.Width = WIDTH;
modeDescription.Height = HEIGHT;
sampleDescription.Count = 1;
sampleDescription.Quality = 0;
swapChainDescription.ModeDescription = modeDescription;
swapChainDescription.SampleDescription = sampleDescription;
swapChainDescription.BufferCount = 1;
swapChainDescription.Flags = SwapChainFlags.None;
swapChainDescription.IsWindowed = true;
swapChainDescription.OutputHandle = form.Handle;
swapChainDescription.SwapEffect = SwapEffect.Discard;
swapChainDescription.Usage = Usage.RenderTargetOutput;
using (var factory = new Factory())
{
swapChain = new SwapChain(factory, device, swapChainDescription);
}
using (var resource = swapChain.GetBuffer<Texture2D>(0))
{
renderTarget = new RenderTargetView(device, resource);
}
var viewport = new Viewport
{
X = 0,
Y = 0,
Width = WIDTH,
Height = HEIGHT,
MinZ = 0.0f,
MaxZ = 1.0f
};
device.Rasterizer.SetViewports(viewport);
device.OutputMerger.SetTargets(renderTarget);
}
示例7: InitalizeGraphics
private void InitalizeGraphics()
{
if (Window.RenderCanvasHandle == IntPtr.Zero)
throw new InvalidOperationException("Window handle cannot be zero");
SwapChainDescription swapChainDesc = new SwapChainDescription()
{
BufferCount = 1,
Flags = SwapChainFlags.None,
IsWindowed = true,
OutputHandle = Window.RenderCanvasHandle,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
ModeDescription = new ModeDescription()
{
Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
//Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
Width = Window.ClientSize.Width,
Height = Window.ClientSize.Height,
RefreshRate = new Rational(60, 1),
Scaling = DisplayModeScaling.Unspecified,
ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified
},
SampleDescription = new SampleDescription(1, 0)
};
var giFactory = new SlimDX.DXGI.Factory();
var adapter = giFactory.GetAdapter(0);
Device device;
SwapChain swapChain;
Device.CreateWithSwapChain(adapter, DriverType.Hardware, DeviceCreationFlags.None, swapChainDesc, out device, out swapChain);
_swapChain = swapChain;
GraphicsDevice = device;
// create a view of our render target, which is the backbuffer of the swap chain we just created
using (var resource = SlimDX.Direct3D10.Resource.FromSwapChain<Texture2D>(swapChain, 0))
{
_backBuffer = new RenderTargetView(device, resource);
}
// setting a viewport is required if you want to actually see anything
var viewport = new Viewport(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
device.OutputMerger.SetTargets(_backBuffer);
device.Rasterizer.SetViewports(viewport);
CreateDepthStencil();
LoadVisualizationEffect();
// Allocate a large buffer to write the PhysX visualization vertices into
// There's more optimized ways of doing this, but for this sample a large buffer will do
_userPrimitivesBuffer = new SlimDX.Direct3D10.Buffer(GraphicsDevice, VertexPositionColor.SizeInBytes * 50000, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None);
var elements = new[]
{
new InputElement("Position", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("Color", 0, Format.R32G32B32A32_Float, 16, 0)
};
_inputLayout = new InputLayout(GraphicsDevice, _visualizationEffect.RenderScenePass0.Description.Signature, elements);
}
示例8: Renderer
public Renderer(int Width, int Height, IntPtr? OutputHandle)
{
if (Width < 1)
Width = 1;
if (Height < 1)
Height = 1;
bufferWidth = Width;
bufferHeight = Height;
deviceUsers++;
if (device == null)
device = new Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, FeatureLevel.Level_11_0);
if (OutputHandle.HasValue)
{
SwapChainDescription swapChainDesc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new ModeDescription(BufferWidth, BufferHeight, new Rational(120, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = OutputHandle.Value,
SampleDescription = BufferSampleDescription,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
Flags = SwapChainFlags.AllowModeSwitch,
};
swapChain = new SwapChain(device.Factory, Device, swapChainDesc);
using (var factory = swapChain.GetParent<Factory>())
factory.SetWindowAssociation(OutputHandle.Value, WindowAssociationFlags.IgnoreAltEnter);
}
LightingSystem = new ForwardLighting(this);
SetupRenderTargets();
LightingSystem.Initialize();
}
示例9: DX11SwapChain
public DX11SwapChain(DX11RenderContext context, IntPtr handle, Format format, SampleDescription sampledesc)
{
this.context = context;
this.handle = handle;
SwapChainDescription sd = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), format),
IsWindowed = true,
OutputHandle = handle,
SampleDescription = sampledesc,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput | Usage.ShaderInput,
Flags = SwapChainFlags.None
};
if (sd.SampleDescription.Count == 1 && context.IsFeatureLevel11)
{
sd.Usage |= Usage.UnorderedAccess;
this.allowuav = true;
}
this.swapchain = new SwapChain(context.Device.Factory, context.Device, sd);
this.Resource = Texture2D.FromSwapChain<Texture2D>(this.swapchain, 0);
this.context.Factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAltEnter);
this.RTV = new RenderTargetView(context.Device, this.Resource);
this.SRV = new ShaderResourceView(context.Device, this.Resource);
if (this.allowuav) { this.UAV = new UnorderedAccessView(context.Device, this.Resource); }
this.desc = this.Resource.Description;
}
示例10: Initialize
protected override void Initialize(DemoConfiguration demoConfiguration)
{
// SwapChain description
var desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription =
new ModeDescription(demoConfiguration.Width, demoConfiguration.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = DisplayHandle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// Create Device and SwapChain
Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new [] { FeatureLevel.Level_10_0 }, desc, out _device, out _swapChain);
// Ignore all windows events
Factory factory = _swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(DisplayHandle, WindowAssociationFlags.IgnoreAll);
// New RenderTargetView from the backbuffer
_backBuffer = Texture2D.FromSwapChain<Texture2D>(_swapChain, 0);
_backBufferView = new RenderTargetView(_device, _backBuffer);
}
示例11: DX11Renderer
public DX11Renderer(IntPtr windowHandle, Size2 size, Device dev = null)
{
RenderSize = size;
_windowHandle = windowHandle;
if(dev != null)
{
_dxDevice = dev;
}
else
{
var swapchainDesc = new SwapChainDescription()
{
BufferCount = 2,
ModeDescription =
new ModeDescription(size.Width, size.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = windowHandle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// Create Device and SwapChain
Device.CreateWithSwapChain(DriverType.Hardware,
DeviceCreationFlags.None, swapchainDesc, out _dxDevice, out _swapChain);
// Ignore all windows events
// var factory = _swapChain.GetParent<Factory>();
// factory.MakeWindowAssociation(windowHandle, WindowAssociationFlags.None);
Reset(size.Width, size.Height);
}
}
示例12: DX11GraphicsDevice
public DX11GraphicsDevice(Form form)
{
this.Form = form;
var scDesc = new SwapChainDescription
{
BufferCount = 2,
Flags = SwapChainFlags.AllowModeSwitch,
IsWindowed = true,
ModeDescription = new ModeDescription(
form.ClientSize.Width,
form.ClientSize.Height,
new Rational(60, 1),
format),
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Sequential,
Usage = Usage.RenderTargetOutput
};
var levels = new[] { FeatureLevel.Level_9_2, FeatureLevel.Level_9_1 };
Device.CreateWithSwapChain(
DriverType.Hardware,
DeviceCreationFlags.None,
levels,
scDesc,
out device,
out swapChain);
ResetDevice();
form.ResizeEnd += ResizeEnd;
}
示例13: Initialize
public override void Initialize()
{
Device tmpDevice;
SwapChain sc;
using (var rf = new RenderForm())
{
var desc = new SwapChainDescription
{
BufferCount = 1,
Flags = SwapChainFlags.None,
IsWindowed = true,
ModeDescription = new ModeDescription(100, 100, new Rational(60, 1), SlimDX.DXGI.Format.R8G8B8A8_UNorm),
OutputHandle = rf.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
var res = Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out tmpDevice, out sc);
if (res.IsSuccess)
{
using (tmpDevice)
{
using (sc)
{
PresentPointer = Pulse.Magic.GetObjectVtableFunction(sc.ComPointer, VMT_PRESENT);
ResetTargetPointer = Pulse.Magic.GetObjectVtableFunction(sc.ComPointer, VMT_RESIZETARGET);
}
}
}
}
_presentDelegate = Pulse.Magic.RegisterDelegate<Direct3D11Present>(PresentPointer);
_presentHook = Pulse.Magic.Detours.CreateAndApply(_presentDelegate, new Direct3D11Present(Callback), "D11Present");
}
示例14: Initialize
public override void Initialize()
{
using (var fac = new Factory())
{
using (var tmpDevice = new Device(fac.GetAdapter(0), DriverType.Hardware, DeviceCreationFlags.None))
{
using (var rf = new RenderForm())
{
var desc = new SwapChainDescription
{
BufferCount = 1,
Flags = SwapChainFlags.None,
IsWindowed = true,
ModeDescription = new ModeDescription(100, 100, new Rational(60, 1), Format.R8G8B8A8_UNorm),
OutputHandle = rf.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
using (var sc = new SwapChain(fac, tmpDevice, desc))
{
PresentPointer = Pulse.Magic.GetObjectVtableFunction(sc.ComPointer, VMT_PRESENT);
ResetTargetPointer = Pulse.Magic.GetObjectVtableFunction(sc.ComPointer, VMT_RESIZETARGET);
}
}
}
}
_presentDelegate = Pulse.Magic.RegisterDelegate<Direct3D10Present>(PresentPointer);
_presentHook = Pulse.Magic.Detours.CreateAndApply(_presentDelegate, new Direct3D10Present(Callback), "D10Present");
}
示例15: D3D11RenderingPane
public D3D11RenderingPane( Factory dxgiFactory, SlimDX.Direct3D11.Device d3D11Device, DeviceContext d3D11DeviceContext, D3D11HwndDescription d3D11HwndDescription )
{
mDxgiFactory = dxgiFactory;
mD3D11Device = d3D11Device;
mD3D11DeviceContext = d3D11DeviceContext;
var swapChainDescription = new SwapChainDescription
{
BufferCount = 1,
ModeDescription =
new ModeDescription( d3D11HwndDescription.Width,
d3D11HwndDescription.Height,
new Rational( 60, 1 ),
Format.R8G8B8A8_UNorm ),
IsWindowed = true,
OutputHandle = d3D11HwndDescription.Handle,
SampleDescription = new SampleDescription( 1, 0 ),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
mSwapChain = new SwapChain( mDxgiFactory, mD3D11Device, swapChainDescription );
mDxgiFactory.SetWindowAssociation( d3D11HwndDescription.Handle, WindowAssociationFlags.IgnoreAll );
CreateD3D11Resources( d3D11HwndDescription.Width, d3D11HwndDescription.Height );
PauseRendering = false;
}