本文整理汇总了C#中SwapChain类的典型用法代码示例。如果您正苦于以下问题:C# SwapChain类的具体用法?C# SwapChain怎么用?C# SwapChain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SwapChain类属于命名空间,在下文中一共展示了SwapChain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitDevice
/// <summary>
/// Create Direct3D device and swap chain
/// </summary>
public void InitDevice()
{
device = D3DDevice.CreateDeviceAndSwapChain(host.Handle);
swapChain = device.SwapChain;
// Create a render target view
using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
{
renderTargetView = device.CreateRenderTargetView(pBuffer);
}
device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView }, null);
// Setup the viewport
Viewport vp = new Viewport()
{
Width = (uint)host.ActualWidth,
Height = (uint)host.ActualHeight,
MinDepth = 0.0f,
MaxDepth = 1.0f,
TopLeftX = 0,
TopLeftY = 0
};
device.RS.Viewports = new Viewport[] { vp };
}
示例2: InitDevice
/// <summary>
/// Create Direct3D device and swap chain
/// </summary>
protected void InitDevice()
{
device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle);
swapChain = device.SwapChain;
// Create a render target view
using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
{
renderTargetView = device.CreateRenderTargetView(pBuffer);
}
device.OM.RenderTargets = new OutputMergerRenderTargets(new RenderTargetView[] { renderTargetView });
// Setup the viewport
Viewport vp = new Viewport()
{
Width = (uint)directControl.ClientSize.Width,
Height = (uint)directControl.ClientSize.Height,
MinDepth = 0.0f,
MaxDepth = 1.0f,
TopLeftX = 0,
TopLeftY = 0
};
device.RS.Viewports = new Viewport[] { vp };
}
示例3: 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;
}
示例4: 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);
}
示例5: 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);
}
示例6: 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;
}
示例7: TestException
public void TestException()
{
// Device is implicitly created with a DXGI Factory / Adapter
var device = new Direct3D11.Device(DriverType.Hardware);
// Create another DXGI Factory
var factory = new SharpDX.DXGI.Factory1();
try
{
// This call should raise a DXGI_ERROR_INVALID_CALL:
// The reason is the SwapChain must be created with a d3d device that was created with the same factory
// Because we were creating the D3D11 device without a DXGI factory, it is associated with another factory.
var swapChain = new SwapChain(
factory,
device,
new SwapChainDescription()
{
BufferCount = 1,
Flags = SwapChainFlags.None,
IsWindowed = false,
ModeDescription = new ModeDescription(1024, 768, new Rational(60, 1), Format.R8G8B8A8_UNorm),
SampleDescription = new SampleDescription(1, 0),
OutputHandle = IntPtr.Zero,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
});
} catch (SharpDXException exception)
{
Assert.AreEqual(exception.Descriptor.NativeApiCode, "DXGI_ERROR_INVALID_CALL");
}
}
示例8: D3DApp
protected D3DApp(IntPtr hInstance)
{
AppInst = hInstance;
MainWindowCaption = "D3D11 Application";
DriverType = DriverType.Hardware;
ClientWidth = 800;
ClientHeight = 600;
Enable4XMsaa = false;
Window = null;
AppPaused = false;
Minimized = false;
Maximized = false;
Resizing = false;
Msaa4XQuality = 0;
Device = null;
ImmediateContext = null;
SwapChain = null;
DepthStencilBuffer = null;
RenderTargetView = null;
DepthStencilView = null;
Viewport = new Viewport();
Timer = new GameTimer();
GD3DApp = this;
}
示例9: 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");
}
示例10: 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();
}
示例11: DrawDevice
//-------------------------------------------------------------------
// Constructor
//-------------------------------------------------------------------
public DrawDevice()
{
m_hwnd = IntPtr.Zero;
m_pDevice = null;
m_pSwapChain = null;
m_d3dpp = null;
m_Data = IntPtr.Zero;
m_format = Format.X8R8G8B8;
m_width = 0;
m_height = 0;
m_lDefaultStride = 0;
m_PixelAR.Denominator = m_PixelAR.Numerator = 1;
m_rcDest = Rectangle.Empty;
VideoFormatDefs = new VideoFormatGUID[] {
new VideoFormatGUID(MFMediaType.RGB32, TransformImage_RGB32, ARGB32_To_RGB32),
new VideoFormatGUID(MFMediaType.RGB24, TransformImage_RGB24, ARGB32_To_RGB24),
new VideoFormatGUID(MFMediaType.YUY2, TransformImage_YUY2, ARGB32_To_YUY2),
new VideoFormatGUID(MFMediaType.NV12, TransformImage_NV12, ARGB32_To_NV12)
};
m_convertFn = null;
m_bmpconvertFn = null;
}
示例12: Initialize
public override WriteableBitmap Initialize(Device device)
{
const int width = 600;
const int height = 400;
// Create device and swap chain.
var swapChainPresenter = new WpfSwapChainPresenter();
_swapChain = device.CreateSwapChain(width, height, swapChainPresenter);
_deviceContext = device.ImmediateContext;
// Create RenderTargetView from the backbuffer.
var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
_renderTargetView = device.CreateRenderTargetView(backBuffer);
// Create DepthStencilView.
var depthStencilBuffer = device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
BindFlags = BindFlags.DepthStencil
});
var depthStencilView = device.CreateDepthStencilView(depthStencilBuffer);
// Prepare all the stages.
_deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
_deviceContext.OutputMerger.SetTargets(depthStencilView, _renderTargetView);
return swapChainPresenter.Bitmap;
}
示例13: DeviceContext10
/// <summary>
/// Initializes a new instance of the <see cref="DeviceContext10"/> class.
/// </summary>
/// <param name="handle">The window handle to associate with the device.</param>
/// <param name="settings">The settings used to configure the device.</param>
internal DeviceContext10(IntPtr handle, DeviceSettings10 settings)
{
if (handle == IntPtr.Zero)
throw new ArgumentException("Value must be a valid window handle.", "handle");
if (settings == null)
throw new ArgumentNullException("settings");
this.settings = settings;
factory = new Factory();
device = new Direct3D10.Device(factory.GetAdapter(settings.AdapterOrdinal), Direct3D10.DriverType.Hardware, settings.CreationFlags);
swapChain = new SwapChain(factory, device, new SwapChainDescription
{
BufferCount = 1,
Flags = SwapChainFlags.None,
IsWindowed = true,
ModeDescription = new ModeDescription(settings.Width, settings.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
OutputHandle = handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
});
factory.SetWindowAssociation(handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter);
}
示例14: AfterEngineInit
public void AfterEngineInit()
{
// Basics.
{
var deviceDesc = new Device.Descriptor {DebugDevice = true};
renderDevice = new ClearSight.RendererDX12.Device(ref deviceDesc,
ClearSight.RendererDX12.Device.FeatureLevel.Level_11_0);
var descCQ = new CommandQueue.Descriptor() {Type = CommandListType.Graphics};
commandQueue = renderDevice.Create(ref descCQ);
var wih = new WindowInteropHelper(window);
var swapChainDesc = new SwapChain.Descriptor()
{
AssociatedGraphicsQueue = commandQueue,
MaxFramesInFlight = 3,
BufferCount = 3,
Width = (uint) window.Width,
Height = (uint) window.Height,
Format = Format.R8G8B8A8_UNorm,
SampleCount = 1,
SampleQuality = 0,
WindowHandle = wih.Handle,
Fullscreen = false
};
swapChain = renderDevice.Create(ref swapChainDesc);
var commandListDesc = new CommandList.Descriptor()
{
Type = CommandListType.Graphics,
AllocationPolicy = new CommandListInFlightFrameAllocationPolicy(CommandListType.Graphics, swapChain)
};
commandList = renderDevice.Create(ref commandListDesc);
}
// Render targets.
{
var descHeapDesc = new DescriptorHeap.Descriptor()
{
Type = DescriptorHeap.Descriptor.ResourceDescriptorType.RenderTarget,
NumResourceDescriptors = swapChain.Desc.BufferCount
};
descHeapRenderTargets = renderDevice.Create(ref descHeapDesc);
var rtvViewDesc = new RenderTargetViewDescription()
{
Format = swapChain.Desc.Format,
Dimension = Dimension.Texture2D,
Texture = new TextureSubresourceDesc(mipSlice: 0)
};
for (uint i = 0; i < swapChain.Desc.BufferCount; ++i)
{
renderDevice.CreateRenderTargetView(descHeapRenderTargets, i, swapChain.BackbufferResources[i], ref rtvViewDesc);
}
}
}
示例15: RenderTarget
public RenderTarget(Device device, SwapChain swapChain)
: this()
{
Texture = _disposer.Add(Texture2D.FromSwapChain<Texture2D>(swapChain, 0));
RenderTargetView = _disposer.Add(new RenderTargetView(device, Texture));
ShaderResourceView = null;
Viewport = new Viewport(0, 0, Width, Height, 0.0f, 1.0f);
}