本文整理汇总了C#中Factory.MakeWindowAssociation方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.MakeWindowAssociation方法的具体用法?C# Factory.MakeWindowAssociation怎么用?C# Factory.MakeWindowAssociation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Factory
的用法示例。
在下文中一共展示了Factory.MakeWindowAssociation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Renderer
public Renderer(Device device, Form window)
{
// Default parameter values
P1Color = new Vector3(1.0f, 0.0f, 0.0f);
P2Color = new Vector3(0.0f, 1.0f, 0.0f);
P3Color = new Vector3(0.0f, 0.0f, 1.0f);
Wireframe = false;
Scale = 0.5f;
// Create swapchain for device and window
this.window = window;
this.device = device;
this.factory = device.QueryInterface<DXGIDevice>().GetParent<Adapter>().GetParent<Factory>();
this.swapChain = new SwapChain(factory, device, new SwapChainDescription()
{
BufferCount = 1,
IsWindowed = true,
Flags = SwapChainFlags.None,
OutputHandle = window.Handle,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
SampleDescription = new SampleDescription(1, 0),
ModeDescription = new ModeDescription()
{
Width = 0,
Height = 0,
Format = Format.R8G8B8A8_UNorm,
RefreshRate = new Rational(60, 1),
}
});
context = device.ImmediateContext;
factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);
// Load shaders, create vertex buffers and stuff
vertexBuffer = new Buffer(device, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.Write,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = (32 * 3),
StructureByteStride = 16,
Usage = ResourceUsage.Dynamic
});
var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "VS", "vs_4_0");
vertexShader = new VertexShader(device, vertexShaderByteCode);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "PS", "ps_4_0");
pixelShader = new PixelShader(device, pixelShaderByteCode);
// Get input layout from the vertex shader
layout = new InputLayout(device, ShaderSignature.GetInputSignature(vertexShaderByteCode), new[] {
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
});
Resize(window.ClientSize); // first time resize
}
示例2: InitDX
public void InitDX(RenderForm form)
{
// SwapChain description
SwapChainDescription desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription =
new ModeDescription(form.ClientSize.Width, form.ClientSize.Height, new Rational(60, 1), Format.R10G10B10A2_UNorm),//.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// Create Device and SwapChain
#if DEBUG
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain);
#else
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain);
#endif
context = device.ImmediateContext;
// Ignore all windows events
factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
// New RenderTargetView from the backbuffer
backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer);
LoadShaders();
FileSystemWatcher watcher = new FileSystemWatcher(@"\dev\Galaxies\Galaxies\", "*.fx");
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(Watcher_Changed);
watcher.EnableRaisingEvents = true;
// Compile Vertex and Pixel shaders
//vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "VS", "vs_5_0");
//vertexShader = new VertexShader(device, vertexShaderByteCode);
//pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "PS", "ps_5_0");
//pixelShader = new PixelShader(device, pixelShaderByteCode);
// Create Constant Buffer
//constantBuffer = new Buffer(device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
int tempSize = System.Runtime.InteropServices.Marshal.SizeOf(new ShaderParamStruct());
constantBuffer = new Buffer(device, tempSize, ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
// Create Depth Buffer & View
var depthBuffer = new Texture2D(device, new Texture2DDescription()
{
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = form.ClientSize.Width,
Height = form.ClientSize.Height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
depthView = new DepthStencilView(device, depthBuffer);
//RasterizerStateDescription rsd = new RasterizerStateDescription() { IsMultisampleEnabled = true };
//rsd.CullMode = CullMode.Back;
//rsd.FillMode = FillMode.Solid;
//rsd.IsMultisampleEnabled = true;
//rsd.IsAntialiasedLineEnabled = false;
//rsd.IsDepthClipEnabled = false;
//rsd.IsScissorEnabled = false;
//RasterizerState rs = new RasterizerState(device, rsd);
//device.ImmediateContext.Rasterizer.State = rs;
//rs.Dispose();
depthBuffer.Dispose();
texMan = new TextureManager();
}
示例3: RenderContext11
public RenderContext11(System.Windows.Forms.Control control, bool forceNoSRGB = false)
{
bool failed = true;
while (failed)
{
try
{
// SwapChain description
desc = new SwapChainDescription()
{
BufferCount = 1,
ModeDescription =
new ModeDescription(control.ClientSize.Width, control.ClientSize.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = control.Handle,
SampleDescription = new SampleDescription(MultiSampleCount, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0, FeatureLevel.Level_9_3 };
//Enable this instead for downlevel testing.
//featureLevels = new FeatureLevel[] { FeatureLevel.Level_9_3 };
// Create Device and SwapChain
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, featureLevels, desc, out device, out swapChain);
failed = false;
}
catch
{
if (MultiSampleCount != 1)
{
MultiSampleCount = 1;
AppSettings.SettingsBase["MultiSampling"] = 1;
}
else
{
throw new System.Exception("DX Init failed");
}
failed = true;
}
}
devContext = device.ImmediateContext;
PrepDevice = device;
if(device.FeatureLevel == FeatureLevel.Level_9_3)
{
PixelProfile = "ps_4_0_level_9_3";
VertexProfile = "vs_4_0_level_9_3";
Downlevel = true;
}
else if (device.FeatureLevel == FeatureLevel.Level_9_1)
{
PixelProfile = "ps_4_0_level_9_1";
VertexProfile = "vs_4_0_level_9_1";
Downlevel = true;
}
if (!Downlevel)
{
if (!forceNoSRGB)
{
sRGB = true;
}
//dv1 = device.QueryInterface<Device1>();
//dv1.MaximumFrameLatency = 1;
}
// Ignore all windows events
factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(control.Handle, WindowAssociationFlags.IgnoreAll);
// New RenderTargetView from the backbuffer
backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer);
// Create Depth Buffer & View
depthBuffer = new Texture2D(device, new Texture2DDescription()
{
Format = DefaultDepthStencilFormat,
ArraySize = 1,
MipLevels = 1,
Width = control.ClientSize.Width,
Height = control.ClientSize.Height,
SampleDescription = new SampleDescription(MultiSampleCount, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
depthView = new DepthStencilView(device, depthBuffer);
if (Downlevel)
{
sampler = new SamplerState(device, new SamplerStateDescription()
//.........这里部分代码省略.........
示例4: Engine
/// <summary>
/// Initializes a new engine, sets view , tex manager
/// camera , mesh manager , texture manager , line manager
/// volume manager
/// </summary>
/// <param name="width">The width of the Render target</param>
/// <param name="height">The height of the Render target</param>
public Engine(int Width, int Height, Form form)
{
// pass the settings of resolution
Settings.Resolution = new System.Drawing.Size(Width, Height);
/// set the handles for full screen or windows
this.form = form;
this.FormHandle = form.Handle;
/// Create the factory which manages general graphics resources
g_factory = new Factory();
g_factory.MakeWindowAssociation(this.FormHandle, WindowAssociationFlags.IgnoreAll);
// find correct adapter
int adapterCount = g_factory.GetAdapterCount();
//MessageBox.Show(adapterCount.ToString());
// we try to select the PerfHUD adapter
for (int i = 0; i < adapterCount; i++)
{
Adapter adapt = g_factory.GetAdapter(i);
//MessageBox.Show(adapt.Description.Description);
if (adapt.Description.Description == "NVIDIA PerfHUD")
{
g_device = new Device(
adapt,
DeviceCreationFlags.Debug);
}
Console.WriteLine(i.ToString() + adapt.Description.Description);
}
if (g_device == null)
{
#if true
/// Create the DirectX Device
g_device = new Device(g_factory.GetAdapter(1),
(Settings.Debug) ? DeviceCreationFlags.Debug : DeviceCreationFlags.None,
new FeatureLevel[] { FeatureLevel.Level_11_0 });
#else
g_device = new Device(DriverType.Warp,
(Settings.Debug) ? DeviceCreationFlags.Debug : DeviceCreationFlags.None,
new FeatureLevel[] { FeatureLevel.Level_11_0 });
#endif
// check if we have one device to our system
if (!(((g_device.FeatureLevel & FeatureLevel.Level_10_0) != 0) || ((g_device.FeatureLevel & FeatureLevel.Level_10_1) != 0) || ((g_device.FeatureLevel & FeatureLevel.Level_11_0) != 0)))
{
// if we don't have we just simulate
#region Create the device base on swapChain
/// Create a description of the display mode
g_modeDesc = new ModeDescription();
/// Standard 32-bit RGBA
g_modeDesc.Format = Format.R8G8B8A8_UNorm;
/// Refresh rate of 60Hz (60 / 1 = 60)
g_modeDesc.RefreshRate = new Rational(60, 1);
/// Default
g_modeDesc.Scaling = DisplayModeScaling.Unspecified;
g_modeDesc.ScanlineOrdering = DisplayModeScanlineOrder.Progressive;
/// ClientSize is the size of the
/// form without the title and borders
g_modeDesc.Width = Width;
g_modeDesc.Height = Height;
/// Create a description of the samping
/// for multisampling or antialiasing
g_sampleDesc = new SampleDescription();
/// No multisampling
g_sampleDesc.Count = 1;
g_sampleDesc.Quality = 0;
/// Create a description of the swap
/// chain or front and back buffers
g_swapDesc = new SwapChainDescription();
/// link the ModeDescription
g_swapDesc.ModeDescription = g_modeDesc;
/// link the SampleDescription
g_swapDesc.SampleDescription = g_sampleDesc;
/// Number of buffers (including the front buffer)
g_swapDesc.BufferCount = 1;
g_swapDesc.Flags = SwapChainFlags.AllowModeSwitch;
g_swapDesc.IsWindowed = true;
/// The output window (the windows being rendered to)
g_swapDesc.OutputHandle = this.FormHandle;
/// Scrap the contents of the buffer every frame
g_swapDesc.SwapEffect = SwapEffect.Discard;
/// Indicate that this SwapChain
/// is going to be a Render target
g_swapDesc.Usage = Usage.RenderTargetOutput;
//.........这里部分代码省略.........
示例5: CreateScene
public void CreateScene()
{
// SwapChain description
// Параметры SwapChain, описание смотри ниже
var desc = new SwapChainDescription
{
BufferCount = 1,
ModeDescription =
new ModeDescription(_form.ClientSize.Width, _form.ClientSize.Height,
new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = _form.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput
};
// создаем SwapChain - набор буферов для отрисовки
// эти буферы необходимы для того, чтобы синхронизировать монитор и конвеер.
// Дело в том, безопасно обновлять изображение на мониторе можно только после того, как
// будет выведено предидущие изображение.
SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out _device, out _swapChain);
_context = _device.ImmediateContext;
// Ignore all windows events
_factory = _swapChain.GetParent<Factory>();
_factory.MakeWindowAssociation(_form.Handle, WindowAssociationFlags.IgnoreAll);
// New RenderTargetView from the backbuffer
// получаем один буферов из SwapChain.
// Это фоновый буфер, куда отрисовывается следующие изображение в то время как на экран выводится текущее.
_backBuffer = Texture2D.FromSwapChain<Texture2D>(_swapChain, 0);
_renderView = new RenderTargetView(_device, _backBuffer);
// Compile Vertex and Pixel shaders
// Читаем из файла шейдер: небольшую подпрограммку для GPU. Vertex shader это вершинный шейдер - подпрограммка
// которая принимает на вход матрицу описывающую положение вершины (точки) в пространстве
// точка входа функция VS
// vs_4_0 - профиль шейдера, по сути версия шейдера. Видеокарты поддерживают
_vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "VS", "vs_4_0");
_vertexShader = new VertexShader(_device, _vertexShaderByteCode);
// Тоже самое с писсельным шейдером, только имя точки входа тут PS
_pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniCube.fx", "PS", "ps_4_0");
_pixelShader = new PixelShader(_device, _pixelShaderByteCode);
// Layout from VertexShader input signature
// Описываем вход стадии InputAssembler, а имеено вершинный шейдер и те данные (которые возьмутся из буфера вершин (см. ниже) которые пойдут на вход этой стадии)
_layout = new InputLayout(_device, ShaderSignature.GetInputSignature(_vertexShaderByteCode), new[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0)
});
_result = (from x in Enumerable.Range(0, _sceneDescription.PartHeight)
from y in Enumerable.Range(0, _sceneDescription.PartWidth)
from plane in _sceneDescription.Planes
let rect = _sceneDescription.GetQuadrilateralByPosition(plane, x, y)
let colorIndex = x * _sceneDescription.PartWidth + y
let color = plane.Colors[colorIndex]
select new[]
{
ToVector4(rect.BottomLeft), ToVector4(color),
ToVector4(rect.TopLeft), ToVector4(color),
ToVector4(rect.TopRight), ToVector4(color),
ToVector4(rect.TopRight), ToVector4(color),
ToVector4(rect.BottomRight), ToVector4(color),
ToVector4(rect.BottomLeft), ToVector4(color),
})
.SelectMany(_ => _)
.ToArray();
// Instantiate Vertex buiffer from vertex data
// Буфер с описанием вершин ХАРДКОР
_vertices = SharpDX.Direct3D11.Buffer.Create(_device, BindFlags.VertexBuffer, _result);
// Create Constant Buffer
// буфер констант. Используется для передачи данных между оперативной памятью и памятью видеокарты
_constantBuffer = new SharpDX.Direct3D11.Buffer(_device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
// Create Depth Buffer & View
// Буфер глубины он же Z буфер
var depthBuffer = new Texture2D(_device, new Texture2DDescription
{
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = _form.ClientSize.Width,
Height = _form.ClientSize.Height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
_depthView = new DepthStencilView(_device, depthBuffer);
// Prepare All the stages
//.........这里部分代码省略.........
示例6: InitializeGraphicsDevice
private void InitializeGraphicsDevice(RenderForm window)
{
#if DEBUG
var flags = DeviceCreationFlags.Debug;
#else
var flags = DeviceCreationFlags.None;
#endif
Device.CreateWithSwapChain(DriverType.Hardware, flags, new SwapChainDescription()
{
BufferCount = 1,
IsWindowed = true,
Flags = SwapChainFlags.None,
OutputHandle = window.Handle,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
SampleDescription = new SampleDescription(1, 0),
ModeDescription = new ModeDescription()
{
Width = 0, Height = 0,
Format = Format.R8G8B8A8_UNorm,
RefreshRate = new Rational(60, 1),
}
}, out device, out swapChain);
context = device.ImmediateContext;
factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(window.Handle, WindowAssociationFlags.IgnoreAll);
}