本文整理汇总了C#中DataStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# DataStream.CopyTo方法的具体用法?C# DataStream.CopyTo怎么用?C# DataStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataStream
的用法示例。
在下文中一共展示了DataStream.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Pass
/// <summary>
/// The most general shader pass method.
/// </summary>
/// <param name="context">The device context to use.</param>
/// <param name="shader">The pixel shader.</param>
/// <param name="viewport">The render viewport.</param>
/// <param name="rtv">A render target.</param>
/// <param name="srv">Shader resources.</param>
/// <param name="uav">Unordered access views.</param>
/// <param name="cbuffer">A data stream to fill the constant buffer with.</param>
public void Pass(DeviceContext context, String shader, ViewportF viewport, RenderTargetView rtv, ShaderResourceView[] srv, UnorderedAccessView[] uav, DataStream cbuffer)
{
if (shader == null) throw new ArgumentNullException("Shader code cannot be null.");
context.PixelShader.Set(CompilePixelShader(Device, shader));
if (uav != null) context.OutputMerger.SetTargets(1, uav, new[] { rtv });
else context.OutputMerger.SetTargets(new[] { rtv });
if (srv != null) context.PixelShader.SetShaderResources(0, srv);
context.PixelShader.SetConstantBuffer(0, constantBuffer);
context.Rasterizer.SetViewports(new[] { viewport });
context.PixelShader.SetSampler(0, sampler);
if (cbuffer != null)
{
DataStream stream;
context.MapSubresource(constantBuffer, MapMode.WriteDiscard, MapFlags.None, out stream);
cbuffer.CopyTo(stream);
context.UnmapSubresource(constantBuffer, 0);
stream.Dispose();
}
ExecuteShaderPass(context);
}
示例2: CopyStream
/// <summary>
/// Convenience method to copy the contents of a DataStream into a
/// constant buffer. The buffer must have CPU read access, and its
/// position will be reset to zero before copying (by convention).
/// </summary>
/// <param name="context">Device context to use.</param>
/// <param name="buffer">Constant buffer.</param>
/// <param name="stream">The data stream.</param>
protected static void CopyStream(DeviceContext context, Buffer buffer, DataStream stream)
{
DataStream staging = null;
try
{
context.MapSubresource(buffer, MapMode.WriteDiscard, MapFlags.None, out staging);
stream.Position = 0; stream.CopyTo(staging);
context.UnmapSubresource(buffer, 0);
}
finally
{
if (staging != null) staging.Dispose();
}
}