public void CreateDifferentRasteriserStatesWithNinjectUsingNamedBindings() { //Given SharpDX.Toolkit.Graphics.GraphicsDevice device = SharpDX.Toolkit.Graphics.GraphicsDevice.New(DeviceCreationFlags.Debug); IKernel kernal = new StandardKernel(); kernal.Bind <SharpDXGraphicsDevice>().ToSelf().InSingletonScope(); kernal.Bind <DefaultRasteriserState>().ToSelf().InSingletonScope(); kernal.Bind <ShadowBiasedDepthRasteriserState>().ToSelf().InSingletonScope(); kernal.Bind <FearGraphicsDevice>().ToConstant <SharpDXGraphicsDevice>(new SharpDXGraphicsDevice(GraphicsDevice.New(DeviceCreationFlags.Debug))); kernal.Bind <RasteriserState>().To <DefaultRasteriserState>().Named("Default"); kernal.Bind <RasteriserState>().To <ShadowBiasedDepthRasteriserState>().Named("ShadowBiasedDepth"); //When RasteriserState state = kernal.Get <RasteriserState>("Default"); //Then Assert.IsTrue(state.GetType() == typeof(DefaultRasteriserState)); //When state = kernal.Get <RasteriserState>("ShadowBiasedDepth"); //Then Assert.IsTrue(state.GetType() == typeof(ShadowBiasedDepthRasteriserState)); }
public void CreateDevice() { this.Dx11Device = new Device(DriverType.Hardware); this.GraphicsDevice = SharpDX.Toolkit.Graphics.GraphicsDevice.New(this.Dx11Device); this.Factory = new Factory(); //this.GraphicsDevice.Disposing += DeviceDisposing; }
public void Dispose() { Console.WriteLine("DXGameDeviceManager.Dispose .. start"); this.GraphicsDevice.Dispose(); this.GraphicsDevice = null; this.Dx11Device.Dispose(); this.Dx11Device = null; this.Factory.Dispose(); this.Factory = null; this.platform = null; Console.WriteLine("DXGameDeviceManager.Dispose .. done"); }
unsafe void InitializeInner(AntiAliasingMode antiAliasingMode) { worldMatrix = Matrix.Identity; textMatrix = Matrix.Identity; device = new D3D11.Device(DriverType.Hardware, D3D11.DeviceCreationFlags.None, new[] { FeatureLevel.Level_11_1, FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0 }); tkDevice = TK.GraphicsDevice.New(device); deviceContext = device.ImmediateContext; deviceContext.Rasterizer.State = device.CreateRasterizerState(); //TODO: replace with precompiled bytecode const string shaderFile = @"..\..\..\GameUtils\Graphics\shaders.fx"; ShaderBytecode vertexShaderBytecode = ShaderBytecode.CompileFromFile(shaderFile, "VS", "vs_4_0", ShaderFlags.Debug); ShaderBytecode pixelShaderBytecode = ShaderBytecode.CompileFromFile(shaderFile, "PS", "ps_4_0", ShaderFlags.Debug); InitializeShaders(vertexShaderBytecode, pixelShaderBytecode); indexBuffers = new D3D11.Buffer[BufferCount]; vertexBuffers = new D3D11.Buffer[BufferCount]; for (int i = 0, indexBufferSize = IndexBufferStartSize, vertexBufferSize = VertexBufferStartSize; i < BufferCount; i++, indexBufferSize <<= BufferSizeStep, vertexBufferSize <<= BufferSizeStep) { indexBuffers[i] = device.CreateDynamicBuffer(sizeof(int) * indexBufferSize, D3D11.BindFlags.IndexBuffer); vertexBuffers[i] = device.CreateDynamicBuffer(sizeof(Vertex) * vertexBufferSize, D3D11.BindFlags.VertexBuffer); } currentBufferIndex = 0; indexBuffer = indexBuffers[0]; vertexBuffer = vertexBuffers[0]; //indexBuffer = device.CreateDynamicBuffer(sizeof(int) * IndexBufferSize, D3D11.BindFlags.IndexBuffer); //vertexBuffer = device.CreateDynamicBuffer(sizeof(Vertex) * VertexBufferSize, D3D11.BindFlags.VertexBuffer); matrixBuffer = device.CreateConstantBuffer(sizeof(MatrixBuffer)); brushBuffer = device.CreateConstantBuffer(sizeof(Brush.BrushBuffer)); deviceContext.InputAssembler.SetIndexBuffer(indexBuffer, DXGI.Format.R32_UInt, 0); deviceContext.InputAssembler.SetVertexBuffers(0, new D3D11.VertexBufferBinding(vertexBuffer, sizeof(Vertex), 0)); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; blendState = device.CreateBlendState(); deviceContext.OutputMerger.SetBlendState(blendState); currentWrapMode = WrapMode.Clamp; currentInterpolationMode = InterpolationMode.Linear; samplerState = device.CreateSamplerState(WrapMode.Clamp, InterpolationMode.Linear); deviceContext.PixelShader.SetSampler(0, samplerState); sampleDescription = device.GetMultisamplingLevel(antiAliasingMode); defaultDepthStencilState = device.CreateDepthStencilState(D3D11.Comparison.Always, D3D11.StencilOperation.Keep, D3D11.StencilOperation.Keep); clipDepthStencilState = device.CreateDepthStencilState(D3D11.Comparison.Never, D3D11.StencilOperation.Replace, D3D11.StencilOperation.Keep); clippingDepthStencilState = device.CreateDepthStencilState(D3D11.Comparison.Equal, D3D11.StencilOperation.Keep, D3D11.StencilOperation.Keep); deviceContext.OutputMerger.SetDepthStencilState(defaultDepthStencilState); }