本文整理汇总了C#中SharpDX.Windows.RenderForm.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# RenderForm.Dispose方法的具体用法?C# RenderForm.Dispose怎么用?C# RenderForm.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.Windows.RenderForm
的用法示例。
在下文中一共展示了RenderForm.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
RenderForm form = new RenderForm("Kinect color sample");
RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);
RenderContext context = new RenderContext(device);
DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle);
KinectSensor sensor = KinectSensor.GetDefault();
sensor.Open();
bool doQuit = false;
bool doUpload = false;
ColorRGBAFrameData currentData = null;
DynamicColorRGBATexture colorTexture = new DynamicColorRGBATexture(device);
KinectSensorColorRGBAFrameProvider provider = new KinectSensorColorRGBAFrameProvider(sensor);
provider.FrameReceived += (sender, args) => { currentData = args.FrameData; doUpload = true; };
form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } };
RenderLoop.Run(form, () =>
{
if (doQuit)
{
form.Dispose();
return;
}
if (doUpload)
{
colorTexture.Copy(context, currentData);
doUpload = false;
}
context.RenderTargetStack.Push(swapChain);
device.Primitives.ApplyFullTri(context, colorTexture.ShaderView);
device.Primitives.FullScreenTriangle.Draw(context);
context.RenderTargetStack.Pop();
swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);
});
swapChain.Dispose();
context.Dispose();
device.Dispose();
colorTexture.Dispose();
provider.Dispose();
sensor.Close();
}
示例2: Main
//.........这里部分代码省略.........
Height = worldSize.Height
}, 30f);
emitters[i].Modifiers.Add(new MoveModifier(), 60f);
};
var renderer = new PointSpriteRenderer(device, budget)
{
// EnableFastFade = true
};
var texture = Texture.FromFile(device, "Pixel.dds");
var fontDescription = new FontDescription
{
Height = 16,
FaceName = "Consolas",
PitchAndFamily = FontPitchAndFamily.Mono,
Quality = FontQuality.Draft
};
var font = new Font(device, fontDescription);
var totalTimer = Stopwatch.StartNew();
var updateTimer = new Stopwatch();
var renderTimer = new Stopwatch();
var totalTime = 0f;
foreach (var emitter in emitters)
{
emitter.Trigger(Coordinate.Origin);
}
float updateTime = 0f;
RenderLoop.Run(form, () =>
{
// ReSharper disable AccessToDisposedClosure
var frameTime = ((float)totalTimer.Elapsed.TotalSeconds) - totalTime;
totalTime = (float)totalTimer.Elapsed.TotalSeconds;
var mousePosition = form.PointToClient(RenderForm.MousePosition);
Task.WaitAll(
Task.Factory.StartNew(() =>
{
var mouseVector = new Vector3(mousePosition.X, mousePosition.Y, 0f);
var unprojected = Vector3.Unproject(mouseVector, 0, 0, renderSize.Width, renderSize.Height, 0f, 1f, wvp);
Parallel.ForEach(emitters, emitter => ((VortexModifier)emitter.Modifiers.ElementAt(1)).Position = new Coordinate(unprojected.X, unprojected.Y));
updateTimer.Restart();
Parallel.ForEach(emitters, emitter => emitter.Update(frameTime));
updateTimer.Stop();
updateTime = (float)updateTimer.Elapsed.TotalSeconds;
_updateTimes.Add(updateTime);
}),
Task.Factory.StartNew(() =>
{
device.Clear(ClearFlags.Target, Color.Black, 1f, 0);
device.BeginScene();
renderTimer.Restart();
for (int i = 0; i < numEmitters; i++)
{
renderer.Render(emitters[i], wvp, texture);
}
renderTimer.Stop();
var renderTime = (float)renderTimer.Elapsed.TotalSeconds;
var totalUpdateTime = 0f;
// foreach (var time in _updateTimes)
// {
// totalUpdateTime += time;
// }
// totalUpdateTime /= _updateTimes.Count;
//
// if(_updateTimes.Count > 100)
// _updateTimes.RemoveAt(0);
font.DrawText(null, String.Format("Time: {0}", totalTimer.Elapsed), 0, 0, Color.White);
font.DrawText(null, String.Format("Particles: {0:n0}", emitters[0].ActiveParticles * numEmitters), 0, 16, Color.White);
font.DrawText(null, String.Format("Update: {0:n4} ({1,8:P2})", updateTime, updateTime / 0.01666666f), 0, 32, Color.White);
font.DrawText(null, String.Format("Render: {0:n4} ({1,8:P2})", renderTime, renderTime / 0.01666666f), 0, 48, Color.White);
device.EndScene();
device.Present();
})
);
if (Keyboard.IsKeyDown(Key.Escape))
Environment.Exit(0);
// ReSharper restore AccessToDisposedClosure
});
form.Dispose();
font.Dispose();
device.Dispose();
direct3d.Dispose();
}
示例3: Main
public static void Main()
{
var form = new RenderForm("SimpleD3D9 by C#") { ClientSize = new Size(1024, 768) };
var device = new D3D9Device(
new Direct3D(),
CUDADevice.Default.ID,
DeviceType.Hardware,
form.Handle,
CreateFlags.HardwareVertexProcessing,
new PresentParameters(form.ClientSize.Width, form.ClientSize.Height));
var vertices = new VertexBuffer(device, Utilities.SizeOf<Vector4>()*Total, Usage.WriteOnly,
VertexFormat.None, Pool.Default);
var vertexElems = new []
{
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 12, DeclarationType.Ubyte4, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
var vertexDecl = new VertexDeclaration(device, vertexElems);
var worker = Worker.CreateByFunc(() => Generate(device));
var updater = new SimpleD3D9(GPUModuleTarget.Worker(worker));
var view = Matrix.LookAtLH(
new Vector3(0.0f, 3.0f, -2.0f), // the camera position
new Vector3(0.0f, 0.0f, 0.0f), // the look-at position
new Vector3(0.0f, 1.0f, 0.0f)); // the up direction
var proj = Matrix.PerspectiveFovLH(
(float) (Math.PI/4.0), // the horizontal field of view
1.0f,
1.0f,
100.0f);
device.SetTransform(TransformState.View, view);
device.SetTransform(TransformState.Projection, proj);
device.SetRenderState(RenderState.Lighting, false);
var vbres = RegisterVerticesResource(vertices);
var clock = System.Diagnostics.Stopwatch.StartNew();
RenderLoop.Run(form, () =>
{
var time = (float) (clock.Elapsed.TotalMilliseconds)/300.0f;
updater.Update(vbres, time);
// Now normal D3D9 rendering procedure.
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new ColorBGRA(0, 40, 100, 0), 1.0f, 0);
device.BeginScene();
device.VertexDeclaration = vertexDecl;
device.SetStreamSource(0, vertices, 0, Utilities.SizeOf<Vector4>());
// we use PointList as the graphics primitives
device.DrawPrimitives(SharpDX.Direct3D9.PrimitiveType.PointList, 0, Total);
device.EndScene();
device.Present();
});
UnregisterVerticesResource(vbres);
updater.Dispose();
worker.Dispose();
vertexDecl.Dispose();
vertices.Dispose();
device.Dispose();
form.Dispose();
}