本文整理汇总了C#中Device.CreateRenderTargetView方法的典型用法代码示例。如果您正苦于以下问题:C# Device.CreateRenderTargetView方法的具体用法?C# Device.CreateRenderTargetView怎么用?C# Device.CreateRenderTargetView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.CreateRenderTargetView方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: RenderScene
private static Number4[] RenderScene(Device device)
{
const int width = 200;
const int height = 100;
// Create device and swap chain.
var swapChainPresenter = new RawSwapChainPresenter();
var swapChain = device.CreateSwapChain(
new SwapChainDescription(width, height),
swapChainPresenter);
var deviceContext = device.ImmediateContext;
// Create RenderTargetView from the backbuffer.
var backBuffer = Texture2D.FromSwapChain(swapChain, 0);
var renderTargetView = device.CreateRenderTargetView(backBuffer);
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Assets/MiniTri.fx", "VS", "vs_4_0");
var vertexShader = device.CreateVertexShader(vertexShaderByteCode);
var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Assets/MiniTri.fx", "PS", "ps_4_0");
var pixelShader = device.CreatePixelShader(pixelShaderByteCode);
// Layout from VertexShader input signature
var layout = device.CreateInputLayout(
new[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 0)
}, vertexShaderByteCode);
// Instantiate Vertex buffer from vertex data
var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
{
new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
});
// Prepare all the stages
deviceContext.InputAssembler.InputLayout = layout;
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 0, 32));
deviceContext.VertexShader.Shader = vertexShader;
deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
deviceContext.PixelShader.Shader = pixelShader;
deviceContext.OutputMerger.SetTargets(null, renderTargetView);
deviceContext.ClearRenderTargetView(renderTargetView, Color4.Black);
deviceContext.Draw(3, 0);
swapChain.Present();
return swapChainPresenter.Data;
}
示例3: LoadPipeline
private void LoadPipeline(RenderForm form)
{
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
viewport.Width = width;
viewport.Height = height;
viewport.MaxDepth = 1.0f;
scissorRect.Right = width;
scissorRect.Bottom = height;
#if DEBUG
// Enable the D3D12 debug layer.
{
DebugInterface.Get().EnableDebugLayer();
}
#endif
device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_11_0);
using (var factory = new Factory4())
{
// Describe and create the command queue.
CommandQueueDescription queueDesc = new CommandQueueDescription(CommandListType.Direct);
commandQueue = device.CreateCommandQueue(queueDesc);
// Describe and create the swap chain.
SwapChainDescription swapChainDesc = new SwapChainDescription()
{
BufferCount = FrameCount,
ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
Usage = Usage.RenderTargetOutput,
SwapEffect = SwapEffect.FlipDiscard,
OutputHandle = form.Handle,
//Flags = SwapChainFlags.None,
SampleDescription = new SampleDescription(1, 0),
IsWindowed = true
};
SwapChain tempSwapChain = new SwapChain(factory, commandQueue, swapChainDesc);
swapChain = tempSwapChain.QueryInterface<SwapChain3>();
tempSwapChain.Dispose();
frameIndex = swapChain.CurrentBackBufferIndex;
}
// Create descriptor heaps.
// Describe and create a render target view (RTV) descriptor heap.
DescriptorHeapDescription rtvHeapDesc = new DescriptorHeapDescription()
{
DescriptorCount = FrameCount,
Flags = DescriptorHeapFlags.None,
Type = DescriptorHeapType.RenderTargetView
};
renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc);
DescriptorHeapDescription srvHeapDesc = new DescriptorHeapDescription()
{
DescriptorCount = 1,
Flags = DescriptorHeapFlags.ShaderVisible,
Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView
};
shaderRenderViewHeap = device.CreateDescriptorHeap(srvHeapDesc);
rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView);
// Create frame resources.
CpuDescriptorHandle rtvHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart;
for (int n = 0; n < FrameCount; n++)
{
renderTargets[n] = swapChain.GetBackBuffer<Resource>(n);
device.CreateRenderTargetView(renderTargets[n], null, rtvHandle);
rtvHandle += rtvDescriptorSize;
}
commandAllocator = device.CreateCommandAllocator(CommandListType.Direct);
}
示例4: 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);
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/BasicTriangle/MiniTri.fx", "VS", "vs_4_0");
var vertexShader = device.CreateVertexShader(vertexShaderByteCode);
var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/BasicTriangle/MiniTri.fx", "PS", "ps_4_0");
var pixelShader = device.CreatePixelShader(pixelShaderByteCode);
// Layout from VertexShader input signature
var layout = device.CreateInputLayout(
new[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 0)
}, vertexShaderByteCode);
// Instantiate Vertex buffer from vertex data
var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
{
new Vector4(0.0f, 0.5f, 0.5f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-0.5f, -0.5f, 0.5f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f)
});
_model = new Model();
_model.AddMesh(new ModelMesh
{
IndexBuffer = device.CreateBuffer(new BufferDescription
{
BindFlags = BindFlags.IndexBuffer
}, new uint[] { 0, 1, 2 }),
IndexCount = 3,
InputLayout = layout,
PrimitiveCount = 1,
PrimitiveTopology = PrimitiveTopology.TriangleList,
VertexBuffer = vertices,
VertexCount = 3,
VertexSize = 32
});
// Prepare all the stages
_deviceContext.VertexShader.Shader = vertexShader;
_deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
_deviceContext.PixelShader.Shader = pixelShader;
_deviceContext.OutputMerger.SetTargets(null, _renderTargetView);
return swapChainPresenter.Bitmap;
}
示例5: RenderTargetView
/// <summary>
/// Creates a <see cref = "T:SharpDX.Direct3D11.RenderTargetView" /> for accessing resource data.
/// </summary>
/// <param name = "device">The device to use when creating this <see cref = "T:SharpDX.Direct3D11.RenderTargetView" />.</param>
/// <param name = "resource">The resource that represents the render-target surface. This surface must have been created with the <see cref = "T:SharpDX.Direct3D11.BindFlags">RenderTarget</see> flag.</param>
/// <param name = "description">A structure describing the <see cref = "T:SharpDX.Direct3D11.RenderTargetView" /> to be created.</param>
/// <unmanaged>ID3D11Device::CreateRenderTargetView</unmanaged>
public RenderTargetView(Device device, Resource resource, RenderTargetViewDescription description)
: base(IntPtr.Zero)
{
device.CreateRenderTargetView(resource, description, this);
}
示例6: LoadPipeline
private void LoadPipeline(RenderForm form)
{
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
viewport.Width = width;
viewport.Height = height;
viewport.MaxDepth = 1.0f;
scissorRect.Right = width;
scissorRect.Bottom = height;
device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_11_0);
using (var factory = new Factory4())
{
var queueDesc = new CommandQueueDescription(CommandListType.Direct);
commandQueue = device.CreateCommandQueue(queueDesc);
var swapChainDesc = new SwapChainDescription()
{
BufferCount = FrameCount,
ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
Usage = Usage.RenderTargetOutput,
SwapEffect = SwapEffect.FlipDiscard,
OutputHandle = form.Handle,
SampleDescription = new SampleDescription(1, 0),
IsWindowed = true
};
var tempSwapChain = new SwapChain(factory, commandQueue, swapChainDesc);
swapChain = tempSwapChain.QueryInterface<SwapChain3>();
frameIndex = swapChain.CurrentBackBufferIndex;
}
var rtvHeapDesc = new DescriptorHeapDescription()
{
DescriptorCount = FrameCount,
Flags = DescriptorHeapFlags.None,
Type = DescriptorHeapType.RenderTargetView
};
renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc);
rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView);
var srvHeapDesc = new DescriptorHeapDescription()
{
DescriptorCount = 200,
Flags = DescriptorHeapFlags.ShaderVisible,
Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView
};
shaderRenderViewHeap = device.CreateDescriptorHeap(srvHeapDesc);
var terrainHeapDesc = new DescriptorHeapDescription()
{
DescriptorCount = 2,
Flags = DescriptorHeapFlags.ShaderVisible,
Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView
};
terrainHeap = device.CreateDescriptorHeap(terrainHeapDesc);
var meshCtrCbvDesc = new DescriptorHeapDescription()
{
DescriptorCount = 1,
Flags = DescriptorHeapFlags.ShaderVisible,
Type = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView
};
meshCtrBufferViewHeap = device.CreateDescriptorHeap(meshCtrCbvDesc);
var rtcHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart;
for (int n = 0; n < FrameCount; n++)
{
renderTargets[n] = swapChain.GetBackBuffer<Resource>(n);
device.CreateRenderTargetView(renderTargets[n], null, rtcHandle);
rtcHandle += rtvDescriptorSize;
}
var svHeapDesc = new DescriptorHeapDescription()
{
Type = DescriptorHeapType.Sampler,
DescriptorCount = 1,
Flags = DescriptorHeapFlags.ShaderVisible,
NodeMask = 0
};
samplerViewHeap = device.CreateDescriptorHeap(svHeapDesc);
commandAllocator = device.CreateCommandAllocator(CommandListType.Direct);
}
示例7: ImageGenerator
public ImageGenerator(IResourceManager resourceLoader)
{
const int width = 400;
const int height = 400;
// Create device and swap chain.
_device = new Device();
var swapChainPresenter = new WpfSwapChainPresenter();
_swapChain = _device.CreateSwapChain(width, height, swapChainPresenter);
_outputBitmap = swapChainPresenter.Bitmap;
_deviceContext = _device.ImmediateContext;
// Create RenderTargetView from the backbuffer.
var backBuffer = Texture2D.FromSwapChain(_swapChain, 0);
_renderTargetView = _device.CreateRenderTargetView(backBuffer);
// Create the depth buffer
var depthBuffer = _device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
BindFlags = BindFlags.DepthStencil
});
// Create the depth buffer view
_depthView = _device.CreateDepthStencilView(depthBuffer);
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/TechDemos/Resources/TextureSampling/Texture.fx", "VS", "vs_4_0");
var vertexShader = _device.CreateVertexShader(vertexShaderByteCode);
var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/TechDemos/Resources/TextureSampling/Texture.fx", "PS", "ps_4_1");
var pixelShader = _device.CreatePixelShader(pixelShaderByteCode);
// Layout from VertexShader input signature
var layout = _device.CreateInputLayout(
new[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0, 16)
}, vertexShaderByteCode);
// Instantiate Vertex buiffer from vertex data
var vertices = _device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
{
// 3D coordinates UV Texture coordinates
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Front
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, // BACK
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Top
-1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Bottom
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Left
-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Right
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f
});
// Create Constant Buffer
_constantBuffer = _device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<Matrix>(),
BindFlags = BindFlags.ConstantBuffer
});
// Load texture and create sampler
var textureStream = resourceLoader.GetStream(
//.........这里部分代码省略.........
示例8: LoadPipeline
private void LoadPipeline(RenderForm form)
{
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
viewport.Width = width;
viewport.Height = height;
viewport.MaxDepth = 1.0f;
scissorRect.Right = width;
scissorRect.Bottom = height;
#if DEBUG
// Enable the D3D12 debug layer.
{
DebugInterface.Get().EnableDebugLayer();
}
#endif
device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_11_0);
using (var factory = new Factory4())
{
// Describe and create the command queue.
CommandQueueDescription queueDesc = new CommandQueueDescription(CommandListType.Direct);
commandQueue = device.CreateCommandQueue(queueDesc);
// Describe and create the swap chain.
SwapChainDescription swapChainDesc = new SwapChainDescription()
{
BufferCount = FrameCount,
ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
Usage = Usage.RenderTargetOutput,
SwapEffect = SwapEffect.FlipDiscard,
OutputHandle = form.Handle,
//Flags = SwapChainFlags.None,
SampleDescription = new SampleDescription(1, 0),
IsWindowed = true
};
SwapChain tempSwapChain = new SwapChain(factory, commandQueue, swapChainDesc);
swapChain = tempSwapChain.QueryInterface<SwapChain3>();
tempSwapChain.Dispose();
frameIndex = swapChain.CurrentBackBufferIndex;
}
// Create descriptor heaps.
// Describe and create a render target view (RTV) descriptor heap.
DescriptorHeapDescription rtvHeapDesc = new DescriptorHeapDescription()
{
DescriptorCount = FrameCount,
Flags = DescriptorHeapFlags.None,
Type = DescriptorHeapType.RenderTargetView
};
renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc);
rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView);
// Create frame resources.
CpuDescriptorHandle rtvHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart;
for (int n = 0; n < FrameCount; n++)
{
renderTargets[n] = swapChain.GetBackBuffer<Resource>(n);
device.CreateRenderTargetView(renderTargets[n], null, rtvHandle);
rtvHandle += rtvDescriptorSize;
}
//create depth buffer;
DescriptorHeapDescription dsvHeapDesc = new DescriptorHeapDescription()
{
DescriptorCount = FrameCount,
Flags = DescriptorHeapFlags.None,
Type = DescriptorHeapType.DepthStencilView
};
depthStencilViewHeap = device.CreateDescriptorHeap(dsvHeapDesc);
CpuDescriptorHandle dsvHandle = depthStencilViewHeap.CPUDescriptorHandleForHeapStart;
ClearValue depthOptimizedClearValue = new ClearValue()
{
Format = Format.D32_Float,
DepthStencil = new DepthStencilValue() { Depth = 1.0F, Stencil = 0 },
};
depthTarget = device.CreateCommittedResource(
new HeapProperties(HeapType.Default),
HeapFlags.None,
new ResourceDescription(ResourceDimension.Texture2D, 0, width, height, 1, 0, Format.D32_Float, 1, 0, TextureLayout.Unknown, ResourceFlags.AllowDepthStencil),
ResourceStates.DepthWrite, depthOptimizedClearValue);
var depthView = new DepthStencilViewDescription()
{
Format = Format.D32_Float,
Dimension = DepthStencilViewDimension.Texture2D,
Flags = DepthStencilViewFlags.None,
};
//bind depth buffer
device.CreateDepthStencilView(depthTarget, null, dsvHandle);
commandAllocator = device.CreateCommandAllocator(CommandListType.Direct);
bundleAllocator = device.CreateCommandAllocator(CommandListType.Bundle);
//.........这里部分代码省略.........
示例9: 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 the depth buffer
var depthBuffer = device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
BindFlags = BindFlags.DepthStencil
});
// Create the depth buffer view
_depthView = device.CreateDepthStencilView(depthBuffer);
// Load model.
var modelLoader = new ModelLoader(device, TextureLoader.CreateTextureFromStream);
_model = modelLoader.Load("Modules/SampleBrowser/Samples/ModelLoading/Car/car.obj");
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/ModelLoading/ModelLoading.fx", "VS", "vs_4_0");
var vertexShader = device.CreateVertexShader(vertexShaderByteCode);
var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/ModelLoading/ModelLoading.fx", "PS", "ps_4_0");
var pixelShader = device.CreatePixelShader(pixelShaderByteCode);
_model.SetInputLayout(device, vertexShaderByteCode.InputSignature);
var sampler = device.CreateSamplerState(new SamplerStateDescription
{
Filter = Filter.MinMagMipPoint,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
BorderColor = Color4.Black,
ComparisonFunction = Comparison.Never,
MaximumAnisotropy = 16,
MipLodBias = 0,
MinimumLod = 0,
MaximumLod = 16,
});
// Create constant buffers.
_vertexConstantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<VertexShaderData>(),
BindFlags = BindFlags.ConstantBuffer
});
_pixelConstantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<PixelShaderData>(),
BindFlags = BindFlags.ConstantBuffer
});
// Prepare all the stages
_deviceContext.VertexShader.SetConstantBuffers(0, _vertexConstantBuffer);
_deviceContext.VertexShader.Shader = vertexShader;
_deviceContext.PixelShader.SetConstantBuffers(0, _pixelConstantBuffer);
_deviceContext.PixelShader.Shader = pixelShader;
_deviceContext.PixelShader.SetSamplers(0, sampler);
_vertexShaderData = new VertexShaderData();
_pixelShaderData = new PixelShaderData
{
LightDirection = new Vector4(Vector3.Normalize(new Vector3(0.5f, 0, -1)), 1)
};
_deviceContext.SetBufferData(_pixelConstantBuffer, ref _pixelShaderData);
// Setup targets and viewport for rendering
_deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, width, height, 0.0f, 1.0f));
_deviceContext.OutputMerger.SetTargets(_depthView, _renderTargetView);
//_deviceContext.Rasterizer.State = device.CreateRasterizerState(new Pipeline.Rasterizer.RasterizerStateDescription
//{
// FillMode = Pipeline.Rasterizer.FillMode.Wireframe
//});
// Prepare matrices
_projection = Matrix.PerspectiveFovLH(MathUtil.Pi / 3.0f,
width / (float) height, 1f, 1000.0f);
return swapChainPresenter.Bitmap;
}
示例10: 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 the depth buffer
var depthBuffer = device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
BindFlags = BindFlags.DepthStencil
});
// Create the depth buffer view
_depthView = device.CreateDepthStencilView(depthBuffer);
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/MiniCubeTexture/MiniCubeTexture.fx", "VS", "vs_4_0");
var vertexShader = device.CreateVertexShader(vertexShaderByteCode);
var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/MiniCubeTexture/MiniCubeTexture.fx", "PS", "ps_4_0");
var pixelShader = device.CreatePixelShader(pixelShaderByteCode);
// Layout from VertexShader input signature
var layout = device.CreateInputLayout(
new[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0, 16)
}, vertexShaderByteCode);
// Instantiate Vertex buiffer from vertex data
var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
{
// 3D coordinates UV Texture coordinates
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Front
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, // BACK
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Top
-1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Bottom
1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f,-1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f,-1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f,-1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f, // Left
-1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f, // Right
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f
});
// Create Constant Buffer
_constantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<Matrix>(),
BindFlags = BindFlags.ConstantBuffer
});
// Load texture and create sampler
var textureStream = _resourceLoader.GetStream(
"Modules/SampleBrowser/Samples/MiniCubeTexture/GeneticaMortarlessBlocks.jpg",
GetType().Assembly.FullName);
//.........这里部分代码省略.........
示例11: Initialize
public override WriteableBitmap Initialize(Device device)
{
// 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 the depth buffer
var depthBuffer = device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 1,
MipLevels = 1,
Width = Width,
Height = Height,
BindFlags = BindFlags.DepthStencil
});
// Create the depth buffer view
_depthView = device.CreateDepthStencilView(depthBuffer);
// Create cube map resources.
var cubeMapTexture = device.CreateTexture2D(new Texture2DDescription
{
Width = CubeMapSize,
Height= CubeMapSize,
ArraySize = 6,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
MipLevels = 1
});
_renderTargetViewCube = device.CreateRenderTargetView(cubeMapTexture);
_resourceViewCube = device.CreateShaderResourceView(cubeMapTexture);
var depthBufferCube = device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 6,
MipLevels = 1,
Width = CubeMapSize,
Height = CubeMapSize,
BindFlags = BindFlags.DepthStencil
});
_depthViewCube = device.CreateDepthStencilView(depthBufferCube);
// Load model.
var modelLoader = new ModelLoader(device, TextureLoader.CreateTextureFromStream);
_model = modelLoader.Load("Modules/SampleBrowser/Samples/EnvironmentMapping/teapot.obj");
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "VS_CubeMap", "vs_4_0");
_vertexShaderCubeMap = device.CreateVertexShader(vertexShaderByteCode);
_vertexShaderStandard = device.CreateVertexShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "VS_Standard", "vs_4_0"));
_geometryShaderCubeMap = device.CreateGeometryShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "GS_CubeMap", "gs_4_0"));
_pixelShaderCubeMap = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_CubeMap", "ps_4_0"));
_pixelShaderStandard = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_Standard", "ps_4_0"));
_pixelShaderReflective = device.CreatePixelShader(ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/EnvironmentMapping/EnvironmentMapping.fx", "PS_Reflective", "ps_4_0"));
_model.SetInputLayout(device, vertexShaderByteCode.InputSignature);
var sampler = device.CreateSamplerState(SamplerStateDescription.Default);
// Create constant buffers.
_vertexConstantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<VertexShaderData>(),
BindFlags = BindFlags.ConstantBuffer
});
_geometryConstantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<GeometryShaderData>(),
BindFlags = BindFlags.ConstantBuffer
});
var pixelConstantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<PixelShaderData>(),
BindFlags = BindFlags.ConstantBuffer
});
// Prepare all the stages
_deviceContext.VertexShader.SetConstantBuffers(0, _vertexConstantBuffer);
_deviceContext.GeometryShader.SetConstantBuffers(0, _geometryConstantBuffer);
_deviceContext.PixelShader.SetConstantBuffers(0, pixelConstantBuffer);
_deviceContext.PixelShader.SetSamplers(0, sampler);
_vertexShaderData = new VertexShaderData();
_view1 = Matrix.LookAtLH(Vector3.Zero, new Vector3(1, 0, 0), Vector3.UnitY);
_view2 = Matrix.LookAtLH(Vector3.Zero, new Vector3(-1, 0, 0), Vector3.UnitY);
_view3 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 1, 0), -Vector3.UnitZ);
_view4 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, -1, 0), Vector3.UnitZ);
_view5 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 0, 1), Vector3.UnitY);
_view6 = Matrix.LookAtLH(Vector3.Zero, new Vector3(0, 0, -1), Vector3.UnitY);
var from = new Vector3(0, 30, 70);
var to = new Vector3(0, 0, 0);
// Prepare matrices
//.........这里部分代码省略.........
示例12: LoadPipeline
private void LoadPipeline(RenderForm form)
{
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
viewport.Width = width;
viewport.Height = height;
viewport.MaxDepth = 1.0f;
scissorRect.Right = width;
scissorRect.Bottom = height;
#if DEBUG
// Enable the D3D12 debug layer.
{
DebugInterface.Get().EnableDebugLayer();
}
#endif
device = new Device(null, SharpDX.Direct3D.FeatureLevel.Level_12_0);
using (var factory = new Factory4())
{
// Describe and create the command queue.
CommandQueueDescription queueDesc = new CommandQueueDescription(CommandListType.Direct);
commandQueue = device.CreateCommandQueue(queueDesc);
// Describe and create the swap chain.
SwapChainDescription swapChainDesc = new SwapChainDescription()
{
BufferCount = FrameCount,
ModeDescription = new ModeDescription(width, height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
Usage = Usage.RenderTargetOutput,
SwapEffect = SwapEffect.FlipDiscard,
OutputHandle = form.Handle,
//Flags = SwapChainFlags.None,
SampleDescription = new SampleDescription(1, 0),
IsWindowed = true
};
SwapChain tempSwapChain = new SwapChain(factory, commandQueue, swapChainDesc);
swapChain = tempSwapChain.QueryInterface<SwapChain3>();
tempSwapChain.Dispose();
frameIndex = swapChain.CurrentBackBufferIndex;
}
// Create descriptor heaps.
// Describe and create a render target view (RTV) descriptor heap.
DescriptorHeapDescription rtvHeapDesc = new DescriptorHeapDescription()
{
DescriptorCount = FrameCount,
Flags = DescriptorHeapFlags.None,
Type = DescriptorHeapType.RenderTargetView
};
renderTargetViewHeap = device.CreateDescriptorHeap(rtvHeapDesc);
rtvDescriptorSize = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.RenderTargetView);
//Init Direct3D11 device from Direct3D12 device
device11 = SharpDX.Direct3D11.Device.CreateFromDirect3D12(device, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, null, null, commandQueue);
deviceContext11 = device11.ImmediateContext;
device11on12 = device11.QueryInterface<SharpDX.Direct3D11.ID3D11On12Device>();
var d2dFactory = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.MultiThreaded);
// Create frame resources.
CpuDescriptorHandle rtvHandle = renderTargetViewHeap.CPUDescriptorHandleForHeapStart;
for (int n = 0; n < FrameCount; n++)
{
renderTargets[n] = swapChain.GetBackBuffer<Resource>(n);
device.CreateRenderTargetView(renderTargets[n], null, rtvHandle);
rtvHandle += rtvDescriptorSize;
//init Direct2D surfaces
SharpDX.Direct3D11.D3D11ResourceFlags format = new SharpDX.Direct3D11.D3D11ResourceFlags()
{
BindFlags = (int)SharpDX.Direct3D11.BindFlags.RenderTarget,
CPUAccessFlags = (int)SharpDX.Direct3D11.CpuAccessFlags.None
};
device11on12.CreateWrappedResource(
renderTargets[n], format,
(int)ResourceStates.Present,
(int)ResourceStates.RenderTarget,
typeof(SharpDX.Direct3D11.Resource).GUID,
out wrappedBackBuffers[n]);
//Init direct2D surface
var d2dSurface = wrappedBackBuffers[n].QueryInterface<Surface>();
direct2DRenderTarget[n] = new SharpDX.Direct2D1.RenderTarget(d2dFactory, d2dSurface, new SharpDX.Direct2D1.RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)));
d2dSurface.Dispose();
}
commandAllocator = device.CreateCommandAllocator(CommandListType.Direct);
d2dFactory.Dispose();
//Init font
var directWriteFactory = new SharpDX.DirectWrite.Factory();
textFormat = new SharpDX.DirectWrite.TextFormat(directWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.Bold, SharpDX.DirectWrite.FontStyle.Normal, 48) { TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading, ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near };
textBrush = new SharpDX.Direct2D1.SolidColorBrush(direct2DRenderTarget[0], Color.White);
//.........这里部分代码省略.........
示例13: Initialize
public override WriteableBitmap Initialize(Device device)
{
const int width = 400;
const int height = 300;
// 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 the depth buffer
var depthBuffer = device.CreateTexture2D(new Texture2DDescription
{
ArraySize = 1,
MipLevels = 1,
Width = width,
Height = height,
BindFlags = BindFlags.DepthStencil
});
// Create the depth buffer view
_depthView = device.CreateDepthStencilView(depthBuffer);
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/MiniCube/MiniCube.fx", "VS", "vs_4_0");
var vertexShader = device.CreateVertexShader(vertexShaderByteCode);
var pixelShaderByteCode = ShaderCompiler.CompileFromFile("Modules/SampleBrowser/Samples/MiniCube/MiniCube.fx", "PS", "ps_4_0");
var pixelShader = device.CreatePixelShader(pixelShaderByteCode);
// Layout from VertexShader input signature
var layout = device.CreateInputLayout(
new[]
{
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 0)
}, vertexShaderByteCode);
// Instantiate Vertex buffer from vertex data
var vertices = device.CreateBuffer(new BufferDescription(BindFlags.VertexBuffer), new[]
{
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front
new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK
new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top
new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom
new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f),
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left
new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f),
new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right
new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f),
new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f)
});
// Create Constant Buffer
_constantBuffer = device.CreateBuffer(new BufferDescription
{
SizeInBytes = Utilities.SizeOf<Matrix>(),
BindFlags = BindFlags.ConstantBuffer
});
// Prepare all the stages
_deviceContext.InputAssembler.InputLayout = layout;
_deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
_deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 0, Utilities.SizeOf<Vector4>() * 2));
_deviceContext.VertexShader.SetConstantBuffers(0, _constantBuffer);
//.........这里部分代码省略.........