public void Update(DX11RenderContext context, int w, int h, SampleDescription sd) { if (this.currentmode == eDepthBufferMode.Standard) { DX11DepthStencil ds; if (this.NeedReset || !this.depthoutputpin.IOObject[0].Data.ContainsKey(context)) { if (this.depthoutputpin.IOObject[0] != null) { this.depthoutputpin.IOObject[0].Dispose(context); } if (sd.Count > 1) { if (!context.IsAtLeast101) { host.Log(TLogType.Warning, "Device Feature Level Needs at least 10.1 to create Multisampled Depth Buffer, rolling back to 1"); sd.Count = 1; } } ds = new DX11DepthStencil(context, w, h, sd, DeviceFormatHelper.GetFormat(this.depthformatpin.IOObject[0].Name)); #if DEBUG ds.Resource.DebugName = "DepthStencil"; #endif this.depthoutputpin.IOObject[0][context] = ds; } } }
public void Update(DX11RenderContext context) { Device device = context.Device; if (this.spmax == 0) { return; } if (this.updateddevices.Contains(context)) { return; } if (!this.FOutTexture[0].Contains(context)) { for (int i = 0; i < this.FInElementCount[0]; i++) { var rt = new DX11RenderTarget2D(context, (int)this.FInSize[i].X, (int)this.FInSize[i].Y, new SampleDescription(1, 0), DeviceFormatHelper.GetFormat(this.FInFormat[i]), this.FInMips[i], 0, false, false); this.FOutTexture[i][context] = rt; if (this.FInDepthBuffer[0]) { Format depthfmt = DeviceFormatHelper.GetFormat(this.depthformatpin[0].Name); var db = new DX11DepthStencil(context, (int)this.FInSize[i].X, (int)this.FInSize[i].Y, new SampleDescription(1, 0), depthfmt); this.FOutDepthTexture[i][context] = db; } } } this.updateddevices.Add(context); }
public void CreateD32() { DX11DepthStencil d = new DX11DepthStencil(this.Device, 320, 240, eDepthFormat.d32); Assert.IsNotNull(d.Texture, "Texture Is Null"); Assert.IsNotNull(d.ShaderView, "Shader View Is Null"); Assert.IsNotNull(d.DepthView, "Depth View Is Null"); if (Device.IsFeatureLevel11) { Assert.IsNotNull(d.ReadOnlyView, "Read Only View Is Null"); } else { Assert.IsNull(d.ReadOnlyView, "Read Only View Should Be Null"); } Assert.IsNull(d.Stencil, "Stencil is Not Null"); d.Dispose(); }
public void Update(DX11RenderContext context, int w, int h, SampleDescription sd) { if (this.currentmode == eDepthBufferMode.Standard) { DX11DepthStencil ds; if (this.NeedReset || !this.depthoutputpin.IOObject[0].Contains(context)) { if (this.depthoutputpin.IOObject[0] != null) { this.depthoutputpin.IOObject[0].Dispose(context); } Format depthfmt = DeviceFormatHelper.GetFormat(this.depthformatpin.IOObject[0].Name); sd = this.TrySampleDescription(context, sd); ds = new DX11DepthStencil(context, w, h, sd, depthfmt); #if DEBUG ds.Resource.DebugName = "DepthStencil"; #endif this.depthoutputpin.IOObject[0][context] = ds; } } if (this.currentmode == eDepthBufferMode.WriteOnly) { DX11WriteOnlyDepthStencil ds; if (this.NeedReset || !this.writeOnlyDepth.Contains(context)) { this.writeOnlyDepth.Dispose(context); Format depthfmt = DeviceFormatHelper.GetFormat(this.depthformatpin.IOObject[0].Name); sd = this.TrySampleDescription(context, sd); ds = new DX11WriteOnlyDepthStencil(context, w, h, sd, depthfmt); this.writeOnlyDepth[context] = ds; } } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); RenderForm form = new RenderForm("Kinect Camera Joint sample"); RenderDevice device = new RenderDevice(SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug); RenderContext context = new RenderContext(device); DX11SwapChain swapChain = DX11SwapChain.FromHandle(device, form.Handle); DX11DepthStencil depthStencil = new DX11DepthStencil(device, swapChain.Width, swapChain.Height, eDepthFormat.d24s8); //VertexShader vertexShader = ShaderCompiler.CompileFromFile<VertexShader>(device, "ColorJointView.fx", "VS"); SharpDX.D3DCompiler.ShaderSignature signature; VertexShader vertexShader = ShaderCompiler.CompileFromFile(device, "CameraJointView.fx", "VS_Color", out signature); PixelShader pixelShader = ShaderCompiler.CompileFromFile <PixelShader>(device, "CameraJointView.fx", "PS_Color"); VertexShader vertexShaderLine = ShaderCompiler.CompileFromFile <VertexShader>(device, "CameraJointView.fx", "VS"); PixelShader pixelShaderLine = ShaderCompiler.CompileFromFile <PixelShader>(device, "CameraJointView.fx", "PS_White"); JointTableIndexBuffer indexBuffer = new JointTableIndexBuffer(device, 6); DX11IndexedGeometry cube = device.Primitives.Box(new Box() { Size = new Vector3(0.05f) }); DX11InstancedIndexedDrawer drawer = new DX11InstancedIndexedDrawer(); cube.AssignDrawer(drawer); InputLayout layout; var bc = new ShaderBytecode(signature); cube.ValidateLayout(bc, out layout); KinectSensor sensor = KinectSensor.GetDefault(); sensor.Open(); Color4[] statusColor = new Color4[] { Color.Red, Color.Yellow, Color.Green }; cbCamera camera = new cbCamera(); camera.Projection = Matrix.PerspectiveFovLH(1.57f, 1.3f, 0.1f, 100.0f); camera.View = Matrix.Translation(0.0f, 0.0f, 2.0f); camera.Projection.Transpose(); camera.View.Transpose(); ConstantBuffer <cbCamera> cameraBuffer = new ConstantBuffer <cbCamera>(device); cameraBuffer.Update(context, ref camera); DX11StructuredBuffer colorTableBuffer = DX11StructuredBuffer.CreateImmutable <Color4>(device, statusColor); bool doQuit = false; bool doUpload = false; int bodyCount = 0; KinectBody[] bodyFrame = null; BodyCameraPositionBuffer positionBuffer = new BodyCameraPositionBuffer(device); BodyJointStatusBuffer statusBuffer = new BodyJointStatusBuffer(device); KinectSensorBodyFrameProvider provider = new KinectSensorBodyFrameProvider(sensor); provider.FrameReceived += (sender, args) => { bodyFrame = args.FrameData; doUpload = true; }; form.KeyDown += (sender, args) => { if (args.KeyCode == Keys.Escape) { doQuit = true; } }; context.Context.OutputMerger.DepthStencilState = device.DepthStencilStates.LessReadWrite; context.Context.Rasterizer.State = device.RasterizerStates.BackCullSolid; RenderLoop.Run(form, () => { if (doQuit) { form.Dispose(); return; } if (doUpload) { var tracked = bodyFrame.TrackedOnly(); bodyCount = tracked.Count(); positionBuffer.Copy(context, tracked); statusBuffer.Copy(context, tracked); drawer.InstanceCount = tracked.Count() * Microsoft.Kinect.Body.JointCount; } context.RenderTargetStack.Push(depthStencil, false, swapChain); context.Context.ClearRenderTargetView(swapChain.RenderView, SharpDX.Color.Black); depthStencil.Clear(context); /*Position buffer and cbuffers are the same data and in same slot, * so we bind them only once*/ context.Context.VertexShader.SetShaderResource(0, positionBuffer.ShaderView); context.Context.VertexShader.SetConstantBuffer(0, cameraBuffer.Buffer); //Draw lines context.Context.PixelShader.Set(pixelShaderLine); context.Context.VertexShader.Set(vertexShaderLine); //Attach index buffer, null topology since we fetch indexBuffer.AttachWithLayout(context); indexBuffer.Draw(context, bodyCount); //Draw cubes cube.Bind(context, layout); context.Context.VertexShader.Set(vertexShader); context.Context.PixelShader.Set(pixelShader); context.Context.VertexShader.SetShaderResource(1, statusBuffer.ShaderView); context.Context.VertexShader.SetShaderResource(2, colorTableBuffer.ShaderView); cube.Draw(context); context.RenderTargetStack.Pop(); swapChain.Present(0, SharpDX.DXGI.PresentFlags.None); }); swapChain.Dispose(); depthStencil.Dispose(); context.Dispose(); device.Dispose(); positionBuffer.Dispose(); statusBuffer.Dispose(); colorTableBuffer.Dispose(); cameraBuffer.Dispose(); provider.Dispose(); cube.Dispose(); layout.Dispose(); pixelShader.Dispose(); vertexShader.Dispose(); pixelShaderLine.Dispose(); vertexShaderLine.Dispose(); indexBuffer.Dispose(); sensor.Close(); }
public void Unlock(DX11DepthStencil target) { this.depthpool.UnLock(target); }
public void Render(DX11RenderContext context) { Device device = context.Device; //Just in case if (!this.updateddevices.Contains(context)) { this.Update(context); } if (this.rendereddevices.Contains(context)) { return; } if (this.FInEnabled[0]) { if (this.BeginQuery != null) { this.BeginQuery(context); } int sliceCount = this.FInElementCount[0]; for (int i = 0; i < sliceCount; i++) { DX11RenderTarget2D target = this.FOutTexture[i][context]; DX11DepthStencil depth = null; bool viewportpop = this.FInViewPort.IsConnected; if (this.FInDepthBuffer[0]) { depth = this.FOutDepthTexture[i][context]; } if (depth != null && this.FInClearDepth[i]) { context.CurrentDeviceContext.ClearDepthStencilView(depth.DSV, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); } if (this.FInClear[i]) { context.CurrentDeviceContext.ClearRenderTargetView(target.RTV, this.FInBgColor[i]); } if (depth != null) { context.RenderTargetStack.Push(depth, false, target); } else { context.RenderTargetStack.Push(target); } if (this.FInLayer.IsConnected) { settings.ViewportIndex = i; settings.ViewportCount = sliceCount; settings.ApplyTransforms(this.FInView[i], this.FInProjection[i], this.FInAspect[i], this.FInCrop[i]); settings.RenderWidth = target.Width; settings.RenderHeight = target.Height; settings.RenderDepth = 1; settings.BackBuffer = null; settings.CustomSemantics.Clear(); settings.ResourceSemantics.Clear(); if (viewportpop) { float cw = this.FInSize[i].X; float ch = this.FInSize[i].Y; context.RenderTargetStack.PushViewport(this.FInViewPort[i].Normalize(cw, ch)); } for (int j = 0; j < this.FInLayer.SliceCount; j++) { try { this.FInLayer[j][context].Render(context, settings); } catch (Exception ex) { Console.WriteLine(ex.Message); } } if (viewportpop) { context.RenderTargetStack.Pop(); } } context.RenderTargetStack.Pop(); if (this.FInMips[i]) { context.CurrentDeviceContext.GenerateMips(this.FOutTexture[i][context].SRV); } } if (this.EndQuery != null) { this.EndQuery(context); } this.rendereddevices.Add(context); } }