本文整理汇总了C#中DataStream.Release方法的典型用法代码示例。如果您正苦于以下问题:C# DataStream.Release方法的具体用法?C# DataStream.Release怎么用?C# DataStream.Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataStream
的用法示例。
在下文中一共展示了DataStream.Release方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main()
{
var form = new RenderForm("SharpDX - MiniTri Direct3D 11 Sample");
// SwapChain description
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
};
// Create Device and SwapChain
Device device;
SwapChain swapChain;
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain);
var context = device.ImmediateContext;
// Ignore all windows events
Factory factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
// New RenderTargetView from the backbuffer
Texture2D backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
var renderView = new RenderTargetView(device, backBuffer);
// Compile Vertex and Pixel shaders
var vertexShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "VS", "vs_4_0", ShaderFlags.None,
EffectFlags.None);
var vertexShader = new VertexShader(device, vertexShaderByteCode);
var pixelShaderByteCode = ShaderBytecode.CompileFromFile("MiniTri.fx", "PS", "ps_4_0", ShaderFlags.None,
EffectFlags.None);
var pixelShader = new PixelShader(device, pixelShaderByteCode);
// Layout from VertexShader input signature
var 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)
});
// Write vertex data to a datastream
var stream = new DataStream(32*3, true, true);
stream.WriteRange(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)
});
stream.Position = 0;
// Instantiate Vertex buiffer from vertex data
var vertices = new Buffer(device, stream, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 32*3,
Usage = ResourceUsage.Default,
StructureByteStride = 0
});
stream.Release();
// Prepare All the stages
context.InputAssembler.SetInputLayout(layout);
context.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 32, 0));
context.VertexShader.Set(vertexShader);
context.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
context.PixelShader.Set(pixelShader);
context.OutputMerger.SetTargets(renderView);
// Main loop
RenderLoop.Run(form, () =>
{
context.ClearRenderTargetView(renderView, new Color4(1.0f, 0.0f, 0.0f, 0.0f));
context.Draw(3, 0);
swapChain.Present(0, PresentFlags.None);
});
// Release all resources
vertexShaderByteCode.Release();
vertexShader.Release();
pixelShaderByteCode.Release();
pixelShader.Release();
vertices.Release();
layout.Release();
renderView.Release();
backBuffer.Release();
context.ClearState();
context.Flush();
device.Release();
context.Release();
swapChain.Release();
//.........这里部分代码省略.........