本文整理汇总了C#中SharpDX.Direct3D11.Device.QueryInterfaceOrNull方法的典型用法代码示例。如果您正苦于以下问题:C# Device.QueryInterfaceOrNull方法的具体用法?C# Device.QueryInterfaceOrNull怎么用?C# Device.QueryInterfaceOrNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.Direct3D11.Device
的用法示例。
在下文中一共展示了Device.QueryInterfaceOrNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
#region Direct3D Initialization
// Create the window to render to
Form1 form = new Form1();
form.Text = "D3DRendering - Initialize D3D 11.1";
form.Width = 640;
form.Height = 480;
// Create the device and swapchain
Device1 device;
SwapChain1 swapChain;
// First create a regular D3D11 device
using (
var device11 = new Device(
SharpDX.Direct3D.DriverType.Hardware,
DeviceCreationFlags.None,
new [] {
SharpDX.Direct3D.FeatureLevel.Level_11_1,
SharpDX.Direct3D.FeatureLevel.Level_11_0,
}))
{
// Query device for the Device1 interface (ID3D11Device1)
device = device11.QueryInterfaceOrNull<Device1>();
if (device == null)
throw new NotSupportedException("SharpDX.Direct3D11.Device1 is not supported");
}
// Rather than create a new DXGI Factory we should reuse
// the one that has been used internally to create the device
using (var dxgi = device.QueryInterface<SharpDX.DXGI.Device2>())
using (var adapter = dxgi.Adapter)
using (var factory = adapter.GetParent<Factory2>())
{
var desc1 = new SwapChainDescription1()
{
Width = form.ClientSize.Width,
Height = form.ClientSize.Height,
Format = Format.R8G8B8A8_UNorm,
Stereo = false,
SampleDescription = new SampleDescription(1, 0),
Usage = Usage.BackBuffer | Usage.RenderTargetOutput,
BufferCount = 1,
Scaling = Scaling.Stretch,
SwapEffect = SwapEffect.Discard,
};
swapChain = new SwapChain1(factory,
device,
form.Handle,
ref desc1,
new SwapChainFullScreenDescription()
{
RefreshRate = new Rational(60, 1),
Scaling = DisplayModeScaling.Centered,
Windowed = true
},
// Restrict output to specific Output (monitor)
null);
}
// Create references to backBuffer and renderTargetView
var backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
var renderTargetView = new RenderTargetView(device, backBuffer);
#endregion
#region Render loop
// Create Clock and FPS counters
var clock = new System.Diagnostics.Stopwatch();
var clockFrequency = (double)System.Diagnostics.Stopwatch.Frequency;
clock.Start();
var deltaTime = 0.0;
var fpsTimer = new System.Diagnostics.Stopwatch();
fpsTimer.Start();
var fps = 0.0;
int fpsFrames = 0;
// Create and run the render loop
RenderLoop.Run(form, () =>
{
// Time in seconds
var totalSeconds = clock.ElapsedTicks / clockFrequency;
#region FPS and title update
fpsFrames++;
if (fpsTimer.ElapsedMilliseconds > 1000)
{
fps = 1000.0 * fpsFrames / fpsTimer.ElapsedMilliseconds;
// Update window title with FPS once every second
form.Text = string.Format("D3DRendering D3D11.1 - FPS: {0:F2} ({1:F2}ms/frame)", fps, (float)fpsTimer.ElapsedMilliseconds / fpsFrames);
// Restart the FPS counter
fpsTimer.Reset();
fpsTimer.Start();
fpsFrames = 0;
//.........这里部分代码省略.........