本文整理汇总了C#中ShaderResourceView.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ShaderResourceView.Dispose方法的具体用法?C# ShaderResourceView.Dispose怎么用?C# ShaderResourceView.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderResourceView
的用法示例。
在下文中一共展示了ShaderResourceView.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//.........这里部分代码省略.........
// Load effect from file. It is a basic effect that renders a full screen quad through
// an ortho projectio=n matrix
effect = Effect.FromFile(device, "Texture.fx", "fx_4_0", ShaderFlags.Debug, EffectFlags.None);
EffectTechnique technique = effect.GetTechniqueByIndex(0);
EffectPass pass = technique.GetPassByIndex(0);
InputLayout layout = new InputLayout(device, pass.Description.Signature, new[]
{
new InputElement(
"POSITION", 0,
Format.
R32G32B32A32_Float,
0, 0),
new InputElement(
"TEXCOORD", 0,
Format.
R32G32_Float,
16, 0)
});
//effect.GetVariableByName("mWorld").AsMatrix().SetMatrix(
// Matrix.Translation(Layout.OrthographicTransform(Vector2.Zero, 99, size)));
//effect.GetVariableByName("mView").AsMatrix().SetMatrix(qCam.View);
//effect.GetVariableByName("mProjection").AsMatrix().SetMatrix(qCam.OrthoProjection);
//effect.GetVariableByName("tDiffuse").AsResource().SetResource(srv);
// Set RT and Viewports
device.OutputMerger.SetTargets(renderView);
device.Rasterizer.SetViewports(new Viewport(0, 0, size.Width, size.Height, 0.0f, 1.0f));
// Create solid rasterizer state
RasterizerStateDescription rDesc = new RasterizerStateDescription()
{
CullMode = CullMode.None,
IsDepthClipEnabled = true,
FillMode = FillMode.Solid,
IsAntialiasedLineEnabled = false,
IsFrontCounterclockwise = true,
//IsMultisampleEnabled = true,
};
RasterizerState rState = RasterizerState.FromDescription(device, rDesc);
device.Rasterizer.State = rState;
Texture2DDescription rtDesc = new Texture2DDescription
{
ArraySize = 1,
Width = size.Width,
Height = size.Height,
BindFlags = BindFlags.RenderTarget,
CpuAccessFlags = CpuAccessFlags.None,
Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
MipLevels = 1,
SampleDescription = new SampleDescription(1, 0)
};
rtTex = new Texture2D(device, rtDesc);
rv = new RenderTargetView(device, rtTex);
stereoizedTexture = Make3D(sourceTexture);
//ResizeDevice(new Size(1920, 1080), true);
Console.WriteLine(form.ClientSize);
// Main Loop
MessagePump.Run(form, () =>
{
device.ClearRenderTargetView(renderView, Color.Cyan);
//device.InputAssembler.SetInputLayout(layout);
//device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
//device.OutputMerger.SetTargets(rv);
//device.InputAssembler.SetVertexBuffers(0,
// new VertexBufferBinding(vertices, 24, 0));
//device.InputAssembler.SetIndexBuffer(indices, Format.R16_UInt, 0);
//for (int i = 0; i < technique.Description.PassCount; ++i)
//{
// // Render the full screen quad
// pass.Apply();
// device.DrawIndexed(6, 0, 0);
//}
ResourceRegion stereoSrcBox = new ResourceRegion { Front = 0, Back = 1, Top = 0, Bottom = size.Height, Left = 0, Right = size.Width };
device.CopySubresourceRegion(stereoizedTexture, 0, stereoSrcBox, backBuffer, 0, 0, 0, 0);
//device.CopyResource(rv.Resource, backBuffer);
swapChain.Present(0, PresentFlags.None);
});
// Dispose resources
vertices.Dispose();
layout.Dispose();
effect.Dispose();
renderView.Dispose();
backBuffer.Dispose();
device.Dispose();
swapChain.Dispose();
rState.Dispose();
stereoizedTexture.Dispose();
sourceTexture.Dispose();
indices.Dispose();
srv.Dispose();
}
示例2: Main
//.........这里部分代码省略.........
device.Factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
Texture2D backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
var renderView = new RenderTargetView(device, backBuffer);
var bytecode = ShaderBytecode.CompileFromFile("Render.fx", "fx_5_0", ShaderFlags.None, EffectFlags.None);
var effect = new Effect(device, bytecode);
var technique = effect.GetTechniqueByIndex(0);
var pass = technique.GetPassByIndex(0);
String errors;
var computeByteCode = ShaderBytecode.CompileFromFile("compute.fx", "CS", "cs_5_0", ShaderFlags.None, EffectFlags.None, null, null, out errors);
var compute = new ComputeShader(device, computeByteCode);
// shader variable handles
var conwayResourceH = effect.GetVariableByName("tex").AsResource();
var resolutionInvH = effect.GetVariableByName("resolutionInv").AsVector();
resolutionInvH.Set(new Vector2(1.0f / form.ClientSize.Width, 1.0f / form.ClientSize.Height));
EffectVectorVariable lightPosSSH = effect.GetVariableByName("lightPosSS").AsVector();
// create texture, fill it with random data
Texture2DDescription textureDesc = new Texture2DDescription()
{
Width = form.ClientSize.Width,
Height = form.ClientSize.Height,
MipLevels = 1,
ArraySize = 1,
CpuAccessFlags = CpuAccessFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
OptionFlags = ResourceOptionFlags.None,
BindFlags = BindFlags.UnorderedAccess | BindFlags.ShaderResource,
Format = Format.R32_Float
};
var random = new Random();
var data = new float[form.ClientSize.Width * form.ClientSize.Height];
for (int i = 0; i < form.ClientSize.Width; ++i)
{
for (int j = 0; j < form.ClientSize.Height; ++j)
data[i * form.ClientSize.Height + j] = (float)random.Next(2);
}
DataStream ds = new DataStream(data, true, false);
DataRectangle dataRect = new DataRectangle(4 * form.ClientSize.Width, ds);
Texture2D conwayTex = new Texture2D(device, textureDesc, dataRect);
// Create SRV and UAV over the same texture
UnorderedAccessView conwayUAV = new UnorderedAccessView(device, conwayTex);
ShaderResourceView conwaySRV = new ShaderResourceView(device, conwayTex);
// On the more typical setup where you switch shaders,
// you will have to set the texture after every
conwayResourceH.SetResource(conwaySRV);
device.ImmediateContext.OutputMerger.SetTargets(renderView);
device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));
device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
Vector2 lightPosSS;
float angle = 0;
MessagePump.Run(form, () =>
{
// this does the light rotation
angle += 0.002f;
lightPosSS = new Vector2((float)Math.Sin(angle) * 0.5f + 0.5f, (float)Math.Cos(angle) * 0.5f + 0.5f);
lightPosSSH.Set(lightPosSS);
device.ImmediateContext.ComputeShader.Set(compute);
device.ImmediateContext.ComputeShader.SetUnorderedAccessView(conwayUAV, 0);
device.ImmediateContext.Dispatch(form.ClientSize.Width / 16 + 1, form.ClientSize.Height / 16 + 1, 1);
// After running the CS you have to unset UAV from the shader, so you can use it as SRV
device.ImmediateContext.ComputeShader.SetUnorderedAccessView(null, 0);
device.ImmediateContext.ClearRenderTargetView(renderView, Color.Black);
for (int i = 0; i < technique.Description.PassCount; ++i)
{
pass.Apply(device.ImmediateContext);
// No vertices are send as they are created in the vertex shader on the fly.
device.ImmediateContext.Draw(4, 0);
}
swapChain.Present(0, PresentFlags.None);
});
computeByteCode.Dispose();
conwayUAV.Dispose();
conwaySRV.Dispose();
conwayTex.Dispose();
ds.Dispose();
bytecode.Dispose();
effect.Dispose();
renderView.Dispose();
backBuffer.Dispose();
device.Dispose();
swapChain.Dispose();
}