本文整理汇总了C#中SharpDX.Direct3D11.PixelShader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# PixelShader.Dispose方法的具体用法?C# PixelShader.Dispose怎么用?C# PixelShader.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.Direct3D11.PixelShader
的用法示例。
在下文中一共展示了PixelShader.Dispose方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//.........这里部分代码省略.........
});
// Create Constant Buffer
var contantBuffer = new Buffer(device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
// Create Depth Buffer & View
var depthBuffer = new Texture2D(device, new Texture2DDescription()
{
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = form.ClientSize.Width,
Height = form.ClientSize.Height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
var depthView = new DepthStencilView(device, depthBuffer);
// Load texture and create sampler
var texture = Texture2D.FromFile<Texture2D>(device, "GeneticaMortarlessBlocks.jpg");
var textureView = new ShaderResourceView(device, texture);
var sampler = new SamplerState(device, new SamplerStateDescription()
{
Filter = Filter.MinMagMipLinear,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
BorderColor = Color.Black,
ComparisonFunction = Comparison.Never,
MaximumAnisotropy = 16,
MipLodBias = 0,
MinimumLod = 0,
MaximumLod = 16,
});
// Prepare All the stages
context.InputAssembler.InputLayout = layout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() + Utilities.SizeOf<Vector2>(), 0));
context.VertexShader.SetConstantBuffer(0, contantBuffer);
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.PixelShader.SetSampler(0, sampler);
context.PixelShader.SetShaderResource(0, textureView);
context.OutputMerger.SetTargets(depthView, renderView);
// Prepare matrices
var view = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY);
var proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, form.ClientSize.Width / (float)form.ClientSize.Height, 0.1f, 100.0f);
var viewProj = Matrix.Multiply(view, proj);
// Use clock
var clock = new Stopwatch();
clock.Start();
// Main loop
RenderLoop.Run(form, () =>
{
var time = clock.ElapsedMilliseconds / 1000.0f;
// Clear views
context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
context.ClearRenderTargetView(renderView, Color.Black);
// Update WorldViewProj Matrix
var worldViewProj = Matrix.RotationX(time) * Matrix.RotationY(time * 2) * Matrix.RotationZ(time * .7f) * viewProj;
worldViewProj.Transpose();
context.UpdateSubresource(ref worldViewProj, contantBuffer);
// Draw the cube
context.Draw(36, 0);
// Present!
swapChain.Present(0, PresentFlags.None);
});
// Release all resources
vertexShaderByteCode.Dispose();
vertexShader.Dispose();
pixelShaderByteCode.Dispose();
pixelShader.Dispose();
vertices.Dispose();
layout.Dispose();
renderView.Dispose();
backBuffer.Dispose();
context.ClearState();
context.Flush();
device.Dispose();
context.Dispose();
swapChain.Dispose();
factory.Dispose();
}
示例2: 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.None, desc, out device, out swapChain);
var context = device.ImmediateContext;
// Ignore all windows events
var factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAll);
// New RenderTargetView from the backbuffer
var 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)
});
// Instantiate Vertex buiffer from vertex data
var vertices = Buffer.Create(device, 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
context.InputAssembler.InputLayout = layout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertices, 32, 0));
context.VertexShader.Set(vertexShader);
context.Rasterizer.SetViewport(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, Color.Black);
context.Draw(3, 0);
swapChain.Present(0, PresentFlags.None);
});
// Release all resources
vertexShaderByteCode.Dispose();
vertexShader.Dispose();
pixelShaderByteCode.Dispose();
pixelShader.Dispose();
vertices.Dispose();
layout.Dispose();
renderView.Dispose();
backBuffer.Dispose();
context.ClearState();
context.Flush();
device.Dispose();
context.Dispose();
swapChain.Dispose();
factory.Dispose();
}
示例3: Main
//.........这里部分代码省略.........
// Use clock
var clock = new Stopwatch();
clock.Start();
// Declare texture for rendering
bool userResized = true;
Texture2D backBuffer = null;
RenderTargetView renderView = null;
Texture2D depthBuffer = null;
DepthStencilView depthView = null;
// Setup handler on resize form
form.UserResized += (sender, args) => userResized = true;
// Setup full screen mode change F5 (Full) F4 (Window)
form.KeyUp += (sender, args) =>
{
if (args.KeyCode == Keys.F5)
swapChain.SetFullscreenState(true, null);
else if (args.KeyCode == Keys.F4)
swapChain.SetFullscreenState(false, null);
else if (args.KeyCode == Keys.Escape)
form.Close();
};
// Main loop
RenderLoop.Run(form, () =>
{
// If Form resized
if (userResized)
{
// Dispose all previous allocated resources
ComObject.Dispose(ref backBuffer);
ComObject.Dispose(ref renderView);
ComObject.Dispose(ref depthBuffer);
ComObject.Dispose(ref depthView);
// Resize the backbuffer
swapChain.ResizeBuffers(desc.BufferCount, form.ClientSize.Width, form.ClientSize.Height, Format.Unknown, SwapChainFlags.None);
// Get the backbuffer from the swapchain
backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
// Renderview on the backbuffer
renderView = new RenderTargetView(device, backBuffer);
// Create the depth buffer
depthBuffer = new Texture2D(device, new Texture2DDescription()
{
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = form.ClientSize.Width,
Height = form.ClientSize.Height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
// Create the depth buffer view
depthView = new DepthStencilView(device, depthBuffer);
// Setup targets and viewport for rendering
示例4: Program
//.........这里部分代码省略.........
var sampler = new SamplerState(device, new SamplerStateDescription()
{
Filter = Filter.MinMagMipLinear,
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
BorderColor = Color.Black,
ComparisonFunction = Comparison.Never,
MaximumAnisotropy = 16,
MipLodBias = 0,
MinimumLod = 0,
MaximumLod = 16,
});
// Create Constant Buffers
var vertexConstantBuffer = new Buffer(device, Utilities.SizeOf<VertexShaderData>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
var pixelConstantBuffer = new Buffer(device, Utilities.SizeOf<PixelShaderData>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
// Prepare some of the stages. The others are mesh dependent and will be set later
context.VertexShader.Set(vertexShader);
context.Rasterizer.SetViewport(new Viewport(0, 0, form.Width, form.Height, 0.0f, 1.0f));
context.PixelShader.Set(pixelShader);
context.PixelShader.SetSampler(0, sampler);
context.OutputMerger.SetTargets(depthView, renderView);
context.VertexShader.SetConstantBuffer(0, vertexConstantBuffer);
context.PixelShader.SetConstantBuffer(0, pixelConstantBuffer);
//allocate data structs for the vertex and pixel constant buffers
VertexShaderData vsData = new VertexShaderData();
PixelShaderData psData = new PixelShaderData();
//set light position
psData.lightPos = new Vector4(0, 2.5f, 0, 0);
//update pixel shader constant buffer. Only need to do this once.
context.UpdateSubresource(ref psData, pixelConstantBuffer);
// Calc projection matrix
var proj = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, form.Width / (float)form.Height, 0.1f, 100.0f);
// Use clock
var clock = new Stopwatch();
clock.Start();
// Main loop
RenderLoop.Run(form, () =>
{
var time = clock.ElapsedMilliseconds / 1000.0f;
// Prepare matrices
Vector3 cameraPosition = new Vector3(0, 3, 5.0f);
Vector3 cameraLookAt = new Vector3(0, 2.0f, 0);
//rotate camera
Vector4 tempPos = Vector3.Transform(cameraPosition, Matrix.RotationY(0.2f * time));
cameraPosition = new Vector3(tempPos.X, tempPos.Y, tempPos.Z);
//calculate the view matrix
var view = Matrix.LookAtLH(cameraPosition, cameraLookAt, Vector3.UnitY);
var viewProj = Matrix.Multiply(view, proj);
// Clear views
context.ClearDepthStencilView(depthView, DepthStencilClearFlags.Depth, 1.0f, 0);
context.ClearRenderTargetView(renderView, Color.Black);
// Update transformation matrices
vsData.world = Matrix.Translation(0, -model.AABoxCentre.Y / 2, 0);
vsData.worldView = vsData.world * view;
vsData.worldViewProj = vsData.world * viewProj;
//transpose matrices before sending them to the shader
vsData.world.Transpose();
vsData.worldView.Transpose();
vsData.worldViewProj.Transpose();
//update vertex shader constant buffer
context.UpdateSubresource(ref vsData, vertexConstantBuffer);
// Draw the cube
model.Render(context);
// Present
swapChain.Present(0, PresentFlags.None);
});
// Release all resources
model.Dispose();
vertexShaderByteCode.Dispose();
vertexShader.Dispose();
pixelShaderByteCode.Dispose();
pixelShader.Dispose();
renderView.Dispose();
backBuffer.Dispose();
context.ClearState();
context.Flush();
device.Dispose();
context.Dispose();
swapChain.Dispose();
factory.Dispose();
}
示例5: Main
//.........这里部分代码省略.........
Matrix proj = Matrix.Identity;
// Use the clock
var clock = new Stopwatch();
clock.Start();
// Declare texture for rendering (even though we aren't
// using texture here :) ); we also set up our swap chain back buffer
bool userResized = true;
Texture2D backBuffer = null;
RenderTargetView renderView = null;
Texture2D depthBuffer = null;
DepthStencilView depthView = null;
// Set up the light, a grey ambient light and a white positional light
// The positional light is currently located above and behind the cube
// (because it's + in Y and + in Z)
Vector4 lightAmbCol = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);
Vector4 lightPntCol = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
Vector4 lightPntPos = new Vector4(200.0f, 100.0f, -10.0f, 1.0f);
// Handle events where we resize our window
form.UserResized += (sender, args) => userResized = true;
// Main loop: render the objects for each frame of our scene
RenderLoop.Run(form, () =>
{
// If the window was resized, we need to reorganise
// various properties of the window (don't worry about
// this right now)
if (userResized)
{
// Dispose all previous allocated resources
ComObject.Dispose(ref backBuffer);
ComObject.Dispose(ref renderView);
ComObject.Dispose(ref depthBuffer);
ComObject.Dispose(ref depthView);
// Resize the backbuffer
swapChain.ResizeBuffers(desc.BufferCount, form.ClientSize.Width, form.ClientSize.Height, Format.Unknown, SwapChainFlags.None);
// Get the backbuffer from the swapchain
backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
// Renderview on the backbuffer
renderView = new RenderTargetView(device, backBuffer);
// Create the depth buffer
depthBuffer = new Texture2D(device, new Texture2DDescription()
{
Format = Format.D32_Float_S8X24_UInt,
ArraySize = 1,
MipLevels = 1,
Width = form.ClientSize.Width,
Height = form.ClientSize.Height,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.DepthStencil,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
});
// Create the depth buffer view
depthView = new DepthStencilView(device, depthBuffer);
// Setup targets and viewport for rendering
示例6: InitializeOculus
//.........这里部分代码省略.........
int textureIndex = eyeTexture.SwapTextureSet.CurrentIndex++;
immediateContext.OutputMerger.SetRenderTargets(eyeTexture.DepthStencilView, eyeTexture.RenderTargetViews[textureIndex]);
immediateContext.ClearRenderTargetView(eyeTexture.RenderTargetViews[textureIndex], Color.Black);
immediateContext.ClearDepthStencilView(eyeTexture.DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0);
immediateContext.Rasterizer.SetViewport(eyeTexture.Viewport);
//added a custom rasterizer
immediateContext.Rasterizer.State = rasterizerState;
// Retrieve the eye rotation quaternion and use it to calculate the LookAt direction and the LookUp direction.
Quaternion rotationQuaternion = SharpDXHelpers.ToQuaternion(eyePoses[eyeIndex].Orientation);
Matrix rotationMatrix = Matrix.RotationQuaternion(rotationQuaternion);
Vector3 lookUp = Vector3.Transform(new Vector3(0, -1, 0), rotationMatrix).ToVector3();
Vector3 lookAt = Vector3.Transform(new Vector3(0, 0, 1), rotationMatrix).ToVector3();
Vector3 viewPosition = position - eyePoses[eyeIndex].Position.ToVector3();
//use this to get the first rotation to goal
Matrix world = Matrix.Scaling(1.0f) /** Matrix.RotationX(timeSinceStart*0.2f) */* Matrix.RotationY(timeSinceStart * 2 / 10f) /** Matrix.RotationZ(timeSinceStart*3/10f)*/;
Matrix viewMatrix = Matrix.LookAtRH(viewPosition, viewPosition + lookAt, lookUp);
Matrix projectionMatrix = OVR.ovrMatrix4f_Projection(eyeTexture.FieldOfView, 0.1f, 10.0f, OVR.ProjectionModifier.None).ToMatrix();
projectionMatrix.Transpose();
Matrix worldViewProjection = world * viewMatrix * projectionMatrix;
worldViewProjection.Transpose();
// Update the transformation matrix.
immediateContext.UpdateSubresource(ref worldViewProjection, constantBuffer);
// Draw the cube
//immediateContext.Draw(vertices.Length/2, 0);
immediateContext.DrawIndexed(indices.Length, 0, 0);
}
hmd.SubmitFrame(0, layers);
immediateContext.CopyResource(mirrorTextureD3D11, backBuffer);
swapChain.Present(0, PresentFlags.None);
if (newTextureArrived == true)
{
newTextureArrived = false;
DataBox map = device.ImmediateContext.MapSubresource(myTexture, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None);
//load the BitMapSource with appropriate formating (Format32bppPRGBA)
SharpDX.WIC.BitmapSource bitMap = LoadBitmap(new SharpDX.WIC.ImagingFactory(), streamTexture);
//string newFile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\img_merged.jpg";
//SharpDX.WIC.BitmapSource bitMap = LoadBitmapFromFile(new SharpDX.WIC.ImagingFactory(), newFile);
int width = bitMap.Size.Width;
int height = bitMap.Size.Height;
int stride = bitMap.Size.Width * 4;
bitMap.CopyPixels(stride, map.DataPointer, height * stride);
device.ImmediateContext.UnmapSubresource(myTexture, 0);
//bitMap.Dispose();
streamTexture.Seek(0, SeekOrigin.Begin);
}
});
#endregion
// Release all resources
inputLayout.Dispose();
constantBuffer.Dispose();
indexBuffer.Dispose();
vertexBuffer.Dispose();
inputLayout.Dispose();
shaderSignature.Dispose();
pixelShader.Dispose();
pixelShaderByteCode.Dispose();
vertexShader.Dispose();
vertexShaderByteCode.Dispose();
mirrorTextureD3D11.Dispose();
layers.Dispose();
eyeTextures[0].Dispose();
eyeTextures[1].Dispose();
immediateContext.ClearState();
immediateContext.Flush();
immediateContext.Dispose();
depthStencilState.Dispose();
depthStencilView.Dispose();
depthBuffer.Dispose();
backBufferRenderTargetView.Dispose();
backBuffer.Dispose();
swapChain.Dispose();
factory.Dispose();
// Disposing the device, before the hmd, will cause the hmd to fail when disposing.
// Disposing the device, after the hmd, will cause the dispose of the device to fail.
// It looks as if the hmd steals ownership of the device and destroys it, when it's shutting down.
// device.Dispose();
hmd.Dispose();
oculus.Dispose();
}